Refactor TreeRunner specs
This commit is contained in:
+60
-62
@@ -2,46 +2,22 @@ describe('TreeRunner', function() {
|
|||||||
describe('spec execution', 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() {
|
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 timer = jasmine.createSpyObj('timer', ['start']);
|
||||||
const topSuiteId = 'suite1';
|
|
||||||
const spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
id: 'spec1',
|
id: 'spec1',
|
||||||
parentSuiteId: topSuiteId,
|
|
||||||
queueableFn: {},
|
queueableFn: {},
|
||||||
timer
|
timer
|
||||||
});
|
});
|
||||||
const topSuite = new jasmineUnderTest.Suite({ id: topSuiteId });
|
const {
|
||||||
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,
|
runQueue,
|
||||||
|
currentRunableTracker,
|
||||||
runableResources,
|
runableResources,
|
||||||
reportDispatcher,
|
reportDispatcher,
|
||||||
currentRunableTracker,
|
suiteRunQueueArgs,
|
||||||
getConfig() {
|
executePromise
|
||||||
return {};
|
} = runSingleSpecSuite(spec);
|
||||||
},
|
|
||||||
reportChildrenOfBeforeAllFailure() {}
|
|
||||||
});
|
|
||||||
|
|
||||||
const promise = subject.execute();
|
|
||||||
expect(runQueue).toHaveBeenCalledTimes(1);
|
|
||||||
const suiteRunQueueArgs = runQueue.calls.mostRecent().args[0];
|
|
||||||
suiteRunQueueArgs.queueableFns[0].fn();
|
suiteRunQueueArgs.queueableFns[0].fn();
|
||||||
|
|
||||||
expect(runQueue).toHaveBeenCalledTimes(2);
|
expect(runQueue).toHaveBeenCalledTimes(1);
|
||||||
const specRunQueueArgs = runQueue.calls.mostRecent().args[0];
|
const specRunQueueArgs = runQueue.calls.mostRecent().args[0];
|
||||||
const next = jasmine.createSpy('next');
|
const next = jasmine.createSpy('next');
|
||||||
specRunQueueArgs.queueableFns[0].fn(next);
|
specRunQueueArgs.queueableFns[0].fn(next);
|
||||||
@@ -50,56 +26,33 @@ describe('TreeRunner', function() {
|
|||||||
expect(currentRunableTracker.currentRunable()).toBe(spec);
|
expect(currentRunableTracker.currentRunable()).toBe(spec);
|
||||||
expect(runableResources.initForRunable).toHaveBeenCalledWith(
|
expect(runableResources.initForRunable).toHaveBeenCalledWith(
|
||||||
spec.id,
|
spec.id,
|
||||||
topSuite.id
|
spec.parentSuiteId
|
||||||
);
|
);
|
||||||
expect(reportDispatcher.specStarted).toHaveBeenCalledWith(spec.result);
|
expect(reportDispatcher.specStarted).toHaveBeenCalledWith(spec.result);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
expect(reportDispatcher.specStarted).toHaveBeenCalledBefore(next);
|
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() {
|
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 timer = jasmine.createSpyObj('timer', ['start', 'elapsed']);
|
||||||
const topSuiteId = 'suite1';
|
|
||||||
const spec = new jasmineUnderTest.Spec({
|
const spec = new jasmineUnderTest.Spec({
|
||||||
id: 'spec1',
|
id: 'spec1',
|
||||||
parentSuiteId: topSuiteId,
|
|
||||||
queueableFn: {},
|
queueableFn: {},
|
||||||
timer
|
timer
|
||||||
});
|
});
|
||||||
const topSuite = new jasmineUnderTest.Suite({ id: topSuiteId });
|
const {
|
||||||
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,
|
runQueue,
|
||||||
|
currentRunableTracker,
|
||||||
runableResources,
|
runableResources,
|
||||||
reportDispatcher,
|
reportDispatcher,
|
||||||
currentRunableTracker,
|
suiteRunQueueArgs,
|
||||||
getConfig() {
|
executePromise
|
||||||
return {};
|
} = runSingleSpecSuite(spec);
|
||||||
},
|
|
||||||
reportChildrenOfBeforeAllFailure() {}
|
|
||||||
});
|
|
||||||
|
|
||||||
const promise = subject.execute();
|
|
||||||
expect(runQueue).toHaveBeenCalledTimes(1);
|
|
||||||
const suiteRunQueueArgs = runQueue.calls.mostRecent().args[0];
|
|
||||||
suiteRunQueueArgs.queueableFns[0].fn();
|
suiteRunQueueArgs.queueableFns[0].fn();
|
||||||
|
|
||||||
expect(runQueue).toHaveBeenCalledTimes(2);
|
expect(runQueue).toHaveBeenCalledTimes(1);
|
||||||
const specRunQueueArgs = runQueue.calls.mostRecent().args[0];
|
const specRunQueueArgs = runQueue.calls.mostRecent().args[0];
|
||||||
const next = jasmine.createSpy('next');
|
const next = jasmine.createSpy('next');
|
||||||
timer.elapsed.and.returnValue('the elapsed time');
|
timer.elapsed.and.returnValue('the elapsed time');
|
||||||
@@ -115,8 +68,53 @@ describe('TreeRunner', function() {
|
|||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
expect(reportDispatcher.specDone).toHaveBeenCalledBefore(next);
|
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() {
|
function mockReportDispatcher() {
|
||||||
|
|||||||
Reference in New Issue
Block a user