Omit irrelevant properties from specStarted

This commit is contained in:
Steve Gravrock
2025-09-21 13:58:02 -07:00
parent 4020da25a4
commit 970cbdc69c
10 changed files with 406 additions and 60 deletions

View File

@@ -412,4 +412,246 @@ describe('Spec', function() {
});
});
});
describe('#startedEvent', function() {
it('includes only properties that are known before execution', function() {
const spec = new jasmineUnderTest.Spec({
id: 'spec1',
parentSuiteId: 'suite1',
description: 'a spec',
filename: 'somefile.js',
getPath() {
return ['a suite', 'a spec'];
},
queueableFn: { fn: () => {} }
});
expect(spec.startedEvent()).toEqual({
id: 'spec1',
parentSuiteId: 'suite1',
description: 'a spec',
fullName: 'a suite a spec',
filename: 'somefile.js'
});
});
});
describe('#doneEvent', function() {
it('returns the event for a passed spec', function() {
const timer = {
start() {},
elapsed() {
return 123;
}
};
const spec = new jasmineUnderTest.Spec({
id: 'spec1',
parentSuiteId: 'suite1',
description: 'a spec',
filename: 'somefile.js',
getPath() {
return ['a suite', 'a spec'];
},
queueableFn: { fn: () => {} },
timer: timer
});
spec.addExpectationResult(true, {
matcherName: 'a passing expectation',
passed: true
});
spec.executionFinished(false, false);
expect(spec.doneEvent()).toEqual({
id: 'spec1',
parentSuiteId: 'suite1',
description: 'a spec',
fullName: 'a suite a spec',
filename: 'somefile.js',
status: 'passed',
passedExpectations: [
{
matcherName: 'a passing expectation',
passed: true,
message: 'Passed.',
stack: '',
globalErrorType: undefined
}
],
failedExpectations: [],
deprecationWarnings: [],
debugLogs: null, // TODO change to []
properties: null, // TODO change to {}
pendingReason: '',
duration: 123
});
});
it('returns the event for a failed spec', function() {
const timer = {
start() {},
elapsed() {
return 123;
}
};
const spec = new jasmineUnderTest.Spec({
id: 'spec1',
parentSuiteId: 'suite1',
description: 'a spec',
filename: 'somefile.js',
getPath() {
return ['a suite', 'a spec'];
},
queueableFn: { fn: () => {} },
timer: timer
});
spec.addExpectationResult(true, {
matcherName: 'a passing expectation',
passed: true
});
spec.addExpectationResult(false, {
matcherName: 'a failing expectation',
passed: false,
error: new Error('failed')
});
spec.executionFinished(false, false);
expect(spec.doneEvent()).toEqual({
id: 'spec1',
parentSuiteId: 'suite1',
description: 'a spec',
fullName: 'a suite a spec',
filename: 'somefile.js',
status: 'failed',
passedExpectations: [
{
matcherName: 'a passing expectation',
passed: true,
message: 'Passed.',
stack: '',
globalErrorType: undefined
}
],
failedExpectations: [
{
matcherName: 'a failing expectation',
passed: false,
message: jasmine.stringMatching(/^Error: failed/),
stack: jasmine.stringContaining('SpecSpec.js'),
globalErrorType: undefined
}
],
deprecationWarnings: [],
debugLogs: null, // TODO change to []
properties: null, // TODO change to {}
pendingReason: '',
duration: 123
});
});
it("reports a status of 'pending' for a declaratively pended spec", function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: {}
});
spec.executionFinished(false, false);
const result = spec.doneEvent();
expect(result.status).toEqual('pending');
expect(result.pendingReason).toEqual('');
});
it("reports a status of 'pending' for a spec pended by #pend", function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
spec.pend('nope');
spec.executionFinished(false, false);
const result = spec.doneEvent();
expect(result.status).toEqual('pending');
expect(result.pendingReason).toEqual('nope');
});
it("reports a status of 'excluded' for an excluded spec", function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
spec.executionFinished(true, false);
expect(spec.doneEvent().status).toEqual('excluded');
});
describe('When failSpecWithNoExpectations is true', function() {
it("reports a status of 'failed' for a spec with no expectations", function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
spec.executionFinished(false, true);
expect(spec.doneEvent().status).toEqual('failed');
});
});
it('includes deprecation warnings', function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
spec.addDeprecationWarning('stop that');
expect(spec.doneEvent().deprecationWarnings).toEqual([
{
// TODO: remove irrelevant properties
message: 'stop that',
stack: jasmine.stringContaining('SpecSpec.js'),
matcherName: undefined,
passed: undefined,
globalErrorType: undefined
}
]);
});
it('includes debug logs', function() {
const timer = {
start() {},
elapsed() {
return 123;
}
};
const spec = new jasmineUnderTest.Spec({
timer,
queueableFn: { fn: () => {} }
});
spec.debugLog('maybe this will help');
expect(spec.doneEvent().debugLogs).toEqual([
{
message: 'maybe this will help',
timestamp: 123
}
]);
});
it('includes spec properties', function() {
const spec = new jasmineUnderTest.Spec({
queueableFn: { fn: () => {} }
});
spec.setSpecProperty('foo', 'bar');
spec.setSpecProperty('baz', { grault: ['wombat'] });
expect(spec.doneEvent().properties).toEqual({
foo: 'bar',
baz: { grault: ['wombat'] }
});
});
// it("excludes properties that aren't in the public API");
});
});

View File

@@ -28,7 +28,9 @@ describe('TreeRunner', function() {
spec.id,
spec.parentSuiteId
);
expect(reportDispatcher.specStarted).toHaveBeenCalledWith(spec.result);
expect(reportDispatcher.specStarted).toHaveBeenCalledWith(
spec.startedEvent()
);
await Promise.resolve();
expect(reportDispatcher.specStarted).toHaveBeenCalledBefore(next);
await expectAsync(executePromise).toBePending();
@@ -61,7 +63,7 @@ describe('TreeRunner', function() {
expect(currentRunableTracker.currentSpec()).toBeFalsy();
expect(runableResources.clearForRunable).toHaveBeenCalledWith(spec.id);
expect(reportDispatcher.specDone).toHaveBeenCalledWith(spec.result);
expect(reportDispatcher.specDone).toHaveBeenCalledWith(spec.doneEvent());
expect(spec.result.duration).toEqual('the elapsed time');
expect(spec.reportedDone).toEqual(true);
await Promise.resolve();

View File

@@ -1636,15 +1636,18 @@ describe('Env integration', function() {
expect(reporter.specDone.calls.count()).toBe(6);
const baseSpecEvent = {
id: jasmine.any(String),
filename: jasmine.any(String)
};
const baseSpecDoneEvent = {
...baseSpecEvent,
passedExpectations: [],
failedExpectations: [],
deprecationWarnings: [],
pendingReason: '',
duration: null,
properties: null,
debugLogs: null,
id: jasmine.any(String),
filename: jasmine.any(String)
debugLogs: null
};
expect(reporter.specStarted.calls.argsFor(0)[0]).toEqual({
@@ -1654,7 +1657,7 @@ describe('Env integration', function() {
parentSuiteId: null
});
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual({
...baseSpecEvent,
...baseSpecDoneEvent,
description: 'a top level spec',
fullName: 'a top level spec',
status: 'passed',
@@ -1668,7 +1671,7 @@ describe('Env integration', function() {
parentSuiteId: suiteFullNameToId['A Suite']
});
expect(reporter.specDone.calls.argsFor(1)[0]).toEqual({
...baseSpecEvent,
...baseSpecDoneEvent,
description: 'with a spec',
fullName: 'A Suite with a spec',
status: 'passed',
@@ -1689,11 +1692,10 @@ describe('Env integration', function() {
...baseSpecEvent,
description: "with an x'ed spec",
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'
parentSuiteId: suiteFullNameToId['A Suite with a nested suite']
});
expect(reporter.specDone.calls.argsFor(2)[0]).toEqual({
...baseSpecEvent,
...baseSpecDoneEvent,
description: "with an x'ed spec",
fullName: "A Suite with a nested suite with an x'ed spec",
status: 'pending',
@@ -1709,7 +1711,7 @@ describe('Env integration', function() {
parentSuiteId: suiteFullNameToId['A Suite with a nested suite']
});
expect(reporter.specDone.calls.argsFor(3)[0]).toEqual({
...baseSpecEvent,
...baseSpecDoneEvent,
description: 'with a spec',
fullName: 'A Suite with a nested suite with a spec',
status: 'failed',
@@ -1730,7 +1732,7 @@ describe('Env integration', function() {
parentSuiteId: suiteFullNameToId['A Suite with only non-executable specs']
});
expect(reporter.specDone.calls.argsFor(4)[0]).toEqual({
...baseSpecEvent,
...baseSpecDoneEvent,
description: 'is pending',
status: 'pending',
fullName: 'A Suite with only non-executable specs is pending',
@@ -1743,12 +1745,10 @@ describe('Env integration', function() {
...baseSpecEvent,
description: 'is xed',
fullName: 'A Suite with only non-executable specs is xed',
parentSuiteId:
suiteFullNameToId['A Suite with only non-executable specs'],
pendingReason: 'Temporarily disabled with xit'
parentSuiteId: suiteFullNameToId['A Suite with only non-executable specs']
});
expect(reporter.specDone.calls.argsFor(5)[0]).toEqual({
...baseSpecEvent,
...baseSpecDoneEvent,
description: 'is xed',
status: 'pending',
fullName: 'A Suite with only non-executable specs is xed',