diff --git a/spec/core/TreeRunnerSpec.js b/spec/core/TreeRunnerSpec.js index 17e6e3bc..d9184845 100644 --- a/spec/core/TreeRunnerSpec.js +++ b/spec/core/TreeRunnerSpec.js @@ -2,46 +2,22 @@ describe('TreeRunner', function() { describe('spec execution', function() { it('starts the timer, reports the spec started, and updates run state at the start of the queue', async function() { const timer = jasmine.createSpyObj('timer', ['start']); - const topSuiteId = 'suite1'; const spec = new jasmineUnderTest.Spec({ id: 'spec1', - parentSuiteId: topSuiteId, queueableFn: {}, timer }); - const topSuite = new jasmineUnderTest.Suite({ id: topSuiteId }); - topSuite.addChild(spec); - const executionTree = { - topSuite, - childrenOfTopSuite() { - return [{ spec }]; - }, - isExcluded() { - return false; - } - }; - const runQueue = jasmine.createSpy('runQueue'); - const reportDispatcher = mockReportDispatcher(); - const runableResources = mockRunableResources(); - const currentRunableTracker = new jasmineUnderTest.CurrentRunableTracker(); - const subject = new jasmineUnderTest.TreeRunner({ - executionTree, + const { runQueue, + currentRunableTracker, runableResources, reportDispatcher, - currentRunableTracker, - getConfig() { - return {}; - }, - reportChildrenOfBeforeAllFailure() {} - }); - - const promise = subject.execute(); - expect(runQueue).toHaveBeenCalledTimes(1); - const suiteRunQueueArgs = runQueue.calls.mostRecent().args[0]; + suiteRunQueueArgs, + executePromise + } = runSingleSpecSuite(spec); suiteRunQueueArgs.queueableFns[0].fn(); - expect(runQueue).toHaveBeenCalledTimes(2); + expect(runQueue).toHaveBeenCalledTimes(1); const specRunQueueArgs = runQueue.calls.mostRecent().args[0]; const next = jasmine.createSpy('next'); specRunQueueArgs.queueableFns[0].fn(next); @@ -50,56 +26,33 @@ describe('TreeRunner', function() { expect(currentRunableTracker.currentRunable()).toBe(spec); expect(runableResources.initForRunable).toHaveBeenCalledWith( spec.id, - topSuite.id + spec.parentSuiteId ); expect(reportDispatcher.specStarted).toHaveBeenCalledWith(spec.result); await Promise.resolve(); expect(reportDispatcher.specStarted).toHaveBeenCalledBefore(next); - await expectAsync(promise).toBePending(); + await expectAsync(executePromise).toBePending(); }); it('stops the timer, updates run state, and reports the spec done at the end of the queue', async function() { const timer = jasmine.createSpyObj('timer', ['start', 'elapsed']); - const topSuiteId = 'suite1'; const spec = new jasmineUnderTest.Spec({ id: 'spec1', - parentSuiteId: topSuiteId, queueableFn: {}, timer }); - const topSuite = new jasmineUnderTest.Suite({ id: topSuiteId }); - topSuite.addChild(spec); - const executionTree = { - topSuite, - childrenOfTopSuite() { - return [{ spec }]; - }, - isExcluded() { - return false; - } - }; - const runQueue = jasmine.createSpy('runQueue'); - const reportDispatcher = mockReportDispatcher(); - const runableResources = mockRunableResources(); - const currentRunableTracker = new jasmineUnderTest.CurrentRunableTracker(); - const subject = new jasmineUnderTest.TreeRunner({ - executionTree, + const { runQueue, + currentRunableTracker, runableResources, reportDispatcher, - currentRunableTracker, - getConfig() { - return {}; - }, - reportChildrenOfBeforeAllFailure() {} - }); + suiteRunQueueArgs, + executePromise + } = runSingleSpecSuite(spec); - const promise = subject.execute(); - expect(runQueue).toHaveBeenCalledTimes(1); - const suiteRunQueueArgs = runQueue.calls.mostRecent().args[0]; suiteRunQueueArgs.queueableFns[0].fn(); - expect(runQueue).toHaveBeenCalledTimes(2); + expect(runQueue).toHaveBeenCalledTimes(1); const specRunQueueArgs = runQueue.calls.mostRecent().args[0]; const next = jasmine.createSpy('next'); timer.elapsed.and.returnValue('the elapsed time'); @@ -115,8 +68,53 @@ describe('TreeRunner', function() { await Promise.resolve(); await Promise.resolve(); expect(reportDispatcher.specDone).toHaveBeenCalledBefore(next); - await expectAsync(promise).toBePending(); + await expectAsync(executePromise).toBePending(); }); + + function runSingleSpecSuite(spec) { + const topSuiteId = 'suite1'; + spec.parentSuiteId = topSuiteId; + const topSuite = new jasmineUnderTest.Suite({ id: topSuiteId }); + topSuite.addChild(spec); + const executionTree = { + topSuite, + childrenOfTopSuite() { + return [{ spec }]; + }, + isExcluded() { + return false; + } + }; + const runQueue = jasmine.createSpy('runQueue'); + const reportDispatcher = mockReportDispatcher(); + const runableResources = mockRunableResources(); + const currentRunableTracker = new jasmineUnderTest.CurrentRunableTracker(); + const subject = new jasmineUnderTest.TreeRunner({ + executionTree, + runQueue, + runableResources, + reportDispatcher, + currentRunableTracker, + getConfig() { + return {}; + }, + reportChildrenOfBeforeAllFailure() {} + }); + + const executePromise = subject.execute(); + expect(runQueue).toHaveBeenCalledTimes(1); + const suiteRunQueueArgs = runQueue.calls.mostRecent().args[0]; + runQueue.calls.reset(); + + return { + runQueue, + currentRunableTracker, + runableResources, + reportDispatcher, + suiteRunQueueArgs, + executePromise + }; + } }); function mockReportDispatcher() {