Encapsulate suite result

This commit is contained in:
Steve Gravrock
2025-10-04 09:40:10 -07:00
parent 0738ba6462
commit 18491e9b84
8 changed files with 55 additions and 82 deletions
+6 -7
View File
@@ -37,11 +37,6 @@ describe('Runner', function() {
this.sharedUserContext = function() {
return attrs.userContext || {};
};
// TODO remove
this.result = {
id: this.id,
failedExpectations: []
};
this.startedEvent = jasmine.createSpy('startedEvent');
this.doneEvent = jasmine.createSpy('doneEvent');
this.hasOwnFailedExpectations = jasmine.createSpy(
@@ -132,6 +127,7 @@ describe('Runner', function() {
children: [spec],
userContext: { root: 'context' }
});
topSuite.doneEvent.and.returnValue({});
detectLateRejectionHandling = true;
const subject = makeRunner(topSuite);
@@ -159,6 +155,7 @@ describe('Runner', function() {
children: [suite],
userContext: { for: 'topSuite' }
});
topSuite.doneEvent.and.returnValue({});
suite.parentSuite = topSuite;
const subject = makeRunner(topSuite);
@@ -249,9 +246,11 @@ describe('Runner', function() {
verifyAndFinishSpec(spec, queueableFns[1], true);
parent.doneEvent.and.returnValue(parent.result);
parent.doneEvent.and.returnValue('parent suite done event');
runQueue.calls.argsFor(1)[0].onComplete();
expect(reportDispatcher.suiteDone).toHaveBeenCalledWith(parent.result);
expect(reportDispatcher.suiteDone).toHaveBeenCalledWith(
'parent suite done event'
);
await expectAsync(promise).toBePending();
});
+2 -1
View File
@@ -311,10 +311,11 @@ describe('SuiteBuilder', function() {
suiteBuilder.topSuite.handleException(new Error('nope'));
suiteBuilder.parallelReset();
expect(suiteBuilder.topSuite.result).toEqual({
expect(suiteBuilder.topSuite.doneEvent()).toEqual({
id: suiteBuilder.topSuite.id,
description: 'Jasmine__TopLevel__Suite',
fullName: '',
status: 'passed',
failedExpectations: [],
deprecationWarnings: [],
duration: null,
+14 -14
View File
@@ -115,20 +115,20 @@ describe('Suite', function() {
const suite = new privateUnderTest.Suite({});
suite.addExpectationResult(false, {});
expect(suite.getResult().status).toBe('failed');
expect(suite.doneEvent().status).toBe('failed');
});
it('retrieves a result with updated status', function() {
const suite = new privateUnderTest.Suite({});
expect(suite.getResult().status).toBe('passed');
expect(suite.doneEvent().status).toBe('passed');
});
it('retrieves a result with pending status', function() {
const suite = new privateUnderTest.Suite({});
suite.pend();
expect(suite.getResult().status).toBe('pending');
expect(suite.doneEvent().status).toBe('pending');
});
it('throws an ExpectationFailed when receiving a failed expectation when throwOnExpectationFailure is set', function() {
@@ -140,8 +140,8 @@ describe('Suite', function() {
suite.addExpectationResult(false, { message: 'failed' });
}).toThrowError(jasmineUnderTest.private.errors.ExpectationFailed);
expect(suite.getResult().status).toBe('failed');
expect(suite.result.failedExpectations).toEqual([
expect(suite.doneEvent().status).toBe('failed');
expect(suite.doneEvent().failedExpectations).toEqual([
jasmine.objectContaining({ message: 'failed' })
]);
});
@@ -153,7 +153,7 @@ describe('Suite', function() {
new jasmineUnderTest.private.errors.ExpectationFailed()
);
expect(suite.getResult().failedExpectations).toEqual([]);
expect(suite.doneEvent().failedExpectations).toEqual([]);
});
it('forwards late expectation failures to onLateError', function() {
@@ -175,7 +175,7 @@ describe('Suite', function() {
message: jasmine.stringMatching(/^Error: nope/)
})
);
expect(suite.result.failedExpectations).toEqual([]);
expect(suite.doneEvent().failedExpectations).toEqual([]);
});
it('does not forward non-late expectation failures to onLateError', function() {
@@ -194,7 +194,7 @@ describe('Suite', function() {
suite.addExpectationResult(false, data, true);
expect(onLateError).not.toHaveBeenCalled();
expect(suite.result.failedExpectations.length).toEqual(1);
expect(suite.doneEvent().failedExpectations.length).toEqual(1);
});
it('forwards late handleException calls to onLateError', function() {
@@ -212,7 +212,7 @@ describe('Suite', function() {
message: jasmine.stringMatching(/^Error: oops/)
})
);
expect(suite.result.failedExpectations).toEqual([]);
expect(suite.doneEvent().failedExpectations).toEqual([]);
});
it('does not forward non-late handleException calls to onLateError', function() {
@@ -225,7 +225,7 @@ describe('Suite', function() {
suite.handleException(error);
expect(onLateError).not.toHaveBeenCalled();
expect(suite.result.failedExpectations.length).toEqual(1);
expect(suite.doneEvent().failedExpectations.length).toEqual(1);
});
it('clears the reportedDone flag when reset', function() {
@@ -248,7 +248,7 @@ describe('Suite', function() {
});
suite.startTimer();
suite.endTimer();
expect(suite.getResult().duration).toEqual(77000);
expect(suite.doneEvent().duration).toEqual(77000);
});
describe('#sharedUserContext', function() {
@@ -306,14 +306,14 @@ describe('Suite', function() {
const suite = new privateUnderTest.Suite({});
suite.pend();
suite.reset();
expect(suite.getResult().status).toBe('passed');
expect(suite.doneEvent().status).toBe('passed');
});
it('should not reset the "pending" status when the suite was excluded', function() {
const suite = new privateUnderTest.Suite({});
suite.exclude();
suite.reset();
expect(suite.getResult().status).toBe('pending');
expect(suite.doneEvent().status).toBe('pending');
});
it('should also reset the children', function() {
@@ -335,7 +335,7 @@ describe('Suite', function() {
suite.reset();
const result = suite.getResult();
const result = suite.doneEvent();
expect(result.status).toBe('passed');
expect(result.failedExpectations).toHaveSize(0);
});
+1 -1
View File
@@ -218,7 +218,7 @@ describe('TreeRunner', function() {
timer.elapsed.and.returnValue('the duration');
suiteRunQueueOpts.onComplete();
expect(timer.elapsed).toHaveBeenCalled();
const result = suite.getResult();
const result = suite.doneEvent();
expect(result.duration).toEqual('the duration');
expect(reportDispatcher.suiteDone).toHaveBeenCalledWith(result);