question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Karma doesn't exit properly when using public api with the finish callback

See original GitHub issue

Using Karma’s server public API with a done callback makes the whole node process “stuck” - there are probably some event listeners that prevent node process from exiting properly. A simple reproduce scenario:

var karma = require('karma').server;

karma.start({
  //transports: ['websocket', 'xhr-polling', 'jsonp-polling'],
  browsers: ['Chrome'],
  frameworks: ['jasmine'],
  files: [
    'src/**/*.js',
    'test/**/*.spec.js'
  ],
  singleRun: true
}, function(karmaExitCode) {
  console.log('Karma exited with ', karmaExitCode);
  console.log('but the process will never exit...');
});

Interestingly, removing the flash from the list of transports make the Karma exit after a while (~20s after test are finished on my machine).

There is a small repo with the reproduce scenario here: https://github.com/karma-runner/gulp-karma/blob/exit_pb/exitTest.js I will be digging into the topic but any help from someone more knowledgeable about Karma internals would be highly appreciated.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
lazdcommented, Apr 18, 2014

process.exit() is fatal, so that won’t work.

1reaction
jnwucommented, Mar 15, 2017

As a workaround, I am forcing the karma server to be executed in a separate process via ‘gulp-multi-process’

gulp.task('test', () => {
    const config = parseConfig(path.resolve('test/karma.conf.js'));
    const server = new karma.Server(config);
    server.start();
});

gulp.task('multi', (cb) => {
    return multiProcess(['test'], cb);
});

gulp.task('watch', () => {
    gulp.watch(files, ['multi']);
});

In addition my karma config has autoWatch off, and singleRun on. Hence, I am using gulp to watch my files and delegating all the test tasks (including report generation) to karma.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Karma can't capture PhantomJS - Stack Overflow
Karma is not able to run test cases on phantomJS · Karma doesn't exit properly when using public api with the finish callback...
Read more >
Public Api - Karma test runner
Most of the time, you will be using Karma directly from the command line. You can, however, call Karma programmatically from your node...
Read more >
Node.js – Karma can't capture PhantomJS – iTecNote
Best Solution · Karma is not able to run test cases on phantomJS · Karma doesn't exit properly when using public api with...
Read more >
Frontend testing standards and style guidelines - GitLab Docs
Frontend testing standards and style guidelines. There are two types of test suites encountered while developing frontend code at GitLab. We use Jest...
Read more >
Testing Workflow for Web Components - DEV Community ‍ ‍
We're using karma and chai's BDD syntax, so we group sets of tests ( it ) under the features or APIs they relate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found