-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When stop on failure is enabled, skip subsequent it() and beforeEach().
Note: afterEach() functions are still run, because skipping them is highly likely to pollute specs that run after the failure. [Finishes #92252330] - Fixes #577 - Fixes #807
- Loading branch information
Showing
7 changed files
with
368 additions
and
56 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -473,10 +473,12 @@ getJasmineRequireObj().Spec = function(j$) { | |
} | ||
|
||
var fns = this.beforeAndAfterFns(); | ||
var allFns = fns.befores.concat(this.queueableFn).concat(fns.afters); | ||
var regularFns = fns.befores.concat(this.queueableFn); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ArnaudPel
|
||
|
||
this.queueRunnerFactory({ | ||
queueableFns: allFns, | ||
isLeaf: true, | ||
queueableFns: regularFns, | ||
cleanupFns: fns.afters, | ||
onException: function() { self.onException.apply(self, arguments); }, | ||
onComplete: complete, | ||
userContext: this.userContext() | ||
|
@@ -817,6 +819,7 @@ getJasmineRequireObj().Env = function(j$) { | |
options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}; | ||
options.fail = self.fail; | ||
options.globalErrors = globalErrors; | ||
options.completeOnFirstError = throwOnExpectationFailure && options.isLeaf; | ||
|
||
new j$.QueueRunner(options).execute(); | ||
}; | ||
|
@@ -1141,6 +1144,7 @@ getJasmineRequireObj().Env = function(j$) { | |
|
||
this.afterEach = function(afterEachFunction, timeout) { | ||
ensureIsFunctionOrAsync(afterEachFunction, 'afterEach'); | ||
afterEachFunction.isCleanup = true; | ||
currentDeclarationSuite.afterEach({ | ||
fn: afterEachFunction, | ||
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } | ||
|
@@ -1189,6 +1193,10 @@ getJasmineRequireObj().Env = function(j$) { | |
message: message, | ||
error: error && error.message ? error : null | ||
}); | ||
|
||
if (self.throwingExpectationFailures()) { | ||
throw new Error(message); | ||
} | ||
}; | ||
} | ||
|
||
|
@@ -3934,7 +3942,9 @@ getJasmineRequireObj().QueueRunner = function(j$) { | |
} | ||
|
||
function QueueRunner(attrs) { | ||
this.queueableFns = attrs.queueableFns || []; | ||
var queueableFns = attrs.queueableFns || []; | ||
this.queueableFns = queueableFns.concat(attrs.cleanupFns || []); | ||
this.firstCleanupIx = queueableFns.length; | ||
this.onComplete = attrs.onComplete || function() {}; | ||
this.clearStack = attrs.clearStack || function(fn) {fn();}; | ||
this.onException = attrs.onException || function() {}; | ||
|
@@ -3943,6 +3953,7 @@ getJasmineRequireObj().QueueRunner = function(j$) { | |
this.timeout = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout}; | ||
this.fail = attrs.fail || function() {}; | ||
this.globalErrors = attrs.globalErrors || { pushListener: function() {}, popListener: function() {} }; | ||
this.completeOnFirstError = !!attrs.completeOnFirstError; | ||
} | ||
|
||
QueueRunner.prototype.execute = function() { | ||
|
@@ -3951,20 +3962,32 @@ getJasmineRequireObj().QueueRunner = function(j$) { | |
self.onException(error); | ||
}; | ||
this.globalErrors.pushListener(this.handleFinalError); | ||
this.run(this.queueableFns, 0); | ||
this.run(0); | ||
}; | ||
|
||
QueueRunner.prototype.skipToCleanup = function(lastRanIndex) { | ||
if (lastRanIndex < this.firstCleanupIx) { | ||
this.run(this.firstCleanupIx); | ||
} else { | ||
this.run(lastRanIndex + 1); | ||
} | ||
}; | ||
|
||
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) { | ||
var length = queueableFns.length, | ||
QueueRunner.prototype.run = function(recursiveIndex) { | ||
var length = this.queueableFns.length, | ||
self = this, | ||
iterativeIndex; | ||
|
||
|
||
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { | ||
var queueableFn = queueableFns[iterativeIndex]; | ||
var completedSynchronously = attempt(queueableFn); | ||
var result = attempt(iterativeIndex); | ||
|
||
if (!completedSynchronously) { | ||
if (!result.completedSynchronously) { | ||
return; | ||
} | ||
|
||
if (this.completeOnFirstError && result.errored) { | ||
this.skipToCleanup(iterativeIndex); | ||
return; | ||
} | ||
} | ||
|
@@ -3974,7 +3997,7 @@ getJasmineRequireObj().QueueRunner = function(j$) { | |
self.onComplete(); | ||
}); | ||
|
||
function attempt(queueableFn) { | ||
function attempt() { | ||
var clearTimeout = function () { | ||
Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]); | ||
}, | ||
|
@@ -3992,18 +4015,28 @@ getJasmineRequireObj().QueueRunner = function(j$) { | |
}), | ||
next = once(function () { | ||
cleanup(); | ||
|
||
function runNext() { | ||
if (self.completeOnFirstError && errored) { | ||
self.skipToCleanup(iterativeIndex); | ||
} else { | ||
self.run(iterativeIndex + 1); | ||
} | ||
} | ||
|
||
if (completedSynchronously) { | ||
setTimeout(function() { | ||
self.run(queueableFns, iterativeIndex + 1); | ||
}); | ||
setTimeout(runNext); | ||
} else { | ||
self.run(queueableFns, iterativeIndex + 1); | ||
runNext(); | ||
} | ||
}), | ||
errored = false, | ||
queueableFn = self.queueableFns[iterativeIndex], | ||
timeoutId; | ||
|
||
next.fail = function() { | ||
self.fail.apply(null, arguments); | ||
errored = true; | ||
next(); | ||
}; | ||
|
||
|
@@ -4024,31 +4057,33 @@ getJasmineRequireObj().QueueRunner = function(j$) { | |
if (maybeThenable && j$.isFunction_(maybeThenable.then)) { | ||
maybeThenable.then(next, next.fail); | ||
completedSynchronously = false; | ||
return false; | ||
return { completedSynchronously: false }; | ||
} | ||
} else { | ||
queueableFn.fn.call(self.userContext, next); | ||
completedSynchronously = false; | ||
return false; | ||
return { completedSynchronously: false }; | ||
} | ||
} catch (e) { | ||
handleException(e, queueableFn); | ||
errored = true; | ||
} | ||
|
||
cleanup(); | ||
return true; | ||
} | ||
return { completedSynchronously: true, errored: errored }; | ||
|
||
function onException(e) { | ||
self.onException(e); | ||
} | ||
function onException(e) { | ||
self.onException(e); | ||
errored = true; | ||
} | ||
|
||
function handleException(e, queueableFn) { | ||
onException(e); | ||
if (!self.catchException(e)) { | ||
//TODO: set a var when we catch an exception and | ||
//use a finally block to close the loop in a nice way.. | ||
throw e; | ||
function handleException(e, queueableFn) { | ||
onException(e); | ||
if (!self.catchException(e)) { | ||
//TODO: set a var when we catch an exception and | ||
//use a finally block to close the loop in a nice way.. | ||
throw e; | ||
} | ||
} | ||
} | ||
}; | ||
|
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
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
Oops, something went wrong.
I'm sorry for polluting this PR, specifically adding a comment to this line, but I didn't find a way to add a comment for the whole PR.
My question is: what is this "stop on failure" feature about? I can neither find any code changes in this PR (except a "throwOnExpectationFailures" which obviously means something else) nor documentation in the official docs that would describe this feature. How do you enable it?