From b599ab23b3d5f45762de1d339e7f1d3ebff15e43 Mon Sep 17 00:00:00 2001 From: juergba Date: Mon, 13 Jan 2020 13:53:41 +0100 Subject: [PATCH] remove recovery out of uncaught --- lib/runnable.js | 2 +- lib/runner.js | 49 +++++++++++-------------------------------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/lib/runnable.js b/lib/runnable.js index 2d0c428d46..15238535ae 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -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 diff --git a/lib/runner.js b/lib/runner.js index 948a9b9021..8bb647926b 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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); @@ -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; @@ -846,7 +842,7 @@ Runner.prototype.uncaught = function(err) { return; } - runnable.clearTimeout(); + // runnable.clearTimeout(); // ???? if (runnable.isFailed()) { // Ignore error if already failed @@ -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(); }; /**