Skip everything except afterAll fns when a beforeAll fn errors
* Fixes #1533
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
|
||||
function CompleteOnFirstErrorSkipPolicy(queueableFns, firstCleanupIx) {
|
||||
this.queueableFns_ = queueableFns;
|
||||
this.firstCleanupIx_ = firstCleanupIx;
|
||||
this.skipping_ = false;
|
||||
}
|
||||
|
||||
CompleteOnFirstErrorSkipPolicy.prototype.skipTo = function(
|
||||
lastRanFnIx,
|
||||
errored
|
||||
) {
|
||||
if (errored && lastRanFnIx < this.firstCleanupIx_) {
|
||||
CompleteOnFirstErrorSkipPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||
if (this.skipping_ && lastRanFnIx < this.firstCleanupIx_) {
|
||||
return this.firstCleanupIx_;
|
||||
} else {
|
||||
return lastRanFnIx + 1;
|
||||
}
|
||||
};
|
||||
|
||||
CompleteOnFirstErrorSkipPolicy.prototype.fnErrored = function(fnIx) {
|
||||
this.skipping_ = true;
|
||||
};
|
||||
|
||||
return CompleteOnFirstErrorSkipPolicy;
|
||||
};
|
||||
|
||||
@@ -502,15 +502,19 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
var queueRunnerFactory = function(options, args) {
|
||||
if (
|
||||
if (options.isLeaf) {
|
||||
// A spec
|
||||
options.isLeaf ||
|
||||
// A suite, and config.stopOnSpecFailure is set
|
||||
(!options.isLeaf && !options.isReporter && config.stopOnSpecFailure)
|
||||
) {
|
||||
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||
} else {
|
||||
} else if (options.isReporter) {
|
||||
// A reporter queue
|
||||
options.SkipPolicy = j$.NeverSkipPolicy;
|
||||
} else {
|
||||
// A suite
|
||||
if (config.stopOnSpecFailure) {
|
||||
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||
} else {
|
||||
options.SkipPolicy = j$.SkipAfterBeforeAllErrorPolicy;
|
||||
}
|
||||
}
|
||||
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
getJasmineRequireObj().NeverSkipPolicy = function(j$) {
|
||||
function NeverSkipPolicy(queueableFns, firstCleanupIx) {}
|
||||
|
||||
NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx, errored) {
|
||||
NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||
return lastRanFnIx + 1;
|
||||
};
|
||||
|
||||
NeverSkipPolicy.prototype.fnErrored = function(fnIx) {};
|
||||
|
||||
return NeverSkipPolicy;
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
const SkipPolicy = attrs.SkipPolicy || j$.NeverSkipPolicy;
|
||||
this.skipPolicy_ = new SkipPolicy(this.queueableFns, this.firstCleanupIx);
|
||||
this.errored = false;
|
||||
this.errored_ = false;
|
||||
|
||||
if (typeof this.onComplete !== 'function') {
|
||||
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
|
||||
@@ -115,7 +115,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
|
||||
self.fail(err);
|
||||
}
|
||||
self.errored = errored = true;
|
||||
self.recordError_(iterativeIndex);
|
||||
}
|
||||
|
||||
function runNext() {
|
||||
@@ -141,7 +141,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
}
|
||||
}
|
||||
),
|
||||
errored = false,
|
||||
timedOut = false,
|
||||
queueableFn = self.queueableFns[iterativeIndex],
|
||||
timeoutId,
|
||||
@@ -149,7 +148,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
next.fail = function nextFail() {
|
||||
self.fail.apply(null, arguments);
|
||||
self.errored = errored = true;
|
||||
self.recordError_(iterativeIndex);
|
||||
next();
|
||||
};
|
||||
|
||||
@@ -192,15 +191,15 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
}
|
||||
} catch (e) {
|
||||
onException(e);
|
||||
self.errored = errored = true;
|
||||
self.recordError_(iterativeIndex);
|
||||
}
|
||||
|
||||
cleanup();
|
||||
return { completedSynchronously: true, errored: errored };
|
||||
return { completedSynchronously: true };
|
||||
|
||||
function onException(e) {
|
||||
self.onException(e);
|
||||
self.errored = errored = true;
|
||||
self.recordError_(iterativeIndex);
|
||||
}
|
||||
|
||||
function onPromiseRejection(e) {
|
||||
@@ -224,14 +223,12 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
if (!result.completedSynchronously) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.errored = self.errored || result.errored;
|
||||
}
|
||||
|
||||
this.clearStack(function() {
|
||||
self.globalErrors.popListener(self.handleFinalError);
|
||||
|
||||
if (self.errored) {
|
||||
if (self.errored_) {
|
||||
self.onComplete(new StopExecutionError());
|
||||
} else {
|
||||
self.onComplete();
|
||||
@@ -240,7 +237,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
};
|
||||
|
||||
QueueRunner.prototype.nextFnIx_ = function(currentFnIx) {
|
||||
const result = this.skipPolicy_.skipTo(currentFnIx, this.errored);
|
||||
const result = this.skipPolicy_.skipTo(currentFnIx);
|
||||
|
||||
if (result === currentFnIx) {
|
||||
throw new Error("Can't skip to the same queueable fn that just finished");
|
||||
@@ -249,6 +246,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
return result;
|
||||
};
|
||||
|
||||
QueueRunner.prototype.recordError_ = function(currentFnIx) {
|
||||
this.errored_ = true;
|
||||
this.skipPolicy_.fnErrored(currentFnIx);
|
||||
};
|
||||
|
||||
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
||||
var msg;
|
||||
|
||||
|
||||
32
src/core/SkipAfterBeforeAllErrorPolicy.js
Normal file
32
src/core/SkipAfterBeforeAllErrorPolicy.js
Normal file
@@ -0,0 +1,32 @@
|
||||
getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) {
|
||||
function SkipAfterBeforeAllErrorPolicy(queueableFns, firstCleanupIx) {
|
||||
this.queueableFns_ = queueableFns;
|
||||
this.skipping_ = false;
|
||||
}
|
||||
|
||||
SkipAfterBeforeAllErrorPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||
if (this.skipping_) {
|
||||
return this.nextAfterAllAfter_(lastRanFnIx);
|
||||
} else {
|
||||
return lastRanFnIx + 1;
|
||||
}
|
||||
};
|
||||
|
||||
SkipAfterBeforeAllErrorPolicy.prototype.nextAfterAllAfter_ = function(i) {
|
||||
for (
|
||||
i++;
|
||||
i < this.queueableFns_.length &&
|
||||
this.queueableFns_[i].type !== 'afterAll';
|
||||
i++
|
||||
) {}
|
||||
return i;
|
||||
};
|
||||
|
||||
SkipAfterBeforeAllErrorPolicy.prototype.fnErrored = function(fnIx) {
|
||||
if (this.queueableFns_[fnIx].type === 'beforeAll') {
|
||||
this.skipping_ = true;
|
||||
}
|
||||
};
|
||||
|
||||
return SkipAfterBeforeAllErrorPolicy;
|
||||
};
|
||||
@@ -253,7 +253,16 @@ getJasmineRequireObj().TreeProcessor = function() {
|
||||
return result;
|
||||
}
|
||||
|
||||
return node.beforeAllFns.concat(result).concat(node.afterAllFns);
|
||||
return node.beforeAllFns
|
||||
.map(function(fn) {
|
||||
return { type: 'beforeAll', ...fn };
|
||||
})
|
||||
.concat(result)
|
||||
.concat(
|
||||
node.afterAllFns.map(function(fn) {
|
||||
return { type: 'afterAll', ...fn };
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,9 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
||||
j$.SetContaining = jRequire.SetContaining(j$);
|
||||
j$.QueueRunner = jRequire.QueueRunner(j$);
|
||||
j$.NeverSkipPolicy = jRequire.NeverSkipPolicy(j$);
|
||||
j$.SkipAfterBeforeAllErrorPolicy = jRequire.SkipAfterBeforeAllErrorPolicy(
|
||||
j$
|
||||
);
|
||||
j$.CompleteOnFirstErrorSkipPolicy = jRequire.CompleteOnFirstErrorSkipPolicy(
|
||||
j$
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user