Consistently identify clenaup fns by a type tag, not position
This was already done for everything except spec cleanup fns, since the various skip policies need to know the difference between afterEach and afterAll.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
|
||||
function CompleteOnFirstErrorSkipPolicy(queueableFns, firstCleanupIx) {
|
||||
function CompleteOnFirstErrorSkipPolicy(queueableFns) {
|
||||
this.queueableFns_ = queueableFns;
|
||||
this.firstCleanupIx_ = firstCleanupIx;
|
||||
this.erroredFnIx_ = null;
|
||||
}
|
||||
|
||||
@@ -23,16 +22,15 @@ getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// firstCleanupIx_ isn't correct for suites with afterAll functions.
|
||||
// Rely on the type for those.
|
||||
if (this.queueableFns_[fnIx].type === 'afterAll') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const candidateSuite = this.queueableFns_[fnIx].suite;
|
||||
const fn = this.queueableFns_[fnIx];
|
||||
const candidateSuite = fn.suite;
|
||||
const errorSuite = this.queueableFns_[this.erroredFnIx_].suite;
|
||||
const wasCleanupFn =
|
||||
fn.type === 'afterEach' ||
|
||||
fn.type === 'afterAll' ||
|
||||
fn.type === 'specCleanup';
|
||||
return (
|
||||
fnIx < this.firstCleanupIx_ ||
|
||||
!wasCleanupFn ||
|
||||
(candidateSuite && isDescendent(candidateSuite, errorSuite))
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
getJasmineRequireObj().NeverSkipPolicy = function(j$) {
|
||||
function NeverSkipPolicy(queueableFns, firstCleanupIx) {}
|
||||
function NeverSkipPolicy(queueableFns) {}
|
||||
|
||||
NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||
return lastRanFnIx + 1;
|
||||
|
||||
@@ -35,9 +35,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
|
||||
function QueueRunner(attrs) {
|
||||
this.id_ = nextid++;
|
||||
var queueableFns = attrs.queueableFns || [];
|
||||
this.queueableFns = queueableFns.concat(attrs.cleanupFns || []);
|
||||
this.firstCleanupIx = queueableFns.length;
|
||||
this.queueableFns = attrs.queueableFns || [];
|
||||
this.onComplete = attrs.onComplete || emptyFn;
|
||||
this.clearStack =
|
||||
attrs.clearStack ||
|
||||
@@ -58,7 +56,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
};
|
||||
|
||||
const SkipPolicy = attrs.SkipPolicy || j$.NeverSkipPolicy;
|
||||
this.skipPolicy_ = new SkipPolicy(this.queueableFns, this.firstCleanupIx);
|
||||
this.skipPolicy_ = new SkipPolicy(this.queueableFns);
|
||||
this.errored_ = false;
|
||||
|
||||
if (typeof this.onComplete !== 'function') {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) {
|
||||
function SkipAfterBeforeAllErrorPolicy(queueableFns, firstCleanupIx) {
|
||||
function SkipAfterBeforeAllErrorPolicy(queueableFns) {
|
||||
this.queueableFns_ = queueableFns;
|
||||
this.skipping_ = false;
|
||||
}
|
||||
|
||||
@@ -137,16 +137,15 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
}
|
||||
|
||||
self.resultCallback(self.result, done);
|
||||
}
|
||||
},
|
||||
type: 'specCleanup'
|
||||
};
|
||||
|
||||
var fns = this.beforeAndAfterFns();
|
||||
var regularFns = fns.befores.concat(this.queueableFn);
|
||||
|
||||
var runnerConfig = {
|
||||
isLeaf: true,
|
||||
queueableFns: regularFns,
|
||||
cleanupFns: fns.afters,
|
||||
queueableFns: [...fns.befores, this.queueableFn, ...fns.afters],
|
||||
onException: function() {
|
||||
self.onException.apply(self, arguments);
|
||||
},
|
||||
@@ -176,11 +175,10 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
|
||||
if (this.markedPending || excluded === true) {
|
||||
runnerConfig.queueableFns = [];
|
||||
runnerConfig.cleanupFns = [];
|
||||
}
|
||||
|
||||
runnerConfig.queueableFns.unshift(onStart);
|
||||
runnerConfig.cleanupFns.push(complete);
|
||||
runnerConfig.queueableFns.push(complete);
|
||||
|
||||
this.queueRunnerFactory(runnerConfig);
|
||||
};
|
||||
|
||||
@@ -103,15 +103,15 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
};
|
||||
|
||||
Suite.prototype.beforeAll = function(fn) {
|
||||
this.beforeAllFns.push(fn);
|
||||
this.beforeAllFns.push({ ...fn, type: 'beforeAll' });
|
||||
};
|
||||
|
||||
Suite.prototype.afterEach = function(fn) {
|
||||
this.afterFns.unshift({ ...fn, suite: this });
|
||||
this.afterFns.unshift({ ...fn, suite: this, type: 'afterEach' });
|
||||
};
|
||||
|
||||
Suite.prototype.afterAll = function(fn) {
|
||||
this.afterAllFns.unshift(fn);
|
||||
this.afterAllFns.unshift({ ...fn, type: 'afterAll' });
|
||||
};
|
||||
|
||||
Suite.prototype.startTimer = function() {
|
||||
|
||||
@@ -253,16 +253,7 @@ getJasmineRequireObj().TreeProcessor = function() {
|
||||
return result;
|
||||
}
|
||||
|
||||
return node.beforeAllFns
|
||||
.map(function(fn) {
|
||||
return { type: 'beforeAll', ...fn };
|
||||
})
|
||||
.concat(result)
|
||||
.concat(
|
||||
node.afterAllFns.map(function(fn) {
|
||||
return { type: 'afterAll', ...fn };
|
||||
})
|
||||
);
|
||||
return node.beforeAllFns.concat(result).concat(node.afterAllFns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user