More precisely characterize suite/spec reporting

This commit is contained in:
Steve Gravrock
2025-09-13 10:09:45 -07:00
parent 0bf9aff195
commit 3d8396da0a

View File

@@ -1600,6 +1600,16 @@ describe('Env integration', function() {
suiteFullNameToId[e.fullName] = e.id; suiteFullNameToId[e.fullName] = e.id;
}); });
// Clone args to work around Jasmine mutating the result after passing it
// to the reporter event.
// TODO: remove this once Jasmine no longer does that
const clone = structuredClone.bind(globalThis);
reporter.specStarted.calls.saveArgumentsByValue(clone);
reporter.specDone.calls.saveArgumentsByValue(clone);
reporter.specStarted.calls.saveArgumentsByValue(clone);
reporter.suiteDone.calls.saveArgumentsByValue(clone);
env.configure({ random: false });
env.addReporter(reporter); env.addReporter(reporter);
env.it('a top level spec', function() {}); env.it('a top level spec', function() {});
@@ -1636,110 +1646,179 @@ describe('Env integration', function() {
expect(reporter.specStarted.calls.count()).toBe(6); expect(reporter.specStarted.calls.count()).toBe(6);
expect(reporter.specDone.calls.count()).toBe(6); expect(reporter.specDone.calls.count()).toBe(6);
expect(reporter.specStarted).toHaveBeenCalledWith( const baseSpecEvent = {
jasmine.objectContaining({ passedExpectations: [],
description: 'a top level spec', failedExpectations: [],
parentSuiteId: null deprecationWarnings: [],
}) pendingReason: '',
); duration: null,
expect(reporter.specDone).toHaveBeenCalledWith( properties: null,
jasmine.objectContaining({ debugLogs: null,
description: 'a top level spec', id: jasmine.any(String),
status: 'passed', filename: jasmine.any(String)
parentSuiteId: null };
})
);
expect(reporter.specStarted).toHaveBeenCalledWith(
jasmine.objectContaining({
description: 'with a spec',
parentSuiteId: suiteFullNameToId['A Suite']
})
);
expect(reporter.specDone).toHaveBeenCalledWith(
jasmine.objectContaining({
description: 'with a spec',
status: 'passed',
parentSuiteId: suiteFullNameToId['A Suite']
})
);
expect(reporter.specStarted).toHaveBeenCalledWith( expect(reporter.specStarted.calls.argsFor(0)[0]).toEqual({
jasmine.objectContaining({ ...baseSpecEvent,
description: "with an x'ed spec", description: 'a top level spec',
parentSuiteId: suiteFullNameToId['A Suite with a nested suite'] fullName: 'a top level spec',
}) parentSuiteId: null
); });
expect(reporter.specDone).toHaveBeenCalledWith( expect(reporter.specDone.calls.argsFor(0)[0]).toEqual({
jasmine.objectContaining({ ...baseSpecEvent,
description: "with an x'ed spec", description: 'a top level spec',
status: 'pending', fullName: 'a top level spec',
parentSuiteId: suiteFullNameToId['A Suite with a nested suite'] status: 'passed',
}) parentSuiteId: null,
); duration: jasmine.any(Number)
});
expect(reporter.specStarted.calls.argsFor(1)[0]).toEqual({
...baseSpecEvent,
description: 'with a spec',
fullName: 'A Suite with a spec',
parentSuiteId: suiteFullNameToId['A Suite']
});
expect(reporter.specDone.calls.argsFor(1)[0]).toEqual({
...baseSpecEvent,
description: 'with a spec',
fullName: 'A Suite with a spec',
status: 'passed',
parentSuiteId: suiteFullNameToId['A Suite'],
passedExpectations: [
{ matcherName: 'toBe', message: 'Passed.', stack: '', passed: true }
],
duration: jasmine.any(Number)
});
expect(reporter.specStarted).toHaveBeenCalledWith( expect(reporter.specStarted.calls.argsFor(2)[0]).toEqual({
jasmine.objectContaining({ ...baseSpecEvent,
description: 'with a spec', description: "with an x'ed spec",
parentSuiteId: suiteFullNameToId['A Suite with a nested suite'] fullName: "A Suite with a nested suite with an x'ed spec",
}) parentSuiteId: suiteFullNameToId['A Suite with a nested suite'],
); pendingReason: 'Temporarily disabled with xit'
expect(reporter.specDone).toHaveBeenCalledWith( });
jasmine.objectContaining({ expect(reporter.specDone.calls.argsFor(2)[0]).toEqual({
description: 'with a spec', ...baseSpecEvent,
status: 'failed', description: "with an x'ed spec",
parentSuiteId: suiteFullNameToId['A Suite with a nested suite'] fullName: "A Suite with a nested suite with an x'ed spec",
}) status: 'pending',
); parentSuiteId: suiteFullNameToId['A Suite with a nested suite'],
pendingReason: 'Temporarily disabled with xit',
duration: jasmine.any(Number)
});
expect(reporter.specStarted).toHaveBeenCalledWith( expect(reporter.specStarted.calls.argsFor(3)[0]).toEqual({
jasmine.objectContaining({ ...baseSpecEvent,
description: 'is pending', description: 'with a spec',
parentSuiteId: fullName: 'A Suite with a nested suite with a spec',
suiteFullNameToId['A Suite with only non-executable specs'] parentSuiteId: suiteFullNameToId['A Suite with a nested suite']
}) });
); expect(reporter.specDone.calls.argsFor(3)[0]).toEqual({
expect(reporter.specDone).toHaveBeenCalledWith( ...baseSpecEvent,
jasmine.objectContaining({ description: 'with a spec',
description: 'is pending', fullName: 'A Suite with a nested suite with a spec',
status: 'pending', status: 'failed',
parentSuiteId: parentSuiteId: suiteFullNameToId['A Suite with a nested suite'],
suiteFullNameToId['A Suite with only non-executable specs'] failedExpectations: [
}) jasmine.objectContaining({
); matcherName: 'toBe',
message: 'Expected true to be false.'
})
],
duration: jasmine.any(Number)
});
expect(reporter.suiteStarted).toHaveBeenCalledWith( expect(reporter.specStarted.calls.argsFor(4)[0]).toEqual({
jasmine.objectContaining({ ...baseSpecEvent,
description: 'A Suite', description: 'is pending',
parentSuiteId: null fullName: 'A Suite with only non-executable specs is pending',
}) parentSuiteId: suiteFullNameToId['A Suite with only non-executable specs']
); });
expect(reporter.suiteDone).toHaveBeenCalledWith( expect(reporter.specDone.calls.argsFor(4)[0]).toEqual({
jasmine.objectContaining({ ...baseSpecEvent,
description: 'A Suite', description: 'is pending',
status: 'passed', status: 'pending',
parentSuiteId: null fullName: 'A Suite with only non-executable specs is pending',
}) parentSuiteId:
); suiteFullNameToId['A Suite with only non-executable specs'],
duration: jasmine.any(Number)
});
expect(reporter.suiteStarted).toHaveBeenCalledWith( expect(reporter.specStarted.calls.argsFor(5)[0]).toEqual({
jasmine.objectContaining({ ...baseSpecEvent,
description: 'with a nested suite', description: 'is xed',
parentSuiteId: suiteFullNameToId['A Suite'] fullName: 'A Suite with only non-executable specs is xed',
}) parentSuiteId:
); suiteFullNameToId['A Suite with only non-executable specs'],
expect(reporter.suiteDone).toHaveBeenCalledWith( pendingReason: 'Temporarily disabled with xit'
jasmine.objectContaining({ });
description: 'with a nested suite', expect(reporter.specDone.calls.argsFor(5)[0]).toEqual({
status: 'passed', ...baseSpecEvent,
parentSuiteId: suiteFullNameToId['A Suite'] description: 'is xed',
}) status: 'pending',
); fullName: 'A Suite with only non-executable specs is xed',
parentSuiteId:
suiteFullNameToId['A Suite with only non-executable specs'],
pendingReason: 'Temporarily disabled with xit',
duration: jasmine.any(Number)
});
const suiteDone = reporter.suiteDone.calls.argsFor(0)[0]; expect(reporter.suiteStarted.calls.count()).toBe(3);
expect(typeof suiteDone.duration).toBe('number'); expect(reporter.suiteDone.calls.count()).toBe(3);
const suiteResult = reporter.suiteStarted.calls.argsFor(0)[0]; const baseSuiteEvent = {
expect(suiteResult.description).toEqual('A Suite'); id: jasmine.any(String),
filename: jasmine.any(String),
failedExpectations: [],
deprecationWarnings: [],
duration: null,
properties: null
};
expect(reporter.suiteStarted.calls.argsFor(0)[0]).toEqual({
...baseSuiteEvent,
description: 'A Suite',
fullName: 'A Suite',
parentSuiteId: null
});
expect(reporter.suiteDone.calls.argsFor(2)[0]).toEqual({
...baseSuiteEvent,
description: 'A Suite',
fullName: 'A Suite',
status: 'passed',
parentSuiteId: null,
duration: jasmine.any(Number)
});
expect(reporter.suiteStarted.calls.argsFor(1)[0]).toEqual({
...baseSuiteEvent,
description: 'with a nested suite',
fullName: 'A Suite with a nested suite',
parentSuiteId: suiteFullNameToId['A Suite']
});
expect(reporter.suiteDone.calls.argsFor(0)[0]).toEqual({
...baseSuiteEvent,
description: 'with a nested suite',
status: 'passed',
fullName: 'A Suite with a nested suite',
parentSuiteId: suiteFullNameToId['A Suite'],
duration: jasmine.any(Number)
});
expect(reporter.suiteStarted.calls.argsFor(2)[0]).toEqual({
...baseSuiteEvent,
description: 'with only non-executable specs',
fullName: 'A Suite with only non-executable specs',
parentSuiteId: suiteFullNameToId['A Suite']
});
expect(reporter.suiteDone.calls.argsFor(1)[0]).toEqual({
...baseSuiteEvent,
description: 'with only non-executable specs',
status: 'passed',
fullName: 'A Suite with only non-executable specs',
parentSuiteId: suiteFullNameToId['A Suite'],
duration: jasmine.any(Number)
});
}); });
it('reports focused specs and suites as expected', async function() { it('reports focused specs and suites as expected', async function() {