Created
December 1, 2012 00:01
-
-
Save othiym23/4179636 to your computer and use it in GitHub Desktop.
mocha is not your friend if you want to test uncaughtException handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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