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

@@ -123,7 +123,7 @@ getJasmineRequireObj().Runner = function(j$) {
this.#currentRunableTracker.popSuite();
let overallStatus, incompleteReason, incompleteCode;
if (hasFailures || this.#topSuite.result.failedExpectations.length > 0) {
if (hasFailures || this.#topSuite.hasOwnFailedExpectations()) {
overallStatus = 'failed';
} else if (this.#getFocusedRunables().length > 0) {
overallStatus = 'incomplete';

View File

@@ -139,7 +139,7 @@ getJasmineRequireObj().Spec = function(j$) {
* 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
* @since 2.0.0
*/
return this.#commonEventFields();
}
@@ -165,7 +165,7 @@ 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 6.0.0
* @since 2.0.0
*/
const event = {
...this.#commonEventFields(),

View File

@@ -100,8 +100,45 @@ getJasmineRequireObj().Suite = function(j$) {
}
reset() {
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
parentSuiteId: this.#reportedParentSuiteId,
filename: this.filename,
failedExpectations: [],
deprecationWarnings: [],
duration: null,
properties: null
};
this.markedPending = this.markedExcluding;
this.children.forEach(function(child) {
child.reset();
});
this.reportedDone = false;
}
startedEvent() {
/**
* @typedef SuiteResult
* @typedef SuiteStartedEvent
* @property {String} id - The unique id of this suite.
* @property {String} description - The description text passed to the {@link describe} that made this suite.
* @property {String} fullName - The full description including all ancestors of this suite.
* @property {String|null} parentSuiteId - The ID of the suite containing this suite, or null if this is not in another describe().
* @property {String} filename - Deprecated. The name of the file the suite was defined in.
* Note: The value may be incorrect if zone.js is installed or
* `describe`/`fdescribe`/`xdescribe` 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 SuiteDoneEvent
* @property {String} id - The unique id of this suite.
* @property {String} description - The description text passed to the {@link describe} that made this suite.
* @property {String} fullName - The full description including all ancestors of this suite.
@@ -119,22 +156,32 @@ getJasmineRequireObj().Suite = function(j$) {
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSuiteProperty}
* @since 2.0.0
*/
this.result = {
const event = {
...this.#commonEventFields(),
status: this.#status()
};
const toCopy = [
'failedExpectations',
'deprecationWarnings',
'duration',
'properties'
];
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.#reportedParentSuiteId,
filename: this.filename,
failedExpectations: [],
deprecationWarnings: [],
duration: null,
properties: null
filename: this.filename
};
this.markedPending = this.markedExcluding;
this.children.forEach(function(child) {
child.reset();
});
this.reportedDone = false;
}
removeChildren() {
@@ -157,6 +204,10 @@ getJasmineRequireObj().Suite = function(j$) {
}
}
hasOwnFailedExpectations() {
return this.result.failedExpectations.length > 0;
}
getResult() {
this.result.status = this.#status();
return this.result;

View File

@@ -163,7 +163,7 @@ getJasmineRequireObj().TreeRunner = function(j$) {
this.#runQueue({
onComplete: maybeError => {
this.#suiteSegmentComplete(suite, suite.getResult(), () => {
this.#suiteSegmentComplete(suite, () => {
done(maybeError);
});
},
@@ -200,11 +200,12 @@ getJasmineRequireObj().TreeRunner = function(j$) {
#suiteSegmentStart(suite, next) {
this.#currentRunableTracker.pushSuite(suite);
this.#runableResources.initForRunable(suite.id, suite.parentSuite.id);
this.#reportDispatcher.suiteStarted(suite.result).then(next);
this.#reportDispatcher.suiteStarted(suite.startedEvent()).then(next);
suite.startTimer();
}
#suiteSegmentComplete(suite, result, next) {
#suiteSegmentComplete(suite, next) {
suite.endTimer();
const isTopSuite = suite === this.#executionTree.topSuite;
if (!isTopSuite) {
@@ -220,15 +221,14 @@ getJasmineRequireObj().TreeRunner = function(j$) {
this.#runableResources.clearForRunable(suite.id);
this.#currentRunableTracker.popSuite();
if (result.status === 'failed') {
if (suite.doneEvent().status === 'failed') {
this.#hasFailures = true;
}
suite.endTimer();
}
const finish = isTopSuite
? next
: () => this.#reportSuiteDone(suite, result, next);
: () => this.#reportSuiteDone(suite, next);
if (suite.hadBeforeAllFailure) {
this.#reportChildrenOfBeforeAllFailure(suite).then(finish);
@@ -237,9 +237,9 @@ getJasmineRequireObj().TreeRunner = function(j$) {
}
}
#reportSuiteDone(suite, result, next) {
#reportSuiteDone(suite, next) {
suite.reportedDone = true;
this.#reportDispatcher.suiteDone(result).then(next);
this.#reportDispatcher.suiteDone(suite.doneEvent()).then(next);
}
async #specComplete(spec) {
@@ -261,14 +261,14 @@ getJasmineRequireObj().TreeRunner = function(j$) {
async #reportChildrenOfBeforeAllFailure(suite) {
for (const child of suite.children) {
if (child instanceof j$.private.Suite) {
await this.#reportDispatcher.suiteStarted(child.result);
await this.#reportDispatcher.suiteStarted(child.startedEvent());
await this.#reportChildrenOfBeforeAllFailure(child);
// Marking the suite passed is consistent with how suites that
// contain failed specs but no suite-level failures are reported.
child.result.status = 'passed';
await this.#reportDispatcher.suiteDone(child.result);
await this.#reportDispatcher.suiteDone(child.doneEvent());
} else {
/* a spec */
await this.#reportDispatcher.specStarted(child.startedEvent());

View File

@@ -50,7 +50,7 @@ getJasmineRequireObj().reporterEvents = function(j$) {
* `suiteStarted` is invoked when a `describe` starts to run
* @function
* @name Reporter#suiteStarted
* @param {SuiteResult} result Information about the individual {@link describe} being run
* @param {SuiteStartedEvent} result Information about the individual {@link describe} 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
@@ -62,7 +62,7 @@ getJasmineRequireObj().reporterEvents = function(j$) {
* While jasmine doesn't require any specific functions, not defining a `suiteDone` will make it impossible for a reporter to know when a suite has failures in an `afterAll`.
* @function
* @name Reporter#suiteDone
* @param {SuiteResult} result
* @param {SuiteDoneEvent} 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