Skip everything except afterAll fns when a beforeAll fn errors

* Fixes #1533
This commit is contained in:
Steve Gravrock
2021-09-30 10:19:58 -07:00
parent 5eaeeb0b6c
commit 5f1ef5ac2b
14 changed files with 316 additions and 70 deletions

View File

@@ -83,6 +83,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$
);
@@ -1612,15 +1615,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;
@@ -3390,21 +3397,22 @@ getJasmineRequireObj().Clock = function() {
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;
};
@@ -7288,10 +7296,12 @@ getJasmineRequireObj().MockDate = function(j$) {
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;
};
@@ -7762,7 +7772,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));
@@ -7818,7 +7828,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
self.fail(err);
}
self.errored = errored = true;
self.recordError_(iterativeIndex);
}
function runNext() {
@@ -7844,7 +7854,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
}
}
),
errored = false,
timedOut = false,
queueableFn = self.queueableFns[iterativeIndex],
timeoutId,
@@ -7852,7 +7861,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
next.fail = function nextFail() {
self.fail.apply(null, arguments);
self.errored = errored = true;
self.recordError_(iterativeIndex);
next();
};
@@ -7895,15 +7904,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) {
@@ -7927,14 +7936,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();
@@ -7943,7 +7950,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");
@@ -7952,6 +7959,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;
@@ -8496,6 +8508,39 @@ getJasmineRequireObj().interface = function(jasmine, env) {
return jasmineInterface;
};
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;
};
getJasmineRequireObj().Spy = function(j$) {
var nextOrder = (function() {
var order = 0;
@@ -9942,7 +9987,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 };
})
);
}
}