karma-runner / grunt-karma

Grunt plugin for Karma.
MIT License
468 stars 116 forks source link

Temporarily remove Grunt's uncaughtException listeners. #103

Open jpommerening opened 10 years ago

jpommerening commented 10 years ago

As I mentioned in #93, Grunt's uncaughtException listeners fire before Karma gets a chance to stop the browsers it started.

The only fix that I can think of is removing Grunt's listners for as long as Karma is running. That way, Karma can gracefully handle a framework raising an error or the user pressing Ctrl-c.

I made a small gist to reproduce the problem: https://gist.github.com/jpommerening/10364033

After running npm install, running Grunt will (probably) produce the following output:

$ grunt
Running "karma:unicorns" (karma) task
INFO [karma]: Karma v0.12.6 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket 8mpKEfFNXoO5vMb1GWU6 with id 2679007
PhantomJS 1.9.7 (Linux): Executed 1 of 1 SUCCESS (0.038 secs / 0 secs)

Running "karma:explosions" (karma) task
INFO [karma]: Karma v0.12.6 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket uo1f5cVKNpntcOFnGWd8 with id 10877927
PhantomJS 1.9.7 (Linux): Executed 1 of 1 SUCCESS (0.039 secs / 0 secs)
Fatal error: Bam!

To try the same thing with the changes in this PR:

$ npm install grunt-karma@jpommerening/grunt-karma#fix-stray-browsers
...
$ grunt
...
jpommerening commented 10 years ago

I added another commit to handle SIGINT / Ctrl-c.

Karma listens for SIGINT and takes care of stopping all the browsers. Grunt, however, does not. So after Karma finished, Grunt will just continue running its task queue.

Since Grunt does not listen for SIGINT one would expect Ctrl-c to exit the process immediately. The best we can do is to add our own SIGINT listener and exit the process after Karma is finished.

elicwhite commented 8 years ago

This seems long dead, but we still get problems on our CI machine with browsers hanging around from grunt-karma failures. It would great to see this updated and merged.

dignifiedquire commented 8 years ago

@jpommerening could you rebase this onto latest master please?