Karma doesn't run test after converting to requirejs
javascript, karma-runner, requirejs
Solution
the really big thing here was that `karma.conf.js` wasn't loading all of the bower files. Then some of the `test-main.js` paths were wrong.
files: [
'test/test-main.js',
{pattern: 'test/spec/**/*.js', included: false},
{pattern: 'app/scripts/**/*.js', included: false},
{pattern: 'app/scripts/*.js', included: false},
{pattern: 'app/bower_components/**/*.js', included: false},
],
// list of files to exclude
exclude: [
'**/*.swp',
'app/bower_components/**/*min.js',
'app/scripts/main.js',
],
I have not gotten the created loop array to work
var tests = [];
for (var file in window.__karma__.files) {
if (/spec\.js$/i.test(file)) {
tests.push(file);
console.log( file );
}
}
require.config({
baseUrl: '/base/app/scripts',
paths: {
'domReady' :'../bower_components/requirejs-domready/domReady',
'jquery' :'../bower_components/jquery/jquery',
'angular' :'../bower_components/angular/angular',
'angular-sanitize':'../bower_components/angular-sanitize/angular-sanitize',
'angular-route' :'../bower_components/angular-route/angular-route',
'angular-mocks' :'../bower_components/angular-mocks/angular-mocks',
'crypto' :'../bower_components/cryptojs/lib/Crypto',
'crypto.MD5' :'../bower_components/cryptojs/lib/MD5',
'highlight' :'../bower_components/highlightjs/highlight.pack',
},
shim: {
'jquery' : { 'exports':'jquery'},
'angular' : { 'exports':'angular', 'deps':['jquery'] },
'angular-sanitize': [ 'angular' ],
'angular-route' : [ 'angular' ],
'angular-mocks' : [ 'angular' ],
'crypto.MD5' : [ 'crypto' ],
},
deps: ['pastey','/base/test/spec/controllers/insert.js'],
callback: window.__karma__.start,
});
Problem
To prefix the problem currently the test runs, but it seems to hang, it launches the browser but doesn't exit the browser on its own and appears to not be running the code in the test. I'm thinking it's not running because the final test file isn't being loaded by the browser, but I'm not sure why. Here's my `karma.conf.js` ``` // Generated on Mon Nov 18 2013 01:47:10 GMT-0600 (CST) module.exports = function(config) { config.set({ // base path, that will be used to resolve files and exclude basePath: '', // frameworks to use frameworks: ['jasmine', 'requirejs'], // list of files / patterns to load in the browser files: [ {pattern: 'app/scripts/**/*.js', included: false}, {pattern: 'app/scripts/*.js', included: false}, {pattern: 'test/spec/**/*.js', included: false}, 'test/test-main.js', ], // list of files to exclude exclude: [], // test results reporter to use // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' reporters: ['progress'], // web server port port: 9876, // enable / disable colors in the output (reporters and logs) colors: true, // level of logging // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG logLevel: config.LOG_DEBUG, // enable / disable watching file and executing tests whenever any file changes autoWatch: true, // Start these browsers, currently available: // - Chrome // - ChromeCanary // - Firefox // - Opera (has to be installed with `npm install karma-opera-launcher`) // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) // - PhantomJS // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) browsers: ['Chrome'], // If browser does not capture in given timeout [ms], kill it captureTimeout: 60000, // Continuous Integration mode // if true, it capture browsers, run tests and exit singleRun: false }); }; ``` `test/test-main.js` ``` 'use strict'; var tests = []; for (var file in window.__karma__.files) { if ( window.__karma__.files.hasOwnProperty(file) ) { if (/spec\.js$/i.test(file)) { tests.push(file); } } } require.config({ baseUrl: '/base/src', paths: { 'jQuery' :'app/bower_components/jquery/jquery', 'angular' :'app/bower_components/angular/angular', 'angular-sanitize':'app/bower_components/angular-sanitize/angular-sanitize', 'angular-route' :'app/bower_components/angular-route/angular-route', 'angular-mocks' :'app/bower_components/angular-mocks/angular-mocks' }, shim: { 'jQuery' : { 'exports':'jQuery'}, 'angular' : { 'exports':'angular', 'deps':['jQuery'] }, 'angular-sanitize': ['angular'], 'angular-route' : ['angular'] }, deps: tests, },[ 'domReady', 'controllers/main', ], function(domReady) { domReady(function() { console.log('testing'); window.__karma__.start; }) }); ``` `test/spec/controllers/main.js` ``` define(['angular','angular-mocks','controllers/insert'], function( angular, mocks, app ) { 'use strict'; describe('Controller: Insert', function () { // load the controller's module beforeEach(module('pasteyApp')); var Insert, scope; // Initialize the controller and a mock scope beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); Insert = $controller('Insert', { $scope: scope }); })); it('should attach a list of awesomeThings to the scope', function () { expect(scope.code).toBeDefined; }); }); }); ``` `grunt test` output ``` DEBUG [plugin]: Loading inlined plugin (defining ). INFO [karma]: Karma v0.10.4 server started at http://localhost:9876/ INFO [launcher]: Starting browser Chrome DEBUG [launcher]: Creating temp dir at /tmp/karma-26802229 DEBUG [launcher]: chromium --user-data-dir=/tmp/karma-26802229 --no-default-browser-check --no-first-run --disable-default-apps --start-maximized http://localhost:9876/?id=26802229 DEBUG [watcher]: Resolved files: /home/xenoterracide/dev/Pastey/node_modules/karma-requirejs/lib/require.js /home/xenoterracide/dev/Pastey/node_modules/karma-requirejs/lib/adapter.js /home/xenoterracide/dev/Pastey/node_modules/karma-jasmine/lib/jasmine.js /home/xenoterracide/dev/Pastey/node_modules/karma-jasmine/lib/adapter.js /home/xenoterracide/dev/Pastey/app/scripts/app.js /home/xenoterracide/dev/Pastey/app/scripts/controllers.js /home/xenoterracide/dev/Pastey/app/scripts/controllers/insert.js /home/xenoterracide/dev/Pastey/app/scripts/controllers/render.js /home/xenoterracide/dev/Pastey/app/scripts/main.js /home/xenoterracide/dev/Pastey/app/scripts/pastey.js /home/xenoterracide/dev/Pastey/app/scripts/routes.js /home/xenoterracide/dev/Pastey/app/scripts/services.js /home/xenoterracide/dev/Pastey/test/spec/controllers/insert.js /home/xenoterracide/dev/Pastey/test/test-main.js DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/node_modules/karma/static/client.html DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/node_modules/karma/static/karma.js DEBUG [karma]: A browser has connected on socket nNwHTFhgWd4VWMXxdmm0 INFO [Chrome 31.0.1650 (Linux)]: Connected on socket nNwHTFhgWd4VWMXxdmm0 DEBUG [karma]: All browsers are ready, executing DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/node_modules/karma/static/context.html DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/node_modules/karma-requirejs/lib/require.js DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/node_modules/karma-requirejs/lib/adapter.js DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/node_modules/karma-jasmine/lib/jasmine.js DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/node_modules/karma-jasmine/lib/adapter.js DEBUG [web-server]: serving: /home/xenoterracide/dev/Pastey/test/test-main.js DEBUG [Chrome 31.0.1650 (Linux)]: Disconnected during run, waiting for reconnecting. DEBUG [launcher]: Process Chrome exitted with code 0 ERROR [launcher]: Chrome crashed. DEBUG [launcher]: Cleaning temp dir /tmp/karma-26802229 WARN [Chrome 31.0.1650 (Linux)]: Disconnected Chrome 31.0.1650 (Linux): Executed 0 of 0 DISCONNECTED (4.751 secs / 0 secs) DEBUG [launcher]: Disconnecting all browsers DEBUG [launcher]: Killing Chrome Warning: Task "karma:unit" failed. Use --force to continue. Aborted due to warnings. Elapsed time concurrent:test 2s ▇▇▇▇▇▇▇▇▇▇▇ 25% karma:unit 6s ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 74% Total 8s ```