Skip to content

Commit

Permalink
remove recovery out of uncaught
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jan 13, 2020
1 parent 0e1ccbb commit b599ab2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/runnable.js
Expand Up @@ -335,7 +335,7 @@ Runnable.prototype.run = function(fn) {
fn(err);
}

// for .resetTimeout()
// for .resetTimeout() and Runner#uncaught()
this.callback = done;

// explicit async with `done` argument
Expand Down
49 changes: 11 additions & 38 deletions lib/runner.js
Expand Up @@ -806,12 +806,9 @@ Runner.prototype.runSuite = function(suite, fn) {
* @private
*/
Runner.prototype.uncaught = function(err) {
if (err instanceof Pending) {
return;
}
if (this.allowUncaught) {
throw err;
}
if (err instanceof Pending) return;

if (this.allowUncaught) throw err;

if (err) {
debug('uncaught exception %O', err);
Expand All @@ -823,9 +820,8 @@ Runner.prototype.uncaught = function(err) {
);
}

if (!isError(err)) {
err = thrown2Error(err);
}
if (!isError(err)) err = thrown2Error(err);

err.uncaught = true;

var runnable = this.currentRunnable;
Expand All @@ -846,7 +842,7 @@ Runner.prototype.uncaught = function(err) {
return;
}

runnable.clearTimeout();
// runnable.clearTimeout(); // ????

if (runnable.isFailed()) {
// Ignore error if already failed
Expand All @@ -861,36 +857,13 @@ Runner.prototype.uncaught = function(err) {

// we cannot recover gracefully if a Runnable has already passed
// then fails asynchronously
var alreadyPassed = runnable.isPassed();
// this will change the state to "failed" regardless of the current value
this.fail(runnable, err);
if (!alreadyPassed) {
// recover from test
if (runnable.type === constants.EVENT_TEST_BEGIN) {
this.emit(constants.EVENT_TEST_END, runnable);
this.hookUp(HOOK_TYPE_AFTER_EACH, this.next);
return;
}
if (runnable.isPassed()) {
this.fail(runnable, err);
this.abort();
} else {
debug(runnable);

// recover from hooks
var errSuite = this.suite;

// XXX how about a less awful way to determine this?
// if hook failure is in afterEach block
if (runnable.fullTitle().indexOf('after each') > -1) {
return this.hookErr(err, errSuite, true);
}
// if hook failure is in beforeEach block
if (runnable.fullTitle().indexOf('before each') > -1) {
return this.hookErr(err, errSuite, false);
}
// if hook failure is in after or before blocks
return this.nextSuite(errSuite);
return runnable.callback(err);
}

// bail
this.abort();
};

/**
Expand Down

0 comments on commit b599ab2

Please sign in to comment.