jfirebaugh/konacha — pull request #140 by Mr0grog (2013-05-27 04:50:03+00:00)
Title: Install Mocha's global error handler in each test's iframe

This patch fixes #136 by copying Mocha's global error handler onto each iframe after the runner starts (Mocha sets up the handler as the last thing `Runner#run` does, so you can't even do it on the `start` event). When the runner ends, it cleans everything up.

Alternatively, you could overwrite Mocha's `process.on()` shim, but that seems more like an implementation detail this prone to breakage.

This also adds a test for async errors.

Also worth noting: in the process of writing this patch, I discovered Mocha's async error handling is a little buggy, which I had missed in my earlier test of it. Specifically, if an async error gets caught by Mocha and then `done()` is still called later, it can screw things up a bit. Mocha doesn't actually fully clean up the test when the async error is caught, but does fire test failure events :\

I think #136 is still worth fixing anyway, but I probably also need to file a bug on Mocha, too.