Omit irrelevant properties from suiteStarted

This commit is contained in:
Steve Gravrock
2025-09-22 17:21:10 -07:00
parent 712f9bac29
commit 0738ba6462
9 changed files with 206 additions and 60 deletions

View File

@@ -37,11 +37,16 @@ describe('Runner', function() {
this.sharedUserContext = function() {
return attrs.userContext || {};
};
// TODO remove
this.result = {
id: this.id,
failedExpectations: []
};
this.getResult = jasmine.createSpy('getResult');
this.startedEvent = jasmine.createSpy('startedEvent');
this.doneEvent = jasmine.createSpy('doneEvent');
this.hasOwnFailedExpectations = jasmine.createSpy(
'hasOwnFailedExpectations'
);
this.beforeAllFns = attrs.beforeAllFns || [];
this.afterAllFns = attrs.afterAllFns || [];
this.cleanupBeforeAfter = function() {};
@@ -182,10 +187,13 @@ describe('Runner', function() {
SkipPolicy: privateUnderTest.SkipAfterBeforeAllErrorPolicy
});
suite.startedEvent.and.returnValue('suite started event');
runQueue.calls.mostRecent().args[0].queueableFns[0].fn('foo');
expect(reportDispatcher.suiteStarted).toHaveBeenCalledWith(suite.result);
expect(reportDispatcher.suiteStarted).toHaveBeenCalledWith(
'suite started event'
);
suite.getResult.and.returnValue({ my: 'result' });
suite.doneEvent.and.returnValue({ my: 'result' });
runQueue.calls.mostRecent().args[0].onComplete();
expect(reportDispatcher.suiteDone).toHaveBeenCalledWith({ my: 'result' });
@@ -233,12 +241,15 @@ describe('Runner', function() {
queueableFns = runQueue.calls.mostRecent().args[0].queueableFns;
expect(queueableFns.length).toBe(2);
parent.startedEvent.and.returnValue('parent suite started event');
queueableFns[0].fn();
expect(reportDispatcher.suiteStarted).toHaveBeenCalledWith(parent.result);
expect(reportDispatcher.suiteStarted).toHaveBeenCalledWith(
'parent suite started event'
);
verifyAndFinishSpec(spec, queueableFns[1], true);
parent.getResult.and.returnValue(parent.result);
parent.doneEvent.and.returnValue(parent.result);
runQueue.calls.argsFor(1)[0].onComplete();
expect(reportDispatcher.suiteDone).toHaveBeenCalledWith(parent.result);
await expectAsync(promise).toBePending();

View File

@@ -425,4 +425,34 @@ describe('Suite', function() {
}).toThrowError("Value can't be cloned");
});
});
describe('#startedEvent', function() {
it('includes only properties that are known before execution', function() {
const topSuite = new privateUnderTest.Suite({});
const parentSuite = new privateUnderTest.Suite({
id: 'suite1',
parentSuite: topSuite,
description: 'a parent suite'
});
const suite = new privateUnderTest.Suite({
id: 'suite2',
parentSuite,
reportedParentSuiteId: parentSuite.id,
description: 'a suite',
filename: 'somefile.js',
getPath() {
return ['a parent suite', 'a spec'];
},
queueableFn: { fn: () => {} }
});
expect(suite.startedEvent()).toEqual({
id: 'suite2',
parentSuiteId: 'suite1',
description: 'a suite',
fullName: 'a parent suite a suite',
filename: 'somefile.js'
});
});
});
});

View File

@@ -1765,10 +1765,12 @@ describe('Env integration', function() {
const baseSuiteEvent = {
id: jasmine.any(String),
filename: jasmine.any(String),
filename: jasmine.any(String)
};
const baseSuiteDoneEvent = {
...baseSuiteEvent,
failedExpectations: [],
deprecationWarnings: [],
duration: null,
properties: null
};
@@ -1779,7 +1781,7 @@ describe('Env integration', function() {
parentSuiteId: null
});
expect(reporter.suiteDone.calls.argsFor(2)[0]).toEqual({
...baseSuiteEvent,
...baseSuiteDoneEvent,
description: 'A Suite',
fullName: 'A Suite',
status: 'passed',
@@ -1794,7 +1796,7 @@ describe('Env integration', function() {
parentSuiteId: suiteFullNameToId['A Suite']
});
expect(reporter.suiteDone.calls.argsFor(0)[0]).toEqual({
...baseSuiteEvent,
...baseSuiteDoneEvent,
description: 'with a nested suite',
status: 'passed',
fullName: 'A Suite with a nested suite',
@@ -1809,7 +1811,7 @@ describe('Env integration', function() {
parentSuiteId: suiteFullNameToId['A Suite']
});
expect(reporter.suiteDone.calls.argsFor(1)[0]).toEqual({
...baseSuiteEvent,
...baseSuiteDoneEvent,
description: 'with only non-executable specs',
status: 'passed',
fullName: 'A Suite with only non-executable specs',