From 41f5c539597b82d7306240e206615eb95f3ca6f0 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Mon, 11 Oct 2021 17:58:40 -0700 Subject: [PATCH] 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. --- lib/jasmine-core/jasmine.js | 55 +++++--------- .../CompleteOnFirstErrorSkipPolicySpec.js | 74 ++++++++++--------- spec/core/QueueRunnerSpec.js | 64 ++++++---------- spec/core/SpecSpec.js | 47 +++++++----- spec/core/SuiteSpec.js | 42 ++++++++++- spec/core/TreeProcessorSpec.js | 29 ++++---- src/core/CompleteOnFirstErrorSkipPolicy.js | 18 ++--- src/core/NeverSkipPolicy.js | 2 +- src/core/QueueRunner.js | 6 +- src/core/SkipAfterBeforeAllErrorPolicy.js | 2 +- src/core/Spec.js | 10 +-- src/core/Suite.js | 6 +- src/core/TreeProcessor.js | 11 +-- 13 files changed, 182 insertions(+), 184 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index fe43148b..bc24d385 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -870,16 +870,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); }, @@ -909,11 +908,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); }; @@ -3466,9 +3464,8 @@ getJasmineRequireObj().Clock = function() { }; getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) { - function CompleteOnFirstErrorSkipPolicy(queueableFns, firstCleanupIx) { + function CompleteOnFirstErrorSkipPolicy(queueableFns) { this.queueableFns_ = queueableFns; - this.firstCleanupIx_ = firstCleanupIx; this.erroredFnIx_ = null; } @@ -3490,16 +3487,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)) ); }; @@ -7395,7 +7391,7 @@ getJasmineRequireObj().MockDate = function(j$) { }; getJasmineRequireObj().NeverSkipPolicy = function(j$) { - function NeverSkipPolicy(queueableFns, firstCleanupIx) {} + function NeverSkipPolicy(queueableFns) {} NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx) { return lastRanFnIx + 1; @@ -7849,9 +7845,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 || @@ -7872,7 +7866,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') { @@ -8610,7 +8604,7 @@ getJasmineRequireObj().interface = function(jasmine, env) { }; getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) { - function SkipAfterBeforeAllErrorPolicy(queueableFns, firstCleanupIx) { + function SkipAfterBeforeAllErrorPolicy(queueableFns) { this.queueableFns_ = queueableFns; this.skipping_ = false; } @@ -9600,15 +9594,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() { @@ -10112,16 +10106,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); } } diff --git a/spec/core/CompleteOnFirstErrorSkipPolicySpec.js b/spec/core/CompleteOnFirstErrorSkipPolicySpec.js index b1536ae0..babe4605 100644 --- a/spec/core/CompleteOnFirstErrorSkipPolicySpec.js +++ b/spec/core/CompleteOnFirstErrorSkipPolicySpec.js @@ -13,10 +13,9 @@ describe('CompleteOnFirstErrorSkipPolicy', function() { describe('After something has errored', function() { it('skips non cleanup fns', function() { const fns = arrayOfArbitraryFns(4); - const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy( - fns, - 2 - ); + fns[2].type = arbitraryCleanupType(); + fns[3].type = arbitraryCleanupType(); + const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns); policy.fnErrored(0); expect(policy.skipTo(0)).toEqual(2); @@ -24,6 +23,19 @@ describe('CompleteOnFirstErrorSkipPolicy', function() { expect(policy.skipTo(3)).toEqual(4); }); + for (const type of ['afterEach', 'specCleanup', 'afterAll']) { + it(`does not skip ${type} fns`, function() { + const fns = arrayOfArbitraryFns(2); + fns[1].type = type; + const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy( + fns + ); + + policy.fnErrored(0); + expect(policy.skipTo(0)).toEqual(1); + }); + } + describe('When the error was in a beforeEach fn', function() { it('runs cleanup fns defined by the current and containing suites', function() { const parentSuite = { description: 'parentSuite' }; @@ -37,16 +49,17 @@ describe('CompleteOnFirstErrorSkipPolicy', function() { }, { fn: () => {}, - suite: suite + suite: suite, + type: arbitraryCleanupType() }, { fn: () => {}, - suite: parentSuite + suite: parentSuite, + type: arbitraryCleanupType() } ]; const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy( - fns, - 2 + fns ); policy.fnErrored(0); @@ -68,16 +81,17 @@ describe('CompleteOnFirstErrorSkipPolicy', function() { }, { fn: () => {}, - suite: suite + suite: suite, + type: arbitraryCleanupType() }, { fn: () => {}, - suite: parentSuite + suite: parentSuite, + type: arbitraryCleanupType() } ]; const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy( - fns, - 2 + fns ); policy.fnErrored(0); @@ -86,42 +100,32 @@ describe('CompleteOnFirstErrorSkipPolicy', function() { }); it('does not skip cleanup fns that have no suite, such as the spec complete fn', function() { - const fns = [{ fn: () => {} }, { fn: () => {} }]; - const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy( - fns, - 1 - ); - - policy.fnErrored(0); - expect(policy.skipTo(0)).toEqual(1); - }); - - it('does not skip afterAll fns, even if before the first cleanup fn index', function() { const fns = [ { fn: () => {} }, { fn: () => {}, - type: 'afterAll' + type: arbitraryCleanupType() } ]; - const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy( - fns, - 2 - ); + const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(fns); policy.fnErrored(0); expect(policy.skipTo(0)).toEqual(1); }); }); }); -}); -function arrayOfArbitraryFns(n) { - const result = []; + function arrayOfArbitraryFns(n) { + const result = []; - for (let i = 0; i < n; i++) { - result.push({ fn: () => {} }); + for (let i = 0; i < n; i++) { + result.push({ fn: () => {} }); + } + + return result; } - return result; -} + function arbitraryCleanupType() { + return 'specCleanup'; + } +}); diff --git a/spec/core/QueueRunnerSpec.js b/spec/core/QueueRunnerSpec.js index 87f575fe..34141f4f 100644 --- a/spec/core/QueueRunnerSpec.js +++ b/spec/core/QueueRunnerSpec.js @@ -18,26 +18,6 @@ describe('QueueRunner', function() { expect(calls).toEqual(['fn1', 'fn2']); }); - it('runs cleanup functions after the others', function() { - var calls = [], - queueableFn1 = { fn: jasmine.createSpy('fn1') }, - queueableFn2 = { fn: jasmine.createSpy('fn2') }, - queueRunner = new jasmineUnderTest.QueueRunner({ - queueableFns: [queueableFn1], - cleanupFns: [queueableFn2] - }); - queueableFn1.fn.and.callFake(function() { - calls.push('fn1'); - }); - queueableFn2.fn.and.callFake(function() { - calls.push('fn2'); - }); - - queueRunner.execute(); - - expect(calls).toEqual(['fn1', 'fn2']); - }); - it("calls each function with a consistent 'this'-- an empty object", function() { var queueableFn1 = { fn: jasmine.createSpy('fn1') }, queueableFn2 = { fn: jasmine.createSpy('fn2') }, @@ -653,18 +633,13 @@ describe('QueueRunner', function() { it('instantiates the skip policy', function() { const SkipPolicy = jasmine.createSpy('SkipPolicy ctor'); const queueableFns = [{ fn: () => {} }, { fn: () => {} }]; - const cleanupFns = [{ fn: () => {} }]; new jasmineUnderTest.QueueRunner({ queueableFns, - cleanupFns, SkipPolicy }); - expect(SkipPolicy).toHaveBeenCalledWith( - [...queueableFns, ...cleanupFns], - 2 - ); + expect(SkipPolicy).toHaveBeenCalledWith(queueableFns); }); it('uses the skip policy to determine which fn to run next', function() { @@ -723,11 +698,13 @@ describe('QueueRunner', function() { } }, nextQueueableFn = { fn: jasmine.createSpy('nextFunction') }, - cleanupFn = { fn: jasmine.createSpy('cleanup') }, + cleanupFn = { + fn: jasmine.createSpy('cleanup'), + type: 'specCleanup' + }, onComplete = jasmine.createSpy('onComplete'), queueRunner = new jasmineUnderTest.QueueRunner({ - queueableFns: [queueableFn, nextQueueableFn], - cleanupFns: [cleanupFn], + queueableFns: [queueableFn, nextQueueableFn, cleanupFn], onComplete: onComplete, SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy }); @@ -745,12 +722,15 @@ describe('QueueRunner', function() { cleanupFn1 = { fn: function() { throw new Error('error'); - } + }, + type: 'afterEach' + }, + cleanupFn2 = { + fn: jasmine.createSpy('cleanupFn2'), + type: 'afterEach' }, - cleanupFn2 = { fn: jasmine.createSpy('cleanupFn2') }, queueRunner = new jasmineUnderTest.QueueRunner({ - queueableFns: [queueableFn], - cleanupFns: [cleanupFn1, cleanupFn2], + queueableFns: [queueableFn, cleanupFn1, cleanupFn2], SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy }); @@ -775,7 +755,7 @@ describe('QueueRunner', function() { } }, nextQueueableFn = { fn: jasmine.createSpy('nextFunction') }, - cleanupFn = { fn: jasmine.createSpy('cleanup') }, + cleanupFn = { fn: jasmine.createSpy('cleanup'), type: 'specCleanup' }, queueRunner = new jasmineUnderTest.QueueRunner({ globalErrors: { pushListener: function(f) { @@ -785,8 +765,7 @@ describe('QueueRunner', function() { errorListeners.pop(); } }, - queueableFns: [queueableFn, nextQueueableFn], - cleanupFns: [cleanupFn], + queueableFns: [queueableFn, nextQueueableFn, cleanupFn], SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy }), queueableFnDone; @@ -806,10 +785,9 @@ describe('QueueRunner', function() { } }, nextQueueableFn = { fn: jasmine.createSpy('nextFunction') }, - cleanupFn = { fn: jasmine.createSpy('cleanup') }, + cleanupFn = { fn: jasmine.createSpy('cleanup'), type: 'specCleanup' }, queueRunner = new jasmineUnderTest.QueueRunner({ - queueableFns: [queueableFn, nextQueueableFn], - cleanupFns: [cleanupFn], + queueableFns: [queueableFn, nextQueueableFn, cleanupFn], SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy }); @@ -826,10 +804,12 @@ describe('QueueRunner', function() { } }, nextQueueableFn = { fn: jasmine.createSpy('nextFunction') }, - cleanupFn = { fn: jasmine.createSpy('cleanup') }, + cleanupFn = { + fn: jasmine.createSpy('cleanup'), + type: 'specCleanup' + }, queueRunner = new jasmineUnderTest.QueueRunner({ - queueableFns: [queueableFn, nextQueueableFn], - cleanupFns: [cleanupFn], + queueableFns: [queueableFn, nextQueueableFn, cleanupFn], SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy }); diff --git a/spec/core/SpecSpec.js b/spec/core/SpecSpec.js index 5c29b80c..6abb1f9e 100644 --- a/spec/core/SpecSpec.js +++ b/spec/core/SpecSpec.js @@ -116,9 +116,13 @@ describe('Spec', function() { expect(options.queueableFns).toEqual([ { fn: jasmine.any(Function) }, before, - queueableFn + queueableFn, + after, + { + fn: jasmine.any(Function), + type: 'specCleanup' + } ]); - expect(options.cleanupFns).toEqual([after, { fn: jasmine.any(Function) }]); }); it("tells the queue runner that it's a leaf node", function() { @@ -171,8 +175,13 @@ describe('Spec', function() { expect(fakeQueueRunner).toHaveBeenCalledWith( jasmine.objectContaining({ onComplete: jasmine.any(Function), - queueableFns: [{ fn: jasmine.any(Function) }], - cleanupFns: [{ fn: jasmine.any(Function) }] + queueableFns: [ + { fn: jasmine.any(Function) }, + { + fn: jasmine.any(Function), + type: 'specCleanup' + } + ] }) ); expect(specBody).not.toHaveBeenCalled(); @@ -180,7 +189,7 @@ describe('Spec', function() { var args = fakeQueueRunner.calls.mostRecent().args[0]; args.queueableFns[0].fn(); expect(startCallback).toHaveBeenCalled(); - args.cleanupFns[0].fn(); + args.queueableFns[args.queueableFns.length - 1].fn(); expect(resultCallback).toHaveBeenCalled(); expect(spec.result.status).toBe('excluded'); @@ -212,7 +221,7 @@ describe('Spec', function() { var args = fakeQueueRunner.calls.mostRecent().args[0]; args.queueableFns[0].fn(); expect(startCallback).toHaveBeenCalled(); - args.cleanupFns[0].fn('things'); + args.queueableFns[1].fn('things'); expect(resultCallback).toHaveBeenCalledWith( { id: spec.id, @@ -284,9 +293,6 @@ describe('Spec', function() { config.queueableFns.forEach(function(qf) { qf.fn(); }); - config.cleanupFns.forEach(function(qf) { - qf.fn(); - }); config.onComplete(); }, timer: timer @@ -354,7 +360,9 @@ describe('Spec', function() { spec.execute(); - fakeQueueRunner.calls.mostRecent().args[0].cleanupFns[0].fn(); + const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns; + fns[fns.length - 1].fn(); + expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([ 'expectation1' ]); @@ -383,7 +391,8 @@ describe('Spec', function() { spec.execute(); - fakeQueueRunner.calls.mostRecent().args[0].cleanupFns[0].fn(); + const fns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns; + fns[fns.length - 1].fn(); expect(resultCallback.calls.first().args[0].passedExpectations).toEqual([ 'passed' ]); @@ -482,7 +491,7 @@ describe('Spec', function() { spec.execute(); var args = fakeQueueRunner.calls.mostRecent().args[0]; - args.cleanupFns[0].fn(); + args.queueableFns[args.queueableFns.length - 1].fn(); expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([ { error: 'foo', @@ -510,7 +519,7 @@ describe('Spec', function() { spec.execute(); var args = fakeQueueRunner.calls.mostRecent().args[0]; - args.cleanupFns[0].fn(); + args.queueableFns[args.queueableFns.length - 1].fn(); expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]); }); @@ -575,9 +584,9 @@ describe('Spec', function() { resultCallback: resultCallback, queueRunnerFactory: function(config) { spec.trace('msg'); - config.cleanupFns.forEach(function(fn) { + for (const fn of config.queueableFns) { fn.fn(); - }); + } config.onComplete(false); } }); @@ -598,9 +607,9 @@ describe('Spec', function() { resultCallback: resultCallback, queueRunnerFactory: function(config) { spec.trace('msg'); - config.cleanupFns.forEach(function(fn) { + for (const fn of config.queueableFns) { fn.fn(); - }); + } config.onComplete(false); } }); @@ -623,9 +632,9 @@ describe('Spec', function() { queueRunnerFactory: function(config) { spec.trace('msg'); spec.onException(new Error('nope')); - config.cleanupFns.forEach(function(fn) { + for (const fn of config.queueableFns) { fn.fn(); - }); + } config.onComplete(true); }, timer: timer diff --git a/spec/core/SuiteSpec.js b/spec/core/SuiteSpec.js index 098c67f1..84fce87e 100644 --- a/spec/core/SuiteSpec.js +++ b/spec/core/SuiteSpec.js @@ -43,7 +43,7 @@ describe('Suite', function() { expect(suite.getFullName()).toEqual('I am a parent suite I am a suite'); }); - it('adds before functions in order of needed execution', function() { + it('adds beforeEach functions in order of needed execution', function() { var suite = new jasmineUnderTest.Suite({ env: env, description: 'I am a suite' @@ -60,7 +60,24 @@ describe('Suite', function() { ]); }); - it('adds after functions in order of needed execution', function() { + it('adds beforeAll functions in order of needed execution', function() { + var suite = new jasmineUnderTest.Suite({ + env: env, + description: 'I am a suite' + }), + outerBefore = { fn: 'outerBeforeAll' }, + innerBefore = { fn: 'insideBeforeAll' }; + + suite.beforeAll(outerBefore); + suite.beforeAll(innerBefore); + + expect(suite.beforeAllFns).toEqual([ + { fn: outerBefore.fn, type: 'beforeAll' }, + { fn: innerBefore.fn, type: 'beforeAll' } + ]); + }); + + it('adds afterEach functions in order of needed execution', function() { var suite = new jasmineUnderTest.Suite({ env: env, description: 'I am a suite' @@ -72,8 +89,25 @@ describe('Suite', function() { suite.afterEach(innerAfter); expect(suite.afterFns).toEqual([ - { fn: innerAfter.fn, suite }, - { fn: outerAfter.fn, suite } + { fn: innerAfter.fn, suite, type: 'afterEach' }, + { fn: outerAfter.fn, suite, type: 'afterEach' } + ]); + }); + + it('adds afterAll functions in order of needed execution', function() { + const suite = new jasmineUnderTest.Suite({ + env: env, + description: 'I am a suite' + }), + outerAfter = { fn: 'outerAfterAll' }, + innerAfter = { fn: 'insideAfterAl' }; + + suite.afterAll(outerAfter); + suite.afterAll(innerAfter); + + expect(suite.afterAllFns).toEqual([ + { fn: innerAfter.fn, type: 'afterAll' }, + { fn: outerAfter.fn, type: 'afterAll' } ]); }); diff --git a/spec/core/TreeProcessorSpec.js b/spec/core/TreeProcessorSpec.js index a3967d42..7ada587d 100644 --- a/spec/core/TreeProcessorSpec.js +++ b/spec/core/TreeProcessorSpec.js @@ -505,27 +505,28 @@ describe('TreeProcessor', function() { expect(queueableFns).toEqual([ { fn: jasmine.any(Function) }, - { type: 'beforeAll', fn: 'beforeAll1', timeout: 1 }, - { type: 'beforeAll', fn: 'beforeAll2', timeout: 2 }, + { fn: 'beforeAll1', timeout: 1 }, + { fn: 'beforeAll2', timeout: 2 }, { fn: jasmine.any(Function) } ]); }); it('runs afterAlls for a node with children', function() { var leaf = new Leaf(), - node = new Node({ - children: [leaf], - afterAllFns: [{ fn: 'afterAll1' }, { fn: 'afterAll2' }] - }), - root = new Node({ children: [node] }), - queueRunner = jasmine.createSpy('queueRunner'), - processor = new jasmineUnderTest.TreeProcessor({ + afterAllFns = [{ fn: 'afterAll1' }, { fn: 'afterAll2' }]; + (node = new Node({ + children: [leaf], + afterAllFns + })), + (root = new Node({ children: [node] })), + (queueRunner = jasmine.createSpy('queueRunner')), + (processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [node.id], queueRunnerFactory: queueRunner - }), - treeComplete = jasmine.createSpy('treeComplete'), - nodeDone = jasmine.createSpy('nodeDone'); + })), + (treeComplete = jasmine.createSpy('treeComplete')), + (nodeDone = jasmine.createSpy('nodeDone')); processor.execute(treeComplete); var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns; @@ -536,8 +537,8 @@ describe('TreeProcessor', function() { expect(queueableFns).toEqual([ { fn: jasmine.any(Function) }, { fn: jasmine.any(Function) }, - { type: 'afterAll', fn: 'afterAll1' }, - { type: 'afterAll', fn: 'afterAll2' } + afterAllFns[0], + afterAllFns[1] ]); }); diff --git a/src/core/CompleteOnFirstErrorSkipPolicy.js b/src/core/CompleteOnFirstErrorSkipPolicy.js index afca843c..5be5c79f 100644 --- a/src/core/CompleteOnFirstErrorSkipPolicy.js +++ b/src/core/CompleteOnFirstErrorSkipPolicy.js @@ -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)) ); }; diff --git a/src/core/NeverSkipPolicy.js b/src/core/NeverSkipPolicy.js index 75fb78d9..7d72cd50 100644 --- a/src/core/NeverSkipPolicy.js +++ b/src/core/NeverSkipPolicy.js @@ -1,5 +1,5 @@ getJasmineRequireObj().NeverSkipPolicy = function(j$) { - function NeverSkipPolicy(queueableFns, firstCleanupIx) {} + function NeverSkipPolicy(queueableFns) {} NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx) { return lastRanFnIx + 1; diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js index 9223c5e0..ebf3b5c3 100644 --- a/src/core/QueueRunner.js +++ b/src/core/QueueRunner.js @@ -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') { diff --git a/src/core/SkipAfterBeforeAllErrorPolicy.js b/src/core/SkipAfterBeforeAllErrorPolicy.js index e2d37630..ce49a830 100644 --- a/src/core/SkipAfterBeforeAllErrorPolicy.js +++ b/src/core/SkipAfterBeforeAllErrorPolicy.js @@ -1,5 +1,5 @@ getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) { - function SkipAfterBeforeAllErrorPolicy(queueableFns, firstCleanupIx) { + function SkipAfterBeforeAllErrorPolicy(queueableFns) { this.queueableFns_ = queueableFns; this.skipping_ = false; } diff --git a/src/core/Spec.js b/src/core/Spec.js index d63b6f79..9b35f749 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -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); }; diff --git a/src/core/Suite.js b/src/core/Suite.js index 672bcb7e..2cb2e7ca 100644 --- a/src/core/Suite.js +++ b/src/core/Suite.js @@ -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() { diff --git a/src/core/TreeProcessor.js b/src/core/TreeProcessor.js index e3d8eeff..f93fc044 100644 --- a/src/core/TreeProcessor.js +++ b/src/core/TreeProcessor.js @@ -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); } }