Skip to content

Instantly share code, notes, and snippets.

@othiym23
Created December 1, 2012 00:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save othiym23/4179636 to your computer and use it in GitHub Desktop.
Save othiym23/4179636 to your computer and use it in GitHub Desktop.
mocha is not your friend if you want to test uncaughtException handlers
before(function (done) {
/**
* Mocha is extremely zealous about trapping errors, and runs each test
* in a try / catch block. To get the exception to propagate out to the
* domain's uncaughtException handler, we need to put the test in an
* asynchronous context and break out of the mocha jail.
*/
process.nextTick(function () {
// disable mocha's error handler
mochaHandler = process.listeners('uncaughtException').pop();
agent = helper.loadMockedAgent();
var disruptor = agent.tracer.transactionProxy(function () {
domain = agent.getTransaction().trace.domain;
active = process.domain;
active.once('error', function (e) {
json = agent.errors.errors[0];
return done();
});
// trigger the domain
throw new Error('sample error');
});
disruptor();
});
});
after(function () {
// ...but be sure to re-enable mocha's error handler
process.on('uncaughtException', mochaHandler);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment