Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

JohnQ: Fix for issue where uncaught exception listener was not being properly removed. - Occurs when you re-run a test suite with uncaught exceptions multiple times. - Store the uncaught function, and remove it properly.

Justin DuJardin02b9d0bff481
diff --git a/lib/runner.js b/lib/runner.js
index 03a11a1d..377ca41b 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -483,16 +483,17 @@ Runner.prototype.uncaught = function(err){
Runner.prototype.run = function(fn){
var self = this
- , fn = fn || function(){};
+ , fn = fn || function(){}
+ , uncaught = function(err){
+ self.uncaught(err);
+ };
debug('start');
// callback
this.on('end', function(){
debug('end');
- process.removeListener('uncaughtException', function(err){
- self.uncaught(err);
- });
+ process.removeListener('uncaughtException', uncaught);
fn(self.failures);
});
@@ -504,9 +505,7 @@ Runner.prototype.run = function(fn){
});
// uncaught exception
- process.on('uncaughtException', function(err){
- self.uncaught(err);
- });
+ process.on('uncaughtException', uncaught);
return this;
};