Replace old "catch exceptions" logic with proper fail fast with error reporting
- Option is called stopOnSpecFailure [#85966014] - See #414 - See jasmine/jasmine-npm#16
This commit is contained in:
@@ -13,8 +13,6 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var totalSpecsDefined = 0;
|
||||
|
||||
var catchExceptions = true;
|
||||
|
||||
var realSetTimeout = j$.getGlobal().setTimeout;
|
||||
var realClearTimeout = j$.getGlobal().clearTimeout;
|
||||
var clearStack = j$.getClearStack(j$.getGlobal());
|
||||
@@ -26,6 +24,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var currentlyExecutingSuites = [];
|
||||
var currentDeclarationSuite = null;
|
||||
var throwOnExpectationFailure = false;
|
||||
var stopOnSpecFailure = false;
|
||||
var random = true;
|
||||
var seed = null;
|
||||
var handlingLoadErrors = true;
|
||||
@@ -160,23 +159,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return buildExpectationResult(attrs);
|
||||
};
|
||||
|
||||
// TODO: fix this naming, and here's where the value comes in
|
||||
this.catchExceptions = function(value) {
|
||||
catchExceptions = !!value;
|
||||
return catchExceptions;
|
||||
};
|
||||
|
||||
this.catchingExceptions = function() {
|
||||
return catchExceptions;
|
||||
};
|
||||
|
||||
var maximumSpecCallbackDepth = 20;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
|
||||
var catchException = function(e) {
|
||||
return j$.Spec.isPendingSpecException(e) || catchExceptions;
|
||||
};
|
||||
|
||||
this.throwOnExpectationFailure = function(value) {
|
||||
throwOnExpectationFailure = !!value;
|
||||
};
|
||||
@@ -185,6 +170,14 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return throwOnExpectationFailure;
|
||||
};
|
||||
|
||||
this.stopOnSpecFailure = function(value) {
|
||||
stopOnSpecFailure = !!value;
|
||||
};
|
||||
|
||||
this.stoppingOnSpecFailure = function() {
|
||||
return stopOnSpecFailure;
|
||||
};
|
||||
|
||||
this.randomizeTests = function(value) {
|
||||
random = !!value;
|
||||
};
|
||||
@@ -208,12 +201,17 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
var queueRunnerFactory = function(options, args) {
|
||||
options.catchException = catchException;
|
||||
var failFast = false;
|
||||
if (options.isLeaf) {
|
||||
failFast = throwOnExpectationFailure;
|
||||
} else if (!options.isReporter) {
|
||||
failFast = stopOnSpecFailure;
|
||||
}
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||
options.fail = self.fail;
|
||||
options.globalErrors = globalErrors;
|
||||
options.completeOnFirstError = throwOnExpectationFailure && options.isLeaf;
|
||||
options.completeOnFirstError = failFast;
|
||||
options.onException = options.onException || function(e) {
|
||||
(currentRunnable() || topSuite).onException(e);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
function StopExecutionError() {}
|
||||
StopExecutionError.prototype = new Error();
|
||||
j$.StopExecutionError = StopExecutionError;
|
||||
|
||||
function once(fn) {
|
||||
var called = false;
|
||||
@@ -18,12 +21,12 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
this.onComplete = attrs.onComplete || function() {};
|
||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||
this.onException = attrs.onException || function() {};
|
||||
this.catchException = attrs.catchException || function() { return true; };
|
||||
this.userContext = attrs.userContext || new j$.UserContext();
|
||||
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;
|
||||
this.errored = false;
|
||||
|
||||
if (typeof(this.onComplete) !== 'function') {
|
||||
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
|
||||
@@ -69,8 +72,10 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
cleanup();
|
||||
|
||||
if (j$.isError_(err)) {
|
||||
self.fail(err);
|
||||
errored = true;
|
||||
if (!(err instanceof StopExecutionError)) {
|
||||
self.fail(err);
|
||||
}
|
||||
self.errored = errored = true;
|
||||
}
|
||||
|
||||
function runNext() {
|
||||
@@ -93,7 +98,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
next.fail = function nextFail() {
|
||||
self.fail.apply(null, arguments);
|
||||
errored = true;
|
||||
self.errored = errored = true;
|
||||
next();
|
||||
};
|
||||
|
||||
@@ -122,8 +127,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
return { completedSynchronously: false };
|
||||
}
|
||||
} catch (e) {
|
||||
handleException(e, queueableFn);
|
||||
errored = true;
|
||||
onException(e);
|
||||
self.errored = errored = true;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
@@ -131,22 +136,13 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
function onException(e) {
|
||||
self.onException(e);
|
||||
errored = true;
|
||||
self.errored = errored = true;
|
||||
}
|
||||
|
||||
function onPromiseRejection(e) {
|
||||
onException(e);
|
||||
next();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
QueueRunner.prototype.run = function(recursiveIndex) {
|
||||
@@ -162,6 +158,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.errored = result.errored;
|
||||
|
||||
if (this.completeOnFirstError && result.errored) {
|
||||
this.skipToCleanup(iterativeIndex);
|
||||
return;
|
||||
@@ -170,7 +168,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
this.clearStack(function() {
|
||||
self.globalErrors.popListener(self.handleFinalError);
|
||||
self.onComplete();
|
||||
self.onComplete(self.errored && new StopExecutionError());
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@@ -43,7 +43,8 @@ getJasmineRequireObj().ReportDispatcher = function(j$) {
|
||||
|
||||
queueRunnerFactory({
|
||||
queueableFns: fns,
|
||||
onComplete: onComplete
|
||||
onComplete: onComplete,
|
||||
isReporter: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,9 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
onException: function () {
|
||||
self.onException.apply(self, arguments);
|
||||
},
|
||||
onComplete: onComplete,
|
||||
onComplete: function() {
|
||||
onComplete(self.result.status === 'failed' && new j$.StopExecutionError('spec failed'));
|
||||
},
|
||||
userContext: this.userContext()
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user