I am trying to run Jasmine tests in Karma. This is for an AngularJS application using RequireJS, but at the moment the test is a simple test expect(true).toBe(true);without Angular dependencies. I found that it starts when I turn off the Karma module requirejsand comment-out "client/app/require-shared.js"and "test/require-test.js"in filesand load the testSpec.js file directly.
However, as soon as I turn on requirejsand add RequireJS configuration files back to karma.conf.js files- saving the testSpec.js file there “statically” - I see errors
Chrome 33.0.1750 (Windows 7) ERROR
Uncaught TypeError: Cannot read property 'failedCount' of null
at C:/.../project/node_modules/karma-jasmine/lib/adapter.js:126
Chrome 33.0.1750 (Windows 7) ERROR
Uncaught TypeError: Cannot read property 'length' of null
at C:/.../project/node_modules/karma-jasmine/lib/jasmine.js:2518
Chrome 33.0.1750 (Windows 7): Executed 1 of 2 ERROR (0.009 secs / 0.001 secs)
If I try to run the full Angular test, I get errors with respect to $injectorzero, but I think all this is due to this problem of the requirejs module. What am I missing in my setup to make this work?
Test /karma.conf.js
module.exports = function(config) {
config.set({
basePath: "../",
frameworks: ["jasmine", "requirejs"],
files: [
"client/app/require-shared.js",
"test/require-test.js",
{pattern: "test/unit/*Spec.js"}
],
exclude: [
"*.conf.js"
],
reporters: ["progress"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ["Chrome"],
singleRun: true
});
};
client / application / require-shared.js
requirejs.config({
paths: {
"app": "../app/app",
"angular": "../extlibs/angular-1.2.14",
"jquery": "../extlibs/jquery-2.1.0.min",
"ng-cookies": "../extlibs/AngularPlugins/angular-cookies-1.2.13",
"ng-resource": "../extlibs/AngularPlugins/angular-resource-1.2.13",
"ng-route": "../extlibs/AngularPlugins/angular-route-1.2.14",
}
,shim: {
angular: {
exports: "angular"
}
,"ng-resource": {
deps: [ "angular" ],
exports: "ng-resource"
},
,"ng-cookies": ["angular"]
,"ng-route": ["angular"]
,"ngui-bootstrap": ["angular"]
}
});
test / require-test.js
var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;
var pathToModule = function(path) {
return path.replace(/^\/base\//, "").replace(/\.js$/, "");
};
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
var normalPath = pathToModule(file);
console.log("adding " + file + " as " + normalPath + " to allTestFiles array");
allTestFiles.push(normalPath);
}
});
requirejs.config({
baseUrl: "/base/client/components/"
,paths: {
"test": "../../test",
"bower": "../../bower_components",
"angular-mocks": "bower/angular-mocks/angular-mocks"
}
,shim: {
'angular-mocks': {
deps: [ 'ng-resource' ],
exports: 'angular.mock'
}
}
,deps: allTestFiles
,callback: window.__karma__.start
});
test / block / testSpec.js
describe('a basic test of version', function() {
it('true should be true', function() {
expect(true).toBe(true);
});
});