Skip to content

Commit

Permalink
fix leaking uncaughtException handler
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jan 11, 2020
1 parent 7d78f20 commit 35a50c6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ Runner.prototype.runSuite = function(suite, fn) {
};

/**
* Handle uncaught exceptions.
* Handle uncaught exceptions within runner.
*
* @param {Error} err
* @private
Expand Down Expand Up @@ -893,6 +893,17 @@ Runner.prototype.uncaught = function(err) {
this.abort();
};

/**
* Handle uncaught exceptions after runner's end event.
*
* @param {Error} err
* @private
*/
Runner.prototype.uncaughtEnd = function uncaughtEnd(err) {
if (err instanceof Pending) return;
throw err;
};

/**
* Run the root suite and invoke `fn(failures)`
* on completion.
Expand Down Expand Up @@ -940,16 +951,12 @@ Runner.prototype.run = function(fn) {
this.on(constants.EVENT_RUN_END, function() {
debug(constants.EVENT_RUN_END);
process.removeListener('uncaughtException', uncaught);
process.on('uncaughtException', function(err) {
if (err instanceof Pending) {
return;
}
throw err;
});
process.on('uncaughtException', self.uncaughtEnd);
fn(self.failures);
});

// uncaught exception
process.removeListener('uncaughtException', self.uncaughtEnd);
process.on('uncaughtException', uncaught);

if (this._delay) {
Expand Down

0 comments on commit 35a50c6

Please sign in to comment.