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

@@ -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
* @since 5.10.0
* @function

View File

@@ -96,7 +96,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
* @function
* @param {Number} index - The position in the specs list to start from.
* @param {Number} length - Maximum number of specs results to return.
* @return {SpecResult[]}
* @return {SpecDoneEvent[]}
*/
this.specResults = function(index, length) {
return specs.slice(index, index + length);
@@ -107,7 +107,7 @@ getJasmineRequireObj().JsApiReporter = function(j$) {
* @name jsApiReporter#specs
* @since 2.0.0
* @function
* @return {SpecResult[]}
* @return {SpecDoneEvent[]}
*/
this.specs = function() {
return specs;

View File

@@ -70,6 +70,7 @@ getJasmineRequireObj().Spec = function(j$) {
return this.result.properties[key];
}
// TODO: throw if the key or value is not structred cloneable
setSpecProperty(key, value) {
this.result.properties = this.result.properties || {};
this.result.properties[key] = value;
@@ -93,8 +94,45 @@ getJasmineRequireObj().Spec = function(j$) {
}
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} description - The description passed to the {@link it} that created 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 {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.
* @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,
description: this.description,
fullName: this.getFullName(),
parentSuiteId: this.parentSuiteId,
filename: this.filename,
failedExpectations: [],
passedExpectations: [],
deprecationWarnings: [],
pendingReason: this.excludeMessage || '',
duration: null,
properties: null,
debugLogs: null
filename: this.filename
};
this.markedPending = this.markedExcluding;
this.reportedDone = false;
}
handleException(e) {

View File

@@ -48,7 +48,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
const onStart = next => {
this.#currentRunableTracker.setCurrentSpec(spec);
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) => {
this.#specComplete(spec).then(next);
@@ -255,7 +255,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
async #reportSpecDone(spec) {
spec.reportedDone = true;
await this.#reportDispatcher.specDone(spec.result);
await this.#reportDispatcher.specDone(spec.doneEvent());
}
async #reportChildrenOfBeforeAllFailure(suite) {
@@ -271,7 +271,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
await this.#reportDispatcher.suiteDone(child.result);
} else {
/* a spec */
await this.#reportDispatcher.specStarted(child.result);
await this.#reportDispatcher.specStarted(child.startedEvent());
child.addExpectationResult(
false,

View File

@@ -421,7 +421,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
/**
* 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.
*
* This method should be called only when a spec (including any associated

View File

@@ -72,7 +72,7 @@ getJasmineRequireObj().reporterEvents = function() {
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
* @function
* @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.
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
* @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.
* @function
* @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.
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
* @see async