Unify top suite and regular suite execution

This commit is contained in:
Steve Gravrock
2025-09-02 08:01:33 -07:00
parent 91bd3f8201
commit 60f34ec087
2 changed files with 66 additions and 102 deletions
+21 -39
View File
@@ -11445,34 +11445,9 @@ getJasmineRequireObj().TreeRunner = function(j$) {
async execute() { async execute() {
this.#hasFailures = false; this.#hasFailures = false;
const topSuite = this.#executionTree.topSuite;
const wrappedChildren = this.#wrapNodes(
this.#executionTree.childrenOfTopSuite()
);
const queueableFns = this.#addBeforeAndAfterAlls(
topSuite,
wrappedChildren
);
await new Promise(resolve => { await new Promise(resolve => {
this.#runQueue({ this.#executeSuiteSegment(this.#executionTree.topSuite, 0, resolve);
queueableFns,
userContext: this.#executionTree.topSuite.sharedUserContext(),
onException: function() {
topSuite.handleException.apply(topSuite, arguments);
}.bind(this),
onComplete: resolve,
onMultipleDone: topSuite.onMultipleDone
? topSuite.onMultipleDone.bind(topSuite)
: null,
SkipPolicy: this.#suiteSkipPolicy()
}); });
});
if (topSuite.hadBeforeAllFailure) {
await this.#reportChildrenOfBeforeAllFailure(topSuite);
}
return { hasFailures: this.#hasFailures }; return { hasFailures: this.#hasFailures };
} }
@@ -11584,18 +11559,20 @@ getJasmineRequireObj().TreeRunner = function(j$) {
} }
#executeSuiteSegment(suite, segmentNumber, done) { #executeSuiteSegment(suite, segmentNumber, done) {
const wrappedChildren = this.#wrapNodes( const isTopSuite = suite === this.#executionTree.topSuite;
this.#executionTree.childrenOfSuiteSegment(suite, segmentNumber) const children = isTopSuite
); ? this.#executionTree.childrenOfTopSuite()
const onStart = { : this.#executionTree.childrenOfSuiteSegment(suite, segmentNumber);
const wrappedChildren = this.#wrapNodes(children);
const queueableFns = this.#addBeforeAndAfterAlls(suite, wrappedChildren);
if (!isTopSuite) {
queueableFns.unshift({
fn: next => { fn: next => {
this.#suiteSegmentStart(suite, next); this.#suiteSegmentStart(suite, next);
} }
}; });
const queueableFns = [ }
onStart,
...this.#addBeforeAndAfterAlls(suite, wrappedChildren)
];
this.#runQueue({ this.#runQueue({
// TODO: if onComplete always takes 0-1 arguments (and it probably does) // TODO: if onComplete always takes 0-1 arguments (and it probably does)
@@ -11627,7 +11604,9 @@ getJasmineRequireObj().TreeRunner = function(j$) {
#suiteSegmentComplete(suite, result, next) { #suiteSegmentComplete(suite, result, next) {
suite.cleanupBeforeAfter(); suite.cleanupBeforeAfter();
const isTopSuite = suite === this.#executionTree.topSuite;
if (!isTopSuite) {
if (suite !== this.#currentRunableTracker.currentSuite()) { if (suite !== this.#currentRunableTracker.currentSuite()) {
throw new Error('Tried to complete the wrong suite'); throw new Error('Tried to complete the wrong suite');
} }
@@ -11639,13 +11618,16 @@ getJasmineRequireObj().TreeRunner = function(j$) {
this.#hasFailures = true; this.#hasFailures = true;
} }
suite.endTimer(); suite.endTimer();
}
const finish = isTopSuite
? next
: () => this.#reportSuiteDone(suite, result, next);
if (suite.hadBeforeAllFailure) { if (suite.hadBeforeAllFailure) {
this.#reportChildrenOfBeforeAllFailure(suite).then(() => { this.#reportChildrenOfBeforeAllFailure(suite).then(finish);
this.#reportSuiteDone(suite, result, next);
});
} else { } else {
this.#reportSuiteDone(suite, result, next); finish();
} }
} }
+21 -39
View File
@@ -23,34 +23,9 @@ getJasmineRequireObj().TreeRunner = function(j$) {
async execute() { async execute() {
this.#hasFailures = false; this.#hasFailures = false;
const topSuite = this.#executionTree.topSuite;
const wrappedChildren = this.#wrapNodes(
this.#executionTree.childrenOfTopSuite()
);
const queueableFns = this.#addBeforeAndAfterAlls(
topSuite,
wrappedChildren
);
await new Promise(resolve => { await new Promise(resolve => {
this.#runQueue({ this.#executeSuiteSegment(this.#executionTree.topSuite, 0, resolve);
queueableFns,
userContext: this.#executionTree.topSuite.sharedUserContext(),
onException: function() {
topSuite.handleException.apply(topSuite, arguments);
}.bind(this),
onComplete: resolve,
onMultipleDone: topSuite.onMultipleDone
? topSuite.onMultipleDone.bind(topSuite)
: null,
SkipPolicy: this.#suiteSkipPolicy()
}); });
});
if (topSuite.hadBeforeAllFailure) {
await this.#reportChildrenOfBeforeAllFailure(topSuite);
}
return { hasFailures: this.#hasFailures }; return { hasFailures: this.#hasFailures };
} }
@@ -162,18 +137,20 @@ getJasmineRequireObj().TreeRunner = function(j$) {
} }
#executeSuiteSegment(suite, segmentNumber, done) { #executeSuiteSegment(suite, segmentNumber, done) {
const wrappedChildren = this.#wrapNodes( const isTopSuite = suite === this.#executionTree.topSuite;
this.#executionTree.childrenOfSuiteSegment(suite, segmentNumber) const children = isTopSuite
); ? this.#executionTree.childrenOfTopSuite()
const onStart = { : this.#executionTree.childrenOfSuiteSegment(suite, segmentNumber);
const wrappedChildren = this.#wrapNodes(children);
const queueableFns = this.#addBeforeAndAfterAlls(suite, wrappedChildren);
if (!isTopSuite) {
queueableFns.unshift({
fn: next => { fn: next => {
this.#suiteSegmentStart(suite, next); this.#suiteSegmentStart(suite, next);
} }
}; });
const queueableFns = [ }
onStart,
...this.#addBeforeAndAfterAlls(suite, wrappedChildren)
];
this.#runQueue({ this.#runQueue({
// TODO: if onComplete always takes 0-1 arguments (and it probably does) // TODO: if onComplete always takes 0-1 arguments (and it probably does)
@@ -205,7 +182,9 @@ getJasmineRequireObj().TreeRunner = function(j$) {
#suiteSegmentComplete(suite, result, next) { #suiteSegmentComplete(suite, result, next) {
suite.cleanupBeforeAfter(); suite.cleanupBeforeAfter();
const isTopSuite = suite === this.#executionTree.topSuite;
if (!isTopSuite) {
if (suite !== this.#currentRunableTracker.currentSuite()) { if (suite !== this.#currentRunableTracker.currentSuite()) {
throw new Error('Tried to complete the wrong suite'); throw new Error('Tried to complete the wrong suite');
} }
@@ -217,13 +196,16 @@ getJasmineRequireObj().TreeRunner = function(j$) {
this.#hasFailures = true; this.#hasFailures = true;
} }
suite.endTimer(); suite.endTimer();
}
const finish = isTopSuite
? next
: () => this.#reportSuiteDone(suite, result, next);
if (suite.hadBeforeAllFailure) { if (suite.hadBeforeAllFailure) {
this.#reportChildrenOfBeforeAllFailure(suite).then(() => { this.#reportChildrenOfBeforeAllFailure(suite).then(finish);
this.#reportSuiteDone(suite, result, next);
});
} else { } else {
this.#reportSuiteDone(suite, result, next); finish();
} }
} }