Omit irrelevant properties from specStarted
This commit is contained in:
@@ -617,7 +617,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a message for use in debugging. If the spec fails, trace messages
|
* Logs a message for use in debugging. If the spec fails, trace messages
|
||||||
* will be included in the {@link SpecResult|result} passed to the
|
* will be included in the {@link SpecDoneEvent|result} passed to the
|
||||||
* reporter's specDone method.
|
* reporter's specDone method.
|
||||||
*
|
*
|
||||||
* This method should be called only when a spec (including any associated
|
* This method should be called only when a spec (including any associated
|
||||||
@@ -844,6 +844,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return this.result.properties[key];
|
return this.result.properties[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: throw if the key or value is not structred cloneable
|
||||||
setSpecProperty(key, value) {
|
setSpecProperty(key, value) {
|
||||||
this.result.properties = this.result.properties || {};
|
this.result.properties = this.result.properties || {};
|
||||||
this.result.properties[key] = value;
|
this.result.properties[key] = value;
|
||||||
@@ -867,8 +868,45 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
|
this.result = {
|
||||||
|
id: this.id,
|
||||||
|
description: this.description,
|
||||||
|
fullName: this.getFullName(),
|
||||||
|
parentSuiteId: this.parentSuiteId,
|
||||||
|
filename: this.filename,
|
||||||
|
failedExpectations: [],
|
||||||
|
passedExpectations: [],
|
||||||
|
deprecationWarnings: [],
|
||||||
|
pendingReason: this.excludeMessage || '',
|
||||||
|
duration: null,
|
||||||
|
properties: null,
|
||||||
|
debugLogs: null
|
||||||
|
};
|
||||||
|
this.markedPending = this.markedExcluding;
|
||||||
|
this.reportedDone = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
startedEvent() {
|
||||||
/**
|
/**
|
||||||
* @typedef SpecResult
|
* @typedef SpecStartedEvent
|
||||||
|
* @property {String} id - The unique id of this spec.
|
||||||
|
* @property {String} description - The description passed to the {@link it} that created this spec.
|
||||||
|
* @property {String} fullName - The full description including all ancestors of this spec.
|
||||||
|
* @property {String|null} parentSuiteId - The ID of the suite containing this spec, or null if this spec is not in a describe().
|
||||||
|
* @property {String} filename - Deprecated. The name of the file the spec was defined in.
|
||||||
|
* Note: The value may be incorrect if zone.js is installed or
|
||||||
|
* `it`/`fit`/`xit` have been replaced with versions that don't maintain the
|
||||||
|
* same call stack height as the originals. This property may be removed in
|
||||||
|
* a future version unless there is enough user interest in keeping it.
|
||||||
|
* See {@link https://github.com/jasmine/jasmine/issues/2065}.
|
||||||
|
* @since 6.0.0
|
||||||
|
*/
|
||||||
|
return this.#commonEventFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
doneEvent() {
|
||||||
|
/**
|
||||||
|
* @typedef SpecDoneEvent
|
||||||
* @property {String} id - The unique id of this spec.
|
* @property {String} id - The unique id of this spec.
|
||||||
* @property {String} description - The description passed to the {@link it} that created this spec.
|
* @property {String} description - The description passed to the {@link it} that created this spec.
|
||||||
* @property {String} fullName - The full description including all ancestors of this spec.
|
* @property {String} fullName - The full description including all ancestors of this spec.
|
||||||
@@ -887,24 +925,37 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
||||||
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
||||||
* @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
|
* @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
|
||||||
* @since 2.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
this.result = {
|
const event = {
|
||||||
|
...this.#commonEventFields()
|
||||||
|
};
|
||||||
|
const toCopy = [
|
||||||
|
'failedExpectations',
|
||||||
|
'passedExpectations',
|
||||||
|
'deprecationWarnings',
|
||||||
|
'pendingReason',
|
||||||
|
'status',
|
||||||
|
'duration',
|
||||||
|
'properties',
|
||||||
|
'debugLogs'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const k of toCopy) {
|
||||||
|
event[k] = this.result[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
#commonEventFields() {
|
||||||
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
fullName: this.getFullName(),
|
fullName: this.getFullName(),
|
||||||
parentSuiteId: this.parentSuiteId,
|
parentSuiteId: this.parentSuiteId,
|
||||||
filename: this.filename,
|
filename: this.filename
|
||||||
failedExpectations: [],
|
|
||||||
passedExpectations: [],
|
|
||||||
deprecationWarnings: [],
|
|
||||||
pendingReason: this.excludeMessage || '',
|
|
||||||
duration: null,
|
|
||||||
properties: null,
|
|
||||||
debugLogs: null
|
|
||||||
};
|
};
|
||||||
this.markedPending = this.markedExcluding;
|
|
||||||
this.reportedDone = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleException(e) {
|
handleException(e) {
|
||||||
@@ -1747,7 +1798,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a user-defined property as part of the properties field of {@link SpecResult}
|
* Get a user-defined property as part of the properties field of {@link SpecDoneEvent}
|
||||||
* @name Env#getSpecProperty
|
* @name Env#getSpecProperty
|
||||||
* @since 5.10.0
|
* @since 5.10.0
|
||||||
* @function
|
* @function
|
||||||
@@ -2039,7 +2090,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
* @function
|
* @function
|
||||||
* @param {Number} index - The position in the specs list to start from.
|
* @param {Number} index - The position in the specs list to start from.
|
||||||
* @param {Number} length - Maximum number of specs results to return.
|
* @param {Number} length - Maximum number of specs results to return.
|
||||||
* @return {SpecResult[]}
|
* @return {SpecDoneEvent[]}
|
||||||
*/
|
*/
|
||||||
this.specResults = function(index, length) {
|
this.specResults = function(index, length) {
|
||||||
return specs.slice(index, index + length);
|
return specs.slice(index, index + length);
|
||||||
@@ -2050,7 +2101,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
* @name jsApiReporter#specs
|
* @name jsApiReporter#specs
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @function
|
* @function
|
||||||
* @return {SpecResult[]}
|
* @return {SpecDoneEvent[]}
|
||||||
*/
|
*/
|
||||||
this.specs = function() {
|
this.specs = function() {
|
||||||
return specs;
|
return specs;
|
||||||
@@ -8715,7 +8766,7 @@ getJasmineRequireObj().reporterEvents = function() {
|
|||||||
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
|
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
|
||||||
* @function
|
* @function
|
||||||
* @name Reporter#specStarted
|
* @name Reporter#specStarted
|
||||||
* @param {SpecResult} result Information about the individual {@link it} being run
|
* @param {SpecStartedEvent} result Information about the individual {@link it} being run
|
||||||
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
||||||
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
||||||
* @see async
|
* @see async
|
||||||
@@ -8727,7 +8778,7 @@ getJasmineRequireObj().reporterEvents = function() {
|
|||||||
* While jasmine doesn't require any specific functions, not defining a `specDone` will make it impossible for a reporter to know when a spec has failed.
|
* While jasmine doesn't require any specific functions, not defining a `specDone` will make it impossible for a reporter to know when a spec has failed.
|
||||||
* @function
|
* @function
|
||||||
* @name Reporter#specDone
|
* @name Reporter#specDone
|
||||||
* @param {SpecResult} result
|
* @param {SpecDoneEvent} result
|
||||||
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
||||||
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
||||||
* @see async
|
* @see async
|
||||||
@@ -11514,7 +11565,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
|
|||||||
const onStart = next => {
|
const onStart = next => {
|
||||||
this.#currentRunableTracker.setCurrentSpec(spec);
|
this.#currentRunableTracker.setCurrentSpec(spec);
|
||||||
this.#runableResources.initForRunable(spec.id, spec.parentSuiteId);
|
this.#runableResources.initForRunable(spec.id, spec.parentSuiteId);
|
||||||
this.#reportDispatcher.specStarted(spec.result).then(next);
|
this.#reportDispatcher.specStarted(spec.startedEvent()).then(next);
|
||||||
};
|
};
|
||||||
const resultCallback = (result, next) => {
|
const resultCallback = (result, next) => {
|
||||||
this.#specComplete(spec).then(next);
|
this.#specComplete(spec).then(next);
|
||||||
@@ -11721,7 +11772,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
|
|||||||
|
|
||||||
async #reportSpecDone(spec) {
|
async #reportSpecDone(spec) {
|
||||||
spec.reportedDone = true;
|
spec.reportedDone = true;
|
||||||
await this.#reportDispatcher.specDone(spec.result);
|
await this.#reportDispatcher.specDone(spec.doneEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
async #reportChildrenOfBeforeAllFailure(suite) {
|
async #reportChildrenOfBeforeAllFailure(suite) {
|
||||||
@@ -11737,7 +11788,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
|
|||||||
await this.#reportDispatcher.suiteDone(child.result);
|
await this.#reportDispatcher.suiteDone(child.result);
|
||||||
} else {
|
} else {
|
||||||
/* a spec */
|
/* a spec */
|
||||||
await this.#reportDispatcher.specStarted(child.result);
|
await this.#reportDispatcher.specStarted(child.startedEvent());
|
||||||
|
|
||||||
child.addExpectationResult(
|
child.addExpectationResult(
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ describe('TreeRunner', function() {
|
|||||||
spec.id,
|
spec.id,
|
||||||
spec.parentSuiteId
|
spec.parentSuiteId
|
||||||
);
|
);
|
||||||
expect(reportDispatcher.specStarted).toHaveBeenCalledWith(spec.result);
|
expect(reportDispatcher.specStarted).toHaveBeenCalledWith(
|
||||||
|
spec.startedEvent()
|
||||||
|
);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
expect(reportDispatcher.specStarted).toHaveBeenCalledBefore(next);
|
expect(reportDispatcher.specStarted).toHaveBeenCalledBefore(next);
|
||||||
await expectAsync(executePromise).toBePending();
|
await expectAsync(executePromise).toBePending();
|
||||||
@@ -61,7 +63,7 @@ describe('TreeRunner', function() {
|
|||||||
|
|
||||||
expect(currentRunableTracker.currentSpec()).toBeFalsy();
|
expect(currentRunableTracker.currentSpec()).toBeFalsy();
|
||||||
expect(runableResources.clearForRunable).toHaveBeenCalledWith(spec.id);
|
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.result.duration).toEqual('the elapsed time');
|
||||||
expect(spec.reportedDone).toEqual(true);
|
expect(spec.reportedDone).toEqual(true);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
|||||||
@@ -1636,15 +1636,18 @@ describe('Env integration', function() {
|
|||||||
expect(reporter.specDone.calls.count()).toBe(6);
|
expect(reporter.specDone.calls.count()).toBe(6);
|
||||||
|
|
||||||
const baseSpecEvent = {
|
const baseSpecEvent = {
|
||||||
|
id: jasmine.any(String),
|
||||||
|
filename: jasmine.any(String)
|
||||||
|
};
|
||||||
|
const baseSpecDoneEvent = {
|
||||||
|
...baseSpecEvent,
|
||||||
passedExpectations: [],
|
passedExpectations: [],
|
||||||
failedExpectations: [],
|
failedExpectations: [],
|
||||||
deprecationWarnings: [],
|
deprecationWarnings: [],
|
||||||
pendingReason: '',
|
pendingReason: '',
|
||||||
duration: null,
|
duration: null,
|
||||||
properties: null,
|
properties: null,
|
||||||
debugLogs: null,
|
debugLogs: null
|
||||||
id: jasmine.any(String),
|
|
||||||
filename: jasmine.any(String)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(reporter.specStarted.calls.argsFor(0)[0]).toEqual({
|
expect(reporter.specStarted.calls.argsFor(0)[0]).toEqual({
|
||||||
@@ -1654,7 +1657,7 @@ describe('Env integration', function() {
|
|||||||
parentSuiteId: null
|
parentSuiteId: null
|
||||||
});
|
});
|
||||||
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual({
|
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual({
|
||||||
...baseSpecEvent,
|
...baseSpecDoneEvent,
|
||||||
description: 'a top level spec',
|
description: 'a top level spec',
|
||||||
fullName: 'a top level spec',
|
fullName: 'a top level spec',
|
||||||
status: 'passed',
|
status: 'passed',
|
||||||
@@ -1668,7 +1671,7 @@ describe('Env integration', function() {
|
|||||||
parentSuiteId: suiteFullNameToId['A Suite']
|
parentSuiteId: suiteFullNameToId['A Suite']
|
||||||
});
|
});
|
||||||
expect(reporter.specDone.calls.argsFor(1)[0]).toEqual({
|
expect(reporter.specDone.calls.argsFor(1)[0]).toEqual({
|
||||||
...baseSpecEvent,
|
...baseSpecDoneEvent,
|
||||||
description: 'with a spec',
|
description: 'with a spec',
|
||||||
fullName: 'A Suite with a spec',
|
fullName: 'A Suite with a spec',
|
||||||
status: 'passed',
|
status: 'passed',
|
||||||
@@ -1689,11 +1692,10 @@ describe('Env integration', function() {
|
|||||||
...baseSpecEvent,
|
...baseSpecEvent,
|
||||||
description: "with an x'ed spec",
|
description: "with an x'ed spec",
|
||||||
fullName: "A Suite with a nested suite 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'],
|
parentSuiteId: suiteFullNameToId['A Suite with a nested suite']
|
||||||
pendingReason: 'Temporarily disabled with xit'
|
|
||||||
});
|
});
|
||||||
expect(reporter.specDone.calls.argsFor(2)[0]).toEqual({
|
expect(reporter.specDone.calls.argsFor(2)[0]).toEqual({
|
||||||
...baseSpecEvent,
|
...baseSpecDoneEvent,
|
||||||
description: "with an x'ed spec",
|
description: "with an x'ed spec",
|
||||||
fullName: "A Suite with a nested suite with an x'ed spec",
|
fullName: "A Suite with a nested suite with an x'ed spec",
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
@@ -1709,7 +1711,7 @@ describe('Env integration', function() {
|
|||||||
parentSuiteId: suiteFullNameToId['A Suite with a nested suite']
|
parentSuiteId: suiteFullNameToId['A Suite with a nested suite']
|
||||||
});
|
});
|
||||||
expect(reporter.specDone.calls.argsFor(3)[0]).toEqual({
|
expect(reporter.specDone.calls.argsFor(3)[0]).toEqual({
|
||||||
...baseSpecEvent,
|
...baseSpecDoneEvent,
|
||||||
description: 'with a spec',
|
description: 'with a spec',
|
||||||
fullName: 'A Suite with a nested suite with a spec',
|
fullName: 'A Suite with a nested suite with a spec',
|
||||||
status: 'failed',
|
status: 'failed',
|
||||||
@@ -1730,7 +1732,7 @@ describe('Env integration', function() {
|
|||||||
parentSuiteId: suiteFullNameToId['A Suite with only non-executable specs']
|
parentSuiteId: suiteFullNameToId['A Suite with only non-executable specs']
|
||||||
});
|
});
|
||||||
expect(reporter.specDone.calls.argsFor(4)[0]).toEqual({
|
expect(reporter.specDone.calls.argsFor(4)[0]).toEqual({
|
||||||
...baseSpecEvent,
|
...baseSpecDoneEvent,
|
||||||
description: 'is pending',
|
description: 'is pending',
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
fullName: 'A Suite with only non-executable specs is pending',
|
fullName: 'A Suite with only non-executable specs is pending',
|
||||||
@@ -1743,12 +1745,10 @@ describe('Env integration', function() {
|
|||||||
...baseSpecEvent,
|
...baseSpecEvent,
|
||||||
description: 'is xed',
|
description: 'is xed',
|
||||||
fullName: 'A Suite with only non-executable specs is xed',
|
fullName: 'A Suite with only non-executable specs is xed',
|
||||||
parentSuiteId:
|
parentSuiteId: suiteFullNameToId['A Suite with only non-executable specs']
|
||||||
suiteFullNameToId['A Suite with only non-executable specs'],
|
|
||||||
pendingReason: 'Temporarily disabled with xit'
|
|
||||||
});
|
});
|
||||||
expect(reporter.specDone.calls.argsFor(5)[0]).toEqual({
|
expect(reporter.specDone.calls.argsFor(5)[0]).toEqual({
|
||||||
...baseSpecEvent,
|
...baseSpecDoneEvent,
|
||||||
description: 'is xed',
|
description: 'is xed',
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
fullName: 'A Suite with only non-executable specs is xed',
|
fullName: 'A Suite with only non-executable specs is xed',
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a user-defined property as part of the properties field of {@link SpecResult}
|
* Get a user-defined property as part of the properties field of {@link SpecDoneEvent}
|
||||||
* @name Env#getSpecProperty
|
* @name Env#getSpecProperty
|
||||||
* @since 5.10.0
|
* @since 5.10.0
|
||||||
* @function
|
* @function
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
* @function
|
* @function
|
||||||
* @param {Number} index - The position in the specs list to start from.
|
* @param {Number} index - The position in the specs list to start from.
|
||||||
* @param {Number} length - Maximum number of specs results to return.
|
* @param {Number} length - Maximum number of specs results to return.
|
||||||
* @return {SpecResult[]}
|
* @return {SpecDoneEvent[]}
|
||||||
*/
|
*/
|
||||||
this.specResults = function(index, length) {
|
this.specResults = function(index, length) {
|
||||||
return specs.slice(index, index + length);
|
return specs.slice(index, index + length);
|
||||||
@@ -107,7 +107,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
|
|||||||
* @name jsApiReporter#specs
|
* @name jsApiReporter#specs
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @function
|
* @function
|
||||||
* @return {SpecResult[]}
|
* @return {SpecDoneEvent[]}
|
||||||
*/
|
*/
|
||||||
this.specs = function() {
|
this.specs = function() {
|
||||||
return specs;
|
return specs;
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return this.result.properties[key];
|
return this.result.properties[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: throw if the key or value is not structred cloneable
|
||||||
setSpecProperty(key, value) {
|
setSpecProperty(key, value) {
|
||||||
this.result.properties = this.result.properties || {};
|
this.result.properties = this.result.properties || {};
|
||||||
this.result.properties[key] = value;
|
this.result.properties[key] = value;
|
||||||
@@ -93,8 +94,45 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
|
this.result = {
|
||||||
|
id: this.id,
|
||||||
|
description: this.description,
|
||||||
|
fullName: this.getFullName(),
|
||||||
|
parentSuiteId: this.parentSuiteId,
|
||||||
|
filename: this.filename,
|
||||||
|
failedExpectations: [],
|
||||||
|
passedExpectations: [],
|
||||||
|
deprecationWarnings: [],
|
||||||
|
pendingReason: this.excludeMessage || '',
|
||||||
|
duration: null,
|
||||||
|
properties: null,
|
||||||
|
debugLogs: null
|
||||||
|
};
|
||||||
|
this.markedPending = this.markedExcluding;
|
||||||
|
this.reportedDone = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
startedEvent() {
|
||||||
/**
|
/**
|
||||||
* @typedef SpecResult
|
* @typedef SpecStartedEvent
|
||||||
|
* @property {String} id - The unique id of this spec.
|
||||||
|
* @property {String} description - The description passed to the {@link it} that created this spec.
|
||||||
|
* @property {String} fullName - The full description including all ancestors of this spec.
|
||||||
|
* @property {String|null} parentSuiteId - The ID of the suite containing this spec, or null if this spec is not in a describe().
|
||||||
|
* @property {String} filename - Deprecated. The name of the file the spec was defined in.
|
||||||
|
* Note: The value may be incorrect if zone.js is installed or
|
||||||
|
* `it`/`fit`/`xit` have been replaced with versions that don't maintain the
|
||||||
|
* same call stack height as the originals. This property may be removed in
|
||||||
|
* a future version unless there is enough user interest in keeping it.
|
||||||
|
* See {@link https://github.com/jasmine/jasmine/issues/2065}.
|
||||||
|
* @since 6.0.0
|
||||||
|
*/
|
||||||
|
return this.#commonEventFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
doneEvent() {
|
||||||
|
/**
|
||||||
|
* @typedef SpecDoneEvent
|
||||||
* @property {String} id - The unique id of this spec.
|
* @property {String} id - The unique id of this spec.
|
||||||
* @property {String} description - The description passed to the {@link it} that created this spec.
|
* @property {String} description - The description passed to the {@link it} that created this spec.
|
||||||
* @property {String} fullName - The full description including all ancestors of this spec.
|
* @property {String} fullName - The full description including all ancestors of this spec.
|
||||||
@@ -113,24 +151,37 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
||||||
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
||||||
* @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
|
* @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
|
||||||
* @since 2.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
this.result = {
|
const event = {
|
||||||
|
...this.#commonEventFields()
|
||||||
|
};
|
||||||
|
const toCopy = [
|
||||||
|
'failedExpectations',
|
||||||
|
'passedExpectations',
|
||||||
|
'deprecationWarnings',
|
||||||
|
'pendingReason',
|
||||||
|
'status',
|
||||||
|
'duration',
|
||||||
|
'properties',
|
||||||
|
'debugLogs'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const k of toCopy) {
|
||||||
|
event[k] = this.result[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
#commonEventFields() {
|
||||||
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
fullName: this.getFullName(),
|
fullName: this.getFullName(),
|
||||||
parentSuiteId: this.parentSuiteId,
|
parentSuiteId: this.parentSuiteId,
|
||||||
filename: this.filename,
|
filename: this.filename
|
||||||
failedExpectations: [],
|
|
||||||
passedExpectations: [],
|
|
||||||
deprecationWarnings: [],
|
|
||||||
pendingReason: this.excludeMessage || '',
|
|
||||||
duration: null,
|
|
||||||
properties: null,
|
|
||||||
debugLogs: null
|
|
||||||
};
|
};
|
||||||
this.markedPending = this.markedExcluding;
|
|
||||||
this.reportedDone = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleException(e) {
|
handleException(e) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
|
|||||||
const onStart = next => {
|
const onStart = next => {
|
||||||
this.#currentRunableTracker.setCurrentSpec(spec);
|
this.#currentRunableTracker.setCurrentSpec(spec);
|
||||||
this.#runableResources.initForRunable(spec.id, spec.parentSuiteId);
|
this.#runableResources.initForRunable(spec.id, spec.parentSuiteId);
|
||||||
this.#reportDispatcher.specStarted(spec.result).then(next);
|
this.#reportDispatcher.specStarted(spec.startedEvent()).then(next);
|
||||||
};
|
};
|
||||||
const resultCallback = (result, next) => {
|
const resultCallback = (result, next) => {
|
||||||
this.#specComplete(spec).then(next);
|
this.#specComplete(spec).then(next);
|
||||||
@@ -255,7 +255,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
|
|||||||
|
|
||||||
async #reportSpecDone(spec) {
|
async #reportSpecDone(spec) {
|
||||||
spec.reportedDone = true;
|
spec.reportedDone = true;
|
||||||
await this.#reportDispatcher.specDone(spec.result);
|
await this.#reportDispatcher.specDone(spec.doneEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
async #reportChildrenOfBeforeAllFailure(suite) {
|
async #reportChildrenOfBeforeAllFailure(suite) {
|
||||||
@@ -271,7 +271,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
|
|||||||
await this.#reportDispatcher.suiteDone(child.result);
|
await this.#reportDispatcher.suiteDone(child.result);
|
||||||
} else {
|
} else {
|
||||||
/* a spec */
|
/* a spec */
|
||||||
await this.#reportDispatcher.specStarted(child.result);
|
await this.#reportDispatcher.specStarted(child.startedEvent());
|
||||||
|
|
||||||
child.addExpectationResult(
|
child.addExpectationResult(
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -421,7 +421,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a message for use in debugging. If the spec fails, trace messages
|
* Logs a message for use in debugging. If the spec fails, trace messages
|
||||||
* will be included in the {@link SpecResult|result} passed to the
|
* will be included in the {@link SpecDoneEvent|result} passed to the
|
||||||
* reporter's specDone method.
|
* reporter's specDone method.
|
||||||
*
|
*
|
||||||
* This method should be called only when a spec (including any associated
|
* This method should be called only when a spec (including any associated
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ getJasmineRequireObj().reporterEvents = function() {
|
|||||||
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
|
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
|
||||||
* @function
|
* @function
|
||||||
* @name Reporter#specStarted
|
* @name Reporter#specStarted
|
||||||
* @param {SpecResult} result Information about the individual {@link it} being run
|
* @param {SpecStartedEvent} result Information about the individual {@link it} being run
|
||||||
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
||||||
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
||||||
* @see async
|
* @see async
|
||||||
@@ -84,7 +84,7 @@ getJasmineRequireObj().reporterEvents = function() {
|
|||||||
* While jasmine doesn't require any specific functions, not defining a `specDone` will make it impossible for a reporter to know when a spec has failed.
|
* While jasmine doesn't require any specific functions, not defining a `specDone` will make it impossible for a reporter to know when a spec has failed.
|
||||||
* @function
|
* @function
|
||||||
* @name Reporter#specDone
|
* @name Reporter#specDone
|
||||||
* @param {SpecResult} result
|
* @param {SpecDoneEvent} result
|
||||||
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
|
||||||
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
|
||||||
* @see async
|
* @see async
|
||||||
|
|||||||
Reference in New Issue
Block a user