Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karma javascript API calls process.exit(1) #3612

Closed
codymikol opened this issue Jan 8, 2021 · 4 comments
Closed

Karma javascript API calls process.exit(1) #3612

codymikol opened this issue Jan 8, 2021 · 4 comments

Comments

@codymikol
Copy link

codymikol commented Jan 8, 2021

Hello, I'm working on writing some integration tests for the karma-webpack plugin, and I ran into some trouble while using the karma javascript API.

The first issue is that when you directly call server.start(), and there are errors in the passed karma configuration, internally karma will call process.exit(1) forcing the currently running node process to exit.

Alongside this, the internal logging that karma uses to report these errors with log4js will by default not print out anything, so my initial experience was my test just exiting without explanation.

My current workaround for this was to pull in log4js and manually set the log level to figure out what was actually being reported and fix my configuration issues.

Would it make sense to add configuration options for setting the log4js level and also to potentially circumvent the process.exit(1) and alternatively emit some kind of fatal_error event? If so this is something I could look into adding.

Thanks!

EDIT: I worked around this issue by using a forked child_process, but I'll leave this open as I think that these could still be useful changes to implement.

@devoto13
Copy link
Collaborator

devoto13 commented Jan 9, 2021

Karma calling process.exit() should be fixed by #3607, which should be included in the next release. With this change you should be able to pass done callback to the new Server(config, done) call and the callback will be used instead of the process.exit. Then you can check the exit code parameter and act accordingly.

As for logging I think it should work when using Karma programatically, or at least I don't see any special handling in the code. I'll do some debugging in the coming days and get back to you.

@codymikol
Copy link
Author

Perfect! Pretty crazy that you just added this so recently and it happens to be exactly what I'm looking for.

@devoto13
Copy link
Collaborator

devoto13 commented Jan 14, 2021

Regarding the logging not working. Can you provide a minimal reproduction? Given the below minimal code, log4js works out of the box, when using Karma programmatically.

$ cat test.js
const { Server } = require('karma')
const server = new Server({
  files: [
    'test/client/*.js'
  ]
}, (code) => console.log(`done with code: ${code}`))
server.start()
$ node test.js
14 01 2021 12:35:41.332:WARN [karma]: No captured browser, open http://localhost:9876/
14 01 2021 12:35:41.504:INFO [karma-server]: Karma v6.0.0 server started at http://localhost:9876/
...

I agree however that it would be good to emit error event, so it is easier to use programatically.

@codymikol
Copy link
Author

If it was an issue, it definitely isn't one now, I think maybe it was just exiting before the logger was being evaluated. Thanks for all your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants