Coder Social home page Coder Social logo

karma-requirejs's Introduction

karma-requirejs's People

Contributors

aymericbeaumet avatar danez avatar dignifiedquire avatar jacksonrayhamilton avatar kevinwarnock avatar motammi avatar poetro avatar sabarasaba avatar sahat avatar vojtajina avatar yanoosh avatar zzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

karma-requirejs's Issues

Requiring files in current directory is failing to append extension

I've ran into a bit of an issue when I require files in the same folder as the spec file. If I call using define(['./app'], function(App) { it won't append the .js extension. If I manually add the .js extension it loads the file properly. Is there a way to work around this without manually adding .js ?

I've also zipped a modified directory structure of the Karma RJS sample folder that has passing tests. It can be reproduces if you change karma-test/source/components/appSpec.js to require ./app instead of ./app.js.

Thanks for all of your work on Karma, it's fantastic!!

  • Adam


network data:
define(['./app', 'jquery', 'underscore'], function(App, $, _) {

Header:
Request URL:http://localhost:9877/base/components/app
Request Method:GET
Status Code:404 Not Found


------------------------------------------------------------------


define(['./app.js', 'jquery', 'underscore'], function(App, $, _) {

Header:
Request URL:http://localhost:9877/base/components/app.js?1368221603000
Request Method:GET
Status Code:200 OK (from cache)


------------------------------------------------------------------


define(['app', 'jquery', 'underscore'], function(App, $, _) {

Header:
Request URL:http://localhost:9877/base/components/app.js?1368221603000
Request Method:GET
Status Code:200 OK (from cache)


------------------------ Karma Files ------------------------

__karma__.files
Object {/adapter/lib/jasmine.js: "1365839185000", /adapter/jasmine.js: "1365839521000", /adapter/lib/require.js: "1365839185000", /adapter/require.js: "1365839521000", /base/scripts/lib/jquery.js: "1367847560000"…}
/adapter/jasmine.js: "1365839521000"
/adapter/lib/jasmine.js: "1365839185000"
/adapter/lib/require.js: "1365839185000"
/adapter/require.js: "1365839521000"
/base/components/app.js: "1368221603000"
/base/components/appSpec.js: "1368221989000"
/base/scripts/lib/jquery.js: "1367847560000"
/base/scripts/lib/require.js: "1367847560000"
/base/scripts/lib/underscore.js: "1367847560000"
/base/scripts/test-main.js: "1368221518000"
__proto__: Object

Automatically append ".js" when normalizing filename

    normalized.push(parts[i]);
  }

  var file = normalized.pop();
  file += file.indexOf('.js') == -1 ? '.js' : '';
  normalized.push(file);

  return normalized.join('/');

Without that karma-cajon, the fork of this project, tries to load files without any extension. Since the author of the fork did not enabled issues -- I'll leave it here.

Relative paths break when running RequireJS app inside Karma

I am trying to setup my Angular app to run inside Karma. I have it working great, and configured properly inside the browser, and all my module definitions (with relative paths) work just fine.

However, when I try to get the app running inside Karma, all of my relative paths seem to break. This is effecting both the Shim paths, as well as paths inside define() statements.

Here is an example app I uploaded:

https://github.com/duro/my-angular-requiejs-example

Take note of the config I have here:

https://github.com/duro/my-angular-requiejs-example/blob/master/test/karma.conf.js

Here:

https://github.com/duro/my-angular-requiejs-example/blob/master/app/test.js

And Here:

https://github.com/duro/my-angular-requiejs-example/blob/master/app/config.js

Everything appears to load just fine in Karma, until it hits a dependency that is setup using a relative path.

Uncaught Error: Mismatched anonymous define()

I am facing below issue while running mocha test via karma

Uncaught Error: Mismatched anonymous define() module: function (workflow) {

var expect = chai.expect;

describe('Empty Workflow Project Creation Module Testing', function () {
it('should throw an error if project is not empty', function () {
var result = [];
alert('check des');

                    result=workflow.onAfterGenerate("projectzip", "model");

     // result = onAfterGenerate("projectzip", "model");
      expect(result[0]).to.equal("projectzip");
      expect(result[1]).to.equal("model");
  });

});

}
http://requirejs.org/docs/errors.html#mismatch
at node_modules/requirejs/require.js:143

My karma conf file is :

module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['requirejs','mocha','openui5'],
openui5: {
//path: 'https://sapui5.hana.ondemand.com/resources/sap-ui-core.js',
path: 'https://sapui5.hana.ondemand.com/1.30.8/resources/sap-ui-core.js',
useMockServer: false
},
files: [
{pattern: 'node_modules/**/*.js', included: false},
'test/test-main.js',
'js/spec/CreateEmptyWFProject_spec.js'

    ],
   /* preprocessors: {
        'src/test/js/fixtures/*.html': ['html2js'],
        'src/*.js': ['coverage']
    },*/

   // reporters: ['progress', 'coverage','html'],

    /*htmlReporter: {
        outputFile: 'target/units.html',

        // Optional
        pageTitle: 'Unit Tests',
        subPageTitle: 'A workflow project description',
        groupSuites: true,
        useCompactStyle: true,
        useLegacyStyle: true
      },*/

    port: 8080,
    colors: true,
    autoWatch: true,

    captureTimeout: 60000, // it was already there
    browserDisconnectTimeout : 10000,
    browserDisconnectTolerance : 1,
    browserNoActivityTimeout : 60000,//by default 10000

    browsers: ['Chrome'],



    singleRun: true,
    logLevel: config.LOG_INFO/*,

    coverageReporter: {
        dir: 'target/test_js_coverage',
        instrumenter: {
            'js/*.js': ['istanbul']
        },
        reporters: [
            { type: 'html', subdir: 'report-html' }
        ]
    }*/
});

};

package.json looks like this

{
"name": "requirejs_mocha",
"version": "1.0.0",
"description": "check requirejs mocha karma",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.1.1",
"karma-mocha": "^1.3.0",
"karma-requirejs": "^1.1.0",
"requirejs": "^2.3.3"
}
}

Project structure :

image

test-main.js is

/**

// if invoked in karma-runner environment
if (typeof window != 'undefined' && window.karma != undefined) {
// Karma serves files from '/base'
baseUrl = '/base';
requirejsCallback = window.karma.start;

// looking for *_spec.js files
specFiles = [];
for (var file in window.__karma__.files) {
  if (window.__karma__.files.hasOwnProperty(file)) {
    if (/.*\/js\/spec\/.+_spec\.js$/.test(file)) {
      specFiles.push(file);
    }
  }
}

}

/** requirejs.config({
baseUrl: baseUrl,

  paths: {
    'chai':  'node_modules/chai/chai',
    'sinon': 'node_modules/sinon/pkg/sinon'
  },

  // ask Require.js to load these files (all our tests)
  deps: specFiles,

  // start test run, once Require.js is done
  callback: requirejsCallback

}); **/
requirejs.config({
baseUrl: '/base',
deps: specFiles,
callback: mocha.run
});
})();

Test file : CreateEmptyWFProject_spec

debugger;
alert('hello');
define(['../../src/workflow-tools/client/sap.bpm.webide.wfs.template.plugin/workflow/workflow'], function(workflow) {
var expect = chai.expect;
describe('Empty Workflow Project Creation Module Testing', function () {
it('should throw an error if project is not empty', function () {
var result = [];
alert('check des');

		result=workflow.onAfterGenerate("projectzip", "model");

   // result = onAfterGenerate("projectzip", "model");
    expect(result[0]).to.equal("projectzip");
    expect(result[1]).to.equal("model");
});

});

});

Thanks for help in advance

Does not have real error messages by misconfiguration

I got "empty test suite" by a misconfiguration. The problem was that I added a non-include file pattern before the inclusion pattern of main.js, and that pattern contained the main.js as well. You should mention this in the error message or at least in the documentation.

By 404 "there is not timestamp" errors you should mention that every used file must be added to karma file patterns. Is there any way to add every project file automatically and just select a main.js to load the tests? Why does karma need those non-include file patterns?

broken link in README.md

In the examples on how to configure RequireJS with Karma the first link to the Karma's e2e test returns 404.

There is no requirejs folder in test/e2e

10 Days ago they were moved to a separate repo (which one?)

Change the examples to better practice...

Currently the messaging around karma-requirejs is to dynamically generate your list of files by iterating over window.karma.files. While I really like this approach it has some edge cases that break require.js module resolution the biggest problem is that if your test files use relative module paths they won't resolve to the appropriate URL. This is an issue best articulated using an example: https://gist.github.com/iammerrick/6300916.

The solution is to stick to module ids and not use urls at all, for our case I simply strip off the .js and the requirejs baseUrl to retrieve the module id and pass that into require appropriately...

for (var file in window.__karma__.files) {
  if (/Test\.js$/.test(file)) {
    // Convert url of file to its module id.
    tests.push(file.replace(/^\/base/, '../..').replace(/\.js$/, ''));
  }
}

This changes the files from:

/base/test/my/module.js

To:

../../test/my/module

As it is a module id instead of a url require.js will resolve all the relative child URLs appropriately.

Feel free to close this issue but I thought it was something you should at least be aware of.

Failing build on Travis

I have the following build https://travis-ci.org/blacksonic/minesweeper.
I run my tests on local machine, no error, but when running them on the CI server I get this:
Error: Module name "shelljs" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded
at /home/travis/build/blacksonic/minesweeper/node_modules/karma-requirejs/lib/require.js:138

I couldn't reproduce this issue on my local machine, even deleting every node module and reinstalling them.

Uncaught Error: Module name "http-errors"

Hi,

I am using karma-requirejs for testing Node-Express project. But I am getting below error when doing npm test. Can anyone help me on this?

{ "message": "Uncaught Error: Module name \"http-errors\" has not been loaded yet for context: _. Use require([])\nhttp://requirejs.org/docs/errors.html#notloaded\nat node_modules/requirejs/require.js:143:9\n\nError: Module name \"http-errors\" has not been loaded yet for context: _. Use require([])\nhttp://requirejs.org/docs/errors.html#notloaded\n at makeError (node_modules/requirejs/require.js:168:17)\n at Object.localRequire [as require] (node_modules/requirejs/require.js:1436:44)\n at requirejs (node_modules/requirejs/require.js:1797:24)\n at app.js:1:19", "str": "Uncaught Error: Module name \"http-errors\" has not been loaded yet for context: _. Use require([])\nhttp://requirejs.org/docs/errors.html#notloaded\nat node_modules/requirejs/require.js:143:9\n\nError: Module name \"http-errors\" has not been loaded yet for context: _. Use require([])\nhttp://requirejs.org/docs/errors.html#notloaded\n at makeError (node_modules/requirejs/require.js:168:17)\n at Object.localRequire [as require] (node_modules/requirejs/require.js:1436:44)\n at requirejs (node_modules/requirejs/require.js:1797:24)\n at app.js:1:19" }

package.json
"scripts": { "start": "node ./bin/www", "test": "karma start & karma run" }, "dependencies": { "browserify": "^16.2.0", "cookie-parser": "~1.4.3", "debug": "~2.6.9", "express": "~4.16.0", "http-errors": "^1.6.3", "jade": "~1.11.0", "morgan": "~1.9.0", "mysql": "^2.15.0", "sqlite3": "^4.0.0", "watchify": "^3.11.0" }, "devDependencies": { "jasmine-core": "~2.8.0", "jasmine-spec-reporter": "~4.2.1", "karma": "^2.0.2", "karma-browserify": "^5.2.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "karma-phantomjs-launcher": "^1.0.4", "karma-requirejs": "^1.1.0", "karma-webpack": "^3.0.0", "requirejs": "^2.3.5", "webpack": "^4.6.0", "webpack-node-externals": "^1.7.2" }

karma.conf.js
`// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

const nodeExternals = require('webpack-node-externals');

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'requirejs'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
//require('karma-phantomjs-launcher'),
//require('karma-jasmine-html-reporter'),
//require('karma-coverage-istanbul-reporter'),
require('karma-requirejs')
],
files: [
'test-main.js',
'app.js',
{pattern: 'routes/.js', included: false},
{pattern: 'spec/
.spec.js', included: false},

    ],
    preprocessors: {
        //use webpack to support require() in test-suits .js files
        //use babel-loader from webpack to compile es2015 features in .js files
        //add webpack as preprocessor
        // 'app.js': ['webpack'],
        // 'routes/*.js': ['webpack'],
        // 'spec/*.spec.js': ['webpack']
    },
    client: {
        clearContext: false
    },
    // reporters: ['progress', 'coverage-istanbul', 'kjhtml'],
    reporters: ['dots'],
    coverageIstanbulReporter: {
        reports: ['html', 'text-summary'],
        fixWebpackSourcePaths: true
    },
    /*webpack: {
        target: 'node',
        node: {
            fs: 'empty'
        },
        mode: 'development',
        externals: [nodeExternals()]
    },*/
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
});

};`

There is no timestamp error when using CommonJS syntax

I'm trying to test modules that use the simplified CommonJS syntax as described in this SO thread.

However, the karma-requirejs/lib/adapter.js logs an error "There is no timestamp for..."

For example:

// mysrc.js
define(function(require) {
  var foo = require('foo');
  var bar = require('bar');

  var someFunc = () {
    // do something with foo and bar...
  }

  return {
    someFunc: someFunc
  };
});

// mysrcSpec.js
define(['mysrc'], function(mysrc) {
  describe('testing', function() {
    it('does something', function() {
      mysrc.someFunc();
    }
  }
});

Then it doesn't even get as far as executing the test, console displays error "There is no timestamp for /base/foo.js"

However, if I rewrite mysrc.js in the traditional RequireJS syntax, then all dependencies are found and test passes:

define(['foo', 'bar'], function(foo, bar) {
   var someFunc = () {
    // do something with foo and bar...
  }
);

Is it possible to use the karma requirejs plugin together with the CommonJS style syntax?

Unable to install karma-requirejs

I installed both karma and requirejs:

$npm install -g "karma@>=0.9" "requirejs@^2.1.0"

then requirejs still fails to install:

$npm install -g karma-requirejs
/usr/local/lib
├── UNMET PEER DEPENDENCY karma@>=0.9
├── [email protected]
└── UNMET PEER DEPENDENCY requirejs@^2.1.0

npm WARN [email protected] requires a peer of karma@>=0.9 but none was installed.
npm WARN [email protected] requires a peer of requirejs@^2.1.0 but none was installed.

$node --version
v6.13.1

$npm --version
3.10.10

I'm on a mac.

Error: Mismatched anonymous define() module

My config:

'use strict';

module.exports = function (config) {
    config.set({
        basePath: './',
        port: 9001,

        browsers  : ['PhantomJS'],
        frameworks: ['mocha-debug', 'mocha', 'requirejs', 'chai', 'chai-as-promised' ],
        reporters : ['mocha', 'progress', 'coverage'],

        client: {
            mocha: {
                reporter: 'html',
                ui      : 'bdd'
            }
        },

        preprocessors: {
            'tests/**/*.js': [ 'babel' ],
            '{trunk,utils}/**/*.js': [ 'coverage' ]
        },

        // https://github.com/karma-runner/karma-coverage
        coverageReporter: {
            type: 'html',
            dir : 'cache/coverage/'
        },

        files: [
            'index.js',
            'tests/**/*.js',
        ],

        colors: true,
        autoWatch: false,
        logLevel : config.LOG_INFO,
        singleRun: true
    });
};

package.json

{
    "devDependencies": {
        "grunt"                   : "^0.4.5",
        "grunt-karma"             : "^0.10.1",
        "grunt-babel"             : "^4.0.0",
        "karma-mocha"             : "^0.1.10",
        "karma-coverage"          : "^0.2.7",
        "karma-chai-plugins"      : "^0.4.0",
        "karma-phantomjs-launcher": "^0.1.4",
        "karma-mocha-debug"       : "^0.1.2",
        "karma-requirejs"         : "^0.2.2",
        "karma-mocha-reporter"    : "^1.0.2",
        "karma-babel-preprocessor": "^5.0.0"
    }
}

A test file

define(['../index.js'], function(polyfiller) {

});
➜ grunt test
Running "karma:tests" (karma) task
INFO [karma]: Karma v0.12.31 server started at http://localhost:9001/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket laHcJ0unDsVM0KNd31Tc with id 53989432
PhantomJS 1.9.8 (Mac OS X) ERROR
  Error: Mismatched anonymous define() module: function (polyfiller) {}
  http://requirejs.org/docs/errors.html#mismatch
  at /workspace/github/polyfiller/node_modules/requirejs/require.js:141
PhantomJS 1.9.8 (Mac OS X) ERROR
  Error: Mismatched anonymous define() module: function (polyfiller) {}
  http://requirejs.org/docs/errors.html#mismatch
  at /workspace/github/polyfiller/node_modules/requirejs/require.js:141


Finished in 0.027 secs / 0 secs

SUMMARY:
✔ 0 tests completed
Warning: Task "karma:tests" failed. Use --force to continue.

Aborted due to warnings.

Ok,

define('foo', ['../index.js'], function(polyfiller) {

});
➜ grunt test
Running "karma:tests" (karma) task
INFO [karma]: Karma v0.12.31 server started at http://localhost:9001/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket w_SmkVVfhA3AXESY5THZ with id 85656734
PhantomJS 1.9.8 (Mac OS X) ERROR: 'There is no timestamp for /workspace/github/polyfiller/node_modules/karma-chai-plugins/node_modules/chai/chai.js!'
PhantomJS 1.9.8 (Mac OS X) ERROR: 'There is no timestamp for /Abashkin/workspace/github/polyfiller/node_modules/karma-chai-plugins/node_modules/chai/chai.js!'

PhantomJS 1.9.8 (Mac OS X) ERROR: 'There is no timestamp for /workspace/github/polyfiller/node_modules/karma-chai-plugins/node_modules/chai-as-promised/lib/chai-as-promised.js!'
PhantomJS 1.9.8 (Mac OS X) ERROR: 'There is no timestamp for /workspace/github/polyfiller/node_modules/karma-chai-plugins/node_modules/chai-as-promised/lib/chai-as-promised.js!'

WARN [PhantomJS 1.9.8 (Mac OS X)]: Disconnected (1 times), because no message in 10000 ms.

Finished in 10.035 secs / 0 secs
Warning: Task "karma:tests" failed. Use --force to continue.
Aborted due to warnings.

What am i doing wrong?

Mocha v3 triggers "mismatched anonymous define" error

After upgrading to Mocha 3.0.0, karma-requirejs throws an error when trying to run tests:

Mismatched anonymous define() module: function () { return JSON3; }

This does not occur when I downgrade to Mocha 2.5.3.

I'm using:

  • karma 1.1.2
  • karma-requirejs 1.0.0
  • mocha 3.0.0
  • phantomjs-prebuilt 2.1.10

We use gulp to activate the tests:

gulp.task('test:components', function() {
    var karma = require('karma').server;

    karma.start({
        configFile: basePath + '/karma.conf.js'
    });
});

And I've reduced our karma.conf.js file to a very limited set:

module.exports = function(config) {
    config.set({
        frameworks: ['mocha', 'requirejs'],
        browsers: ['PhantomJS'],
        port: 9876,
        singleRun: true
    });
};

Here's the full startup log:

03 08 2016 12:54:05.189:INFO [karma]: Karma v1.1.2 server started at http://localhost:9876/
03 08 2016 12:54:05.192:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
03 08 2016 12:54:05.198:INFO [launcher]: Starting browser PhantomJS
03 08 2016 12:54:05.786:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#0At0vvA1atYS3xCnAAAA with id 32375243
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Error: Mismatched anonymous define() module: function () {
        return JSON3;
      }
  http://requirejs.org/docs/errors.html#mismatch
  at /Users/viveleroi/project/node_modules/requirejs/require.js:143

Is the project abandoned?

Nothing seems to have happened for the last year, even though the thing has some breaking issues. It has no documentation and even the ones that are there are pointing to 0.8, whereas latest Karma is 0.12. I think it fair to assume that it has been abandoned?

Provide a mechnism to disable the caching

I am working on a plugin to requirejs and really wanted to write my unit tests using this tool. However, the caching behavior prevents me from writing tests for the variations that my requirejs plugin is trying to test without breaking every single test into a completely independent Karma.config file.

It would be nice to have a switch that allowed me to have all the tests in one file and run with independent requirejs caches which I think would be the behavior if there was a way to disable the caching you added.

If you have other ideas about how I could setup these test or want to see how the plugin testing kind of works: https://github.com/squareplanetdesign/requirejs-min-plugin..... I would appreciate any suggestions you may have if disabling the caching is not the best approach.

Dynamic requirejs file from remote machine

Is it possible to add a dynamically generated "require.js" file to download and make available during run time? As an example lets say the file url is "http://remote/require.js", is there any way to use let karma-requirejs download that file (and all other modules) and make that available to my test execution?

Make "no timestamp" error configurable

For instance when loading files through proxy, there's no timestamp and it's perfectly valid use case.

Maybe something like:

client: {
  requireJsShowNoTimestampsError: false
}

Create new npm version

Hey,

to make the last changes affected (new version of require.js) to karma there should be a new version published to npm.

Thank you 👍

Error: No provider for "framework:requirejs"! (Resolving: framework:requirejs)

Package.json

"devDependencies":{
    "requirejs": "~2.1.5",
    "karma": "~0.12.5",
    "karma-cli": "~0.0.4",
    "karma-phantomjs-launcher": "~0.1.4",
    "karma-requirejs": "~0.2.1"
}

Error: No provider for "framework:requirejs"! (Resolving: framework:requirejs)

Is there something missing?

Versions installed
Requirejs 2.1.11
karma-requirejs 0.2.1
Karma: 0.12.5

native require() seems to completely overridden

I had a usage scenario that I had to run tests on a non requireJS module. It seems that the native commonJS require() is overidden. The question is,

is it kept in another reference that could be accessed from a test or is it gone completely?

Repeated " Some of your tests did a full page reload!" error

Karma config
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: [require("karma-jasmine")],
files: [
'node_modules/requirejs/require.js',
'node_modules/karma-requirejs/lib/adapter.js',
"spec/**/*[sS]pec.js",
]
})
}

Sample spec
describe("Project View Sensors", function() {
it("Should populate measures grid", function(){
expect(1).toBe(1);
});
});

Without fail every time the error is this I am by no means loading anything that would reload the window
Firefox 67.0.0 (Windows 10.0.0) ERROR
Some of your tests did a full page reload!

vague require.js + karma errors

  Uncaught Error: Module name "user.controller" has not been loaded yet for context: _
  http://requirejs.org/docs/errors.html#notloaded
  at /Users/user/Sites/project/node_modules/requirejs/require.js:141

All configuration errors with require.js + karma (+ angular) lead to vague output like above^ (there's no file name that's causing the error, just a reference to where the error happens in require).

Require.js does not prepend baseUrl to dependencies

Hi,

I am trying to use Karma for my application's unit testing. I use Require.js in my app. Below is the directory structure -

|-app
|--all/app/code/goes here
|-public
|--external/lib/goes here
|-test
|--test-spec.js
|-test-main.js
|-karma.conf.js

The problem is that in my UT spec.js file when I include the dependency from app folder, the baseUrl (/base) does not get prefixed to the path resulting in 404.

WARN [web-server]: 404: /app/common/models/metadata.js

If I change the path in dependencies list to /base/app-client/common/models/metadata.js, it works fine.
Similarly all the other dependencies of the models are resulting in 404 as well.

Here is my test-main.js config -

requirejs.config({
    // Karma serves files from '/base'
    baseUrl: '/base',

    shim: {
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        },
        runtime: {
            exports: 'runtime'
        },
        Creatr: {
            deps: [
                'backbone'
            ],
            exports: 'creatr'
        }
    },
    paths: {
        'jquery': 'public/lib/jquery/jquery.min',
        'jquery.min.map': 'public/lib/jquery/jquery.min',
        'underscore': 'public/lib/underscore/underscore',
        'backbone': 'public/lib/backbone/backbone'
    },
    // ask Require.js to load these files (all our tests)
    deps: [
        'backbone',
        '/base/test/test-spec.js'       
    ],
    // start test run, once Require.js is done
    callback: window.__karma__.start
});

Please let me know what am I missing.

Thanks.

How to use QUnit with Karma and RequireJS

I'm new to using Karma, been meaning to get familiar with it for some time. That said, I've just spent the better part of a day trying to get it to run a single unit test (using Mocha and Should.js), and having solved that, am now struggling to get it to run my existing QUnit tests.

I could post this to karma-qunit, but I'm not really sure which framework is the problem and figure its all the same people looking at these issues.

https://gist.github.com/jayboyd/9624412

I've tried everything I can find google and read lots of SO answers to similar problems (including many that eventually helped me sort out getting Mocha to work.

Please, please help! What am I missing?

text! plugin could not load the HTML template during test

I have a text! to load my basic HTML template to use for my Backbone Require.js project at here - https://github.com/mech/front_end_demo

If you run the server, the template will get the properly loaded, but the karma test runner did not seem to be able to load the HTML file. It can somehow only load if I renamed the file to show.js instead of show.html. This conclude that the path is visible, just that it cannot load HTML files?

Error: /base/app/assets/javascripts/src/client/templates/show.html HTTP status: 404

Appreciated for any help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.