Karma: Karma doesn't exit when API is used with callback

Created on 28 May 2015  路  3Comments  路  Source: karma-runner/karma

I use Karma programmatically with its karma.server.start(config, cb) API. When I run my unit tests on a Selenium Grid the process runs forever, but only if I use a callback. That's why Karma seems to default to process.exit - it doesn't really stop without that. But the way I use it I can't know (and don't want to know) _when_ Karma was called and when to call process.exit. I think this is a bug. It shouldn't be necessary to call process.exit, just to stop Karma.

investigation

Most helpful comment

I have the same problem with 1.0.

I think this could be related to https://github.com/karma-runner/karma/issues/1788. It randomely stays open for a while, event if cb is called. It would probably work, too, if I could stop my server manually, but it only has a start method.

All 3 comments

Any update on this?

I have the same problem with 1.0.

I think this could be related to https://github.com/karma-runner/karma/issues/1788. It randomely stays open for a while, event if cb is called. It would probably work, too, if I could stop my server manually, but it only has a start method.

There were multiple changes targeting this problem and the minimal example works as intended now. I.e. cleans up all resources and exits without a process.exit() call.

const karma = require('karma')

karma.config.parseConfig('karma.conf.js', {}, { promiseConfig: true, throwErrors: true })
  .then((karmaConfig) => {
    const server = new karma.Server(karmaConfig, function doneCallback (exitCode) {
      console.log('Karma has exited with ' + exitCode)
      process.exit(exitCode)
    })
    server.start()
  })
  .catch((err) => console.error(err))

If you still experience the problem, please open a new issue with minimal reproduction and we'll look into fixing that specific case as well.

Was this page helpful?
0 / 5 - 0 ratings