Oli Oli - 3 months ago 34
Javascript Question

Karma runner does not run all files

For some weird reason that I cannot fathom, my karma runner sometimes does not run all the test files.

karma.conf.js:

module.exports = function(config) {
config.set({

basePath: '',
frameworks: ['jasmine'],

files: [
'../lib/angular/angular.min.js',
'../lib/angular-mocks/angular-mocks.js',
'../lib/angular-notify/dist/angular-notify.min.js',
'../lib/JsCollection/dist/jscollection-0.1.5.min.js',
'../lib/lodash/dist/lodash.min.js',
'node_modules/jasmine-ajax/lib/mock-ajax.js',
'app/**/*.js',
'tests/**/*.js'
],

plugins: [ 'karma-jasmine', 'karma-phantomjs-launcher'],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false
});
};


So here is what happens, I run my tests and everything starts out just fine:

oli@devone:~/projects/2bi/public/src$ karma start
03 06 2016 11:40:44.861:WARN [karma]: No captured browser, open http://localhost:9876/
03 06 2016 11:40:44.921:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
03 06 2016 11:40:44.967:INFO [launcher]: Starting browser PhantomJS
03 06 2016 11:40:46.764:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket /#qmOPHCmxWaFWMmvrAAAA with id 14003688
PhantomJS 2.1.1 (Linux 0.0.0): Executed 46 of 46 SUCCESS (0.708 secs / 0.888 secs)


So my 46 tests are executed normally, everything is fine and dandy. Then I start to code and karma starts behaving weirdly, it does not run all the tests sometimes, but sometimes it does. Often it gets stuck on only running say 16 tests so I have to restart it to run all the tests again.

Here I change the formula test a few times:

03 06 2016 11:42:25.059:INFO [watcher]: Removed file "/home/oli/projects/2bi/public/src/tests/common/services/Formula.test.js".
PhantomJS 2.1.1 (Linux 0.0.0): Executed 16 of 16 SUCCESS (0.18 secs / 0.255 secs)
03 06 2016 11:42:32.882:INFO [watcher]: Added file "/home/oli/projects/2bi/public/src/tests/common/services/Formula.test.js".
03 06 2016 11:42:32.967:INFO [watcher]: Changed file "/home/oli/projects/2bi/public/src/tests/common/services/Formula.test.js".
PhantomJS 2.1.1 (Linux 0.0.0): Executed 46 of 46 SUCCESS (0.465 secs / 0.598 secs)
03 06 2016 11:43:12.529:INFO [watcher]: Removed file "/home/oli/projects/2bi/public/src/tests/common/services/Formula.test.js".
PhantomJS 2.1.1 (Linux 0.0.0): Executed 16 of 16 SUCCESS (0.136 secs / 0.246 secs)
03 06 2016 11:43:20.094:INFO [watcher]: Added file "/home/oli/projects/2bi/public/src/tests/common/services/Formula.test.js".
03 06 2016 11:43:20.183:INFO [watcher]: Changed file "/home/oli/projects/2bi/public/src/tests/common/services/Formula.test.js".
PhantomJS 2.1.1 (Linux 0.0.0): Executed 46 of 46 SUCCESS (0.506 secs / 0.626 secs)


Everything is run on a virtualbox machine but the filesystem is local.

Anybody have any idea what is going on?

Oli Oli
Answer

After some research it turns out that the karma watcher might have some issues.

What helped me in this particular case was adding usePolling: false in karma.conf.js.

I'm leaving this here if somebody has this problem.

Comments