Split the resulting execution tree out from TreeProcessor

This commit is contained in:
Steve Gravrock
2025-08-16 09:17:48 -07:00
parent b89a870a59
commit a3e1abfa12
4 changed files with 120 additions and 94 deletions

View File

@@ -6,7 +6,7 @@ getJasmineRequireObj().Runner = function(j$) {
#runableResources;
#runQueue;
#TreeProcessor;
#treeProcessor;
#executionTree;
#globalErrors;
#reportDispatcher;
#getConfig;
@@ -69,7 +69,7 @@ getJasmineRequireObj().Runner = function(j$) {
seed: j$.isNumber_(config.seed) ? config.seed + '' : config.seed
});
this.#treeProcessor = new this.#TreeProcessor({
const treeProcessor = new this.#TreeProcessor({
tree: this.#topSuite,
runnableIds: runablesToRun,
orderChildren: function(node) {
@@ -79,7 +79,7 @@ getJasmineRequireObj().Runner = function(j$) {
return !config.specFilter(spec);
}
});
this.#treeProcessor.processTree();
this.#executionTree = treeProcessor.processTree();
return this.#execute2(runablesToRun, order);
}
@@ -164,7 +164,7 @@ getJasmineRequireObj().Runner = function(j$) {
async #executeTopSuite() {
const wrappedChildren = this.#wrapNodes(
this.#treeProcessor.childrenOfTopSuite()
this.#executionTree.childrenOfTopSuite()
);
const queueableFns = this.#addBeforeAndAfterAlls(
this.#topSuite,
@@ -188,7 +188,7 @@ getJasmineRequireObj().Runner = function(j$) {
#executeSuiteSegment(suite, segmentNumber, done) {
const wrappedChildren = this.#wrapNodes(
this.#treeProcessor.childrenOfSuiteSegment(suite, segmentNumber)
this.#executionTree.childrenOfSuiteSegment(suite, segmentNumber)
);
const onStart = {
fn: next => {
@@ -226,7 +226,7 @@ getJasmineRequireObj().Runner = function(j$) {
this.#runQueueWithSkipPolicy.bind(this),
this.#globalErrors,
done,
this.#treeProcessor.isExcluded(spec),
this.#executionTree.isExcluded(spec),
config.failSpecWithNoExpectations,
config.detectLateRejectionHandling
);
@@ -247,7 +247,7 @@ getJasmineRequireObj().Runner = function(j$) {
}
#addBeforeAndAfterAlls(suite, wrappedChildren) {
if (this.#treeProcessor.isExcluded(suite)) {
if (this.#executionTree.isExcluded(suite)) {
return wrappedChildren;
}

View File

@@ -2,13 +2,15 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
const defaultMin = Infinity;
const defaultMax = 1 - Infinity;
// Transforms the suite tree into an execution tree, which represents the set
// of specs and (possibly interleaved) suites to be run in the order they are
// to be run in.
class TreeProcessor {
#tree;
#runnableIds;
#orderChildren;
#excludeNode;
#stats;
#processed;
constructor(attrs) {
this.#tree = attrs.tree;
@@ -24,34 +26,14 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
function(node) {
return false;
};
this.#stats = {};
this.#processed = false;
}
processTree() {
this.#stats = {};
this.#processNode(this.#tree, true);
this.#processed = true;
}
childrenOfTopSuite() {
return this.childrenOfSuiteSegment(this.#tree, 0);
}
childrenOfSuiteSegment(suite, segmentNumber) {
const segmentChildren = this.#stats[suite.id].segments[segmentNumber]
.nodes;
return segmentChildren.map(function(child) {
if (child.owner.children) {
return { suite: child.owner, segmentNumber: child.index };
} else {
return { spec: child.owner };
}
});
}
isExcluded(node) {
const nodeStats = this.#stats[node.id];
return node.children ? !nodeStats.willExecute : nodeStats.excluded;
const result = new ExecutionTree(this.#tree, this.#stats);
this.#stats = null;
return result;
}
#runnableIndex(id) {
@@ -118,6 +100,37 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
}
}
class ExecutionTree {
#topSuite;
#stats;
constructor(topSuite, stats) {
this.#topSuite = topSuite;
this.#stats = stats;
}
childrenOfTopSuite() {
return this.childrenOfSuiteSegment(this.#topSuite, 0);
}
childrenOfSuiteSegment(suite, segmentNumber) {
const segmentChildren = this.#stats[suite.id].segments[segmentNumber]
.nodes;
return segmentChildren.map(function(child) {
if (child.owner.children) {
return { suite: child.owner, segmentNumber: child.index };
} else {
return { spec: child.owner };
}
});
}
isExcluded(node) {
const nodeStats = this.#stats[node.id];
return node.children ? !nodeStats.willExecute : nodeStats.excluded;
}
}
function segmentChildren(node, orderedChildren, stats, executableIndex) {
let currentSegment = {
index: 0,