Remove mutual recursion between Runner and TreeProcessor
This commit is contained in:
@@ -6,6 +6,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
||||
#runableResources;
|
||||
#runQueue;
|
||||
#TreeProcessor;
|
||||
#treeProcessor;
|
||||
#globalErrors;
|
||||
#reportDispatcher;
|
||||
#getConfig;
|
||||
@@ -68,12 +69,9 @@ getJasmineRequireObj().Runner = function(j$) {
|
||||
seed: j$.isNumber_(config.seed) ? config.seed + '' : config.seed
|
||||
});
|
||||
|
||||
const processor = new this.#TreeProcessor({
|
||||
this.#treeProcessor = new this.#TreeProcessor({
|
||||
tree: this.#topSuite,
|
||||
runnableIds: runablesToRun,
|
||||
executeTopSuite: this.#executeTopSuite.bind(this),
|
||||
executeSpec: this.#executeSpec.bind(this),
|
||||
executeSuiteSegment: this.#executeSuiteSegment.bind(this),
|
||||
orderChildren: function(node) {
|
||||
return order.sort(node.children);
|
||||
},
|
||||
@@ -81,12 +79,12 @@ getJasmineRequireObj().Runner = function(j$) {
|
||||
return !config.specFilter(spec);
|
||||
}
|
||||
});
|
||||
processor.processTree();
|
||||
this.#treeProcessor.processTree();
|
||||
|
||||
return this.#execute2(runablesToRun, order, processor);
|
||||
return this.#execute2(runablesToRun, order);
|
||||
}
|
||||
|
||||
async #execute2(runablesToRun, order, processor) {
|
||||
async #execute2(runablesToRun, order) {
|
||||
const totalSpecsDefined = this.#getTotalSpecsDefined();
|
||||
|
||||
this.#runableResources.initForRunable(this.#topSuite.id);
|
||||
@@ -110,7 +108,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
||||
});
|
||||
|
||||
this.#currentlyExecutingSuites.push(this.#topSuite);
|
||||
await processor.execute();
|
||||
await this.#executeTopSuite();
|
||||
|
||||
if (this.#topSuite.hadBeforeAllFailure) {
|
||||
await this.#reportChildrenOfBeforeAllFailure(this.#topSuite);
|
||||
@@ -164,28 +162,34 @@ getJasmineRequireObj().Runner = function(j$) {
|
||||
return jasmineDoneInfo;
|
||||
}
|
||||
|
||||
// TreeProcessor callback.
|
||||
#executeTopSuite(topSuite, wrappedChildren, done) {
|
||||
async #executeTopSuite() {
|
||||
const wrappedChildren = this.#wrapNodes(
|
||||
this.#treeProcessor.childrenOfTopSuite()
|
||||
);
|
||||
const queueableFns = this.#addBeforeAndAfterAlls(
|
||||
topSuite,
|
||||
true,
|
||||
this.#topSuite,
|
||||
wrappedChildren
|
||||
);
|
||||
this.#runQueueWithSkipPolicy({
|
||||
queueableFns,
|
||||
userContext: topSuite.sharedUserContext(),
|
||||
onException: function() {
|
||||
topSuite.handleException.apply(topSuite, arguments);
|
||||
}.bind(this),
|
||||
onComplete: done,
|
||||
onMultipleDone: topSuite.onMultipleDone
|
||||
? topSuite.onMultipleDone.bind(topSuite)
|
||||
: null
|
||||
|
||||
await new Promise(resolve => {
|
||||
this.#runQueueWithSkipPolicy({
|
||||
queueableFns,
|
||||
userContext: this.#topSuite.sharedUserContext(),
|
||||
onException: function() {
|
||||
this.#topSuite.handleException.apply(this.#topSuite, arguments);
|
||||
}.bind(this),
|
||||
onComplete: resolve,
|
||||
onMultipleDone: this.#topSuite.onMultipleDone
|
||||
? this.#topSuite.onMultipleDone.bind(this.#topSuite)
|
||||
: null
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// TreeProcessor callback. Mutually recursive with TreeProcessor##executeNode.
|
||||
#executeSuiteSegment(suite, excluded, wrappedChildren, done) {
|
||||
#executeSuiteSegment(suite, segmentNumber, done) {
|
||||
const wrappedChildren = this.#wrapNodes(
|
||||
this.#treeProcessor.childrenOfSuiteSegment(suite, segmentNumber)
|
||||
);
|
||||
const onStart = {
|
||||
fn: next => {
|
||||
this.#suiteSegmentStart(suite, next);
|
||||
@@ -193,7 +197,7 @@ getJasmineRequireObj().Runner = function(j$) {
|
||||
};
|
||||
const queueableFns = [
|
||||
onStart,
|
||||
...this.#addBeforeAndAfterAlls(suite, excluded, wrappedChildren)
|
||||
...this.#addBeforeAndAfterAlls(suite, wrappedChildren)
|
||||
];
|
||||
|
||||
this.#runQueueWithSkipPolicy({
|
||||
@@ -216,27 +220,40 @@ getJasmineRequireObj().Runner = function(j$) {
|
||||
});
|
||||
}
|
||||
|
||||
// TreeProcessor callback.
|
||||
#executeSpec(spec, excluded, done) {
|
||||
#executeSpec(spec, done) {
|
||||
const config = this.#getConfig();
|
||||
spec.execute(
|
||||
this.#runQueueWithSkipPolicy.bind(this),
|
||||
this.#globalErrors,
|
||||
done,
|
||||
excluded,
|
||||
this.#treeProcessor.isExcluded(spec),
|
||||
config.failSpecWithNoExpectations,
|
||||
config.detectLateRejectionHandling
|
||||
);
|
||||
}
|
||||
|
||||
#addBeforeAndAfterAlls(suite, willExecute, wrappedChildren) {
|
||||
if (willExecute) {
|
||||
return suite.beforeAllFns
|
||||
.concat(wrappedChildren)
|
||||
.concat(suite.afterAllFns);
|
||||
} else {
|
||||
#wrapNodes(nodes) {
|
||||
return nodes.map(node => {
|
||||
return {
|
||||
fn: done => {
|
||||
if (node.suite) {
|
||||
this.#executeSuiteSegment(node.suite, node.segmentNumber, done);
|
||||
} else {
|
||||
this.#executeSpec(node.spec, done);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
#addBeforeAndAfterAlls(suite, wrappedChildren) {
|
||||
if (this.#treeProcessor.isExcluded(suite)) {
|
||||
return wrappedChildren;
|
||||
}
|
||||
|
||||
return suite.beforeAllFns
|
||||
.concat(wrappedChildren)
|
||||
.concat(suite.afterAllFns);
|
||||
}
|
||||
|
||||
#suiteSegmentStart(suite, next) {
|
||||
|
||||
@@ -4,9 +4,6 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
|
||||
|
||||
class TreeProcessor {
|
||||
#tree;
|
||||
#executeTopSuite;
|
||||
#executeSpec;
|
||||
#executeSuiteSegment;
|
||||
#runnableIds;
|
||||
#orderChildren;
|
||||
#excludeNode;
|
||||
@@ -16,9 +13,6 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
|
||||
constructor(attrs) {
|
||||
this.#tree = attrs.tree;
|
||||
this.#runnableIds = attrs.runnableIds;
|
||||
this.#executeTopSuite = attrs.executeTopSuite;
|
||||
this.#executeSpec = attrs.executeSpec;
|
||||
this.#executeSuiteSegment = attrs.executeSuiteSegment;
|
||||
|
||||
this.#orderChildren =
|
||||
attrs.orderChildren ||
|
||||
@@ -30,7 +24,7 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
|
||||
function(node) {
|
||||
return false;
|
||||
};
|
||||
this.#stats = { valid: true };
|
||||
this.#stats = {};
|
||||
this.#processed = false;
|
||||
}
|
||||
|
||||
@@ -40,22 +34,27 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
|
||||
return this.#stats;
|
||||
}
|
||||
|
||||
async execute() {
|
||||
if (!this.#processed) {
|
||||
this.processTree();
|
||||
}
|
||||
childrenOfTopSuite() {
|
||||
return this.childrenOfSuiteSegment(this.#tree, 0);
|
||||
}
|
||||
|
||||
if (!this.#stats.valid) {
|
||||
throw new Error('invalid order');
|
||||
}
|
||||
|
||||
const wrappedChildren = this.#wrapChildren(this.#tree, 0);
|
||||
|
||||
await new Promise(resolve => {
|
||||
this.#executeTopSuite(this.#tree, wrappedChildren, resolve);
|
||||
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;
|
||||
}
|
||||
|
||||
#runnableIndex(id) {
|
||||
for (let i = 0; i < this.#runnableIds.length; i++) {
|
||||
if (this.#runnableIds[i] === id) {
|
||||
@@ -93,15 +92,8 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
|
||||
|
||||
for (let i = 0; i < orderedChildren.length; i++) {
|
||||
const child = orderedChildren[i];
|
||||
|
||||
this.#processNode(child, parentExcluded);
|
||||
|
||||
if (!this.#stats.valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const childStats = this.#stats[child.id];
|
||||
|
||||
hasExecutableChild = hasExecutableChild || childStats.willExecute;
|
||||
}
|
||||
|
||||
@@ -118,7 +110,6 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
|
||||
'The specified spec/suite order splits up a suite, running unrelated specs in the middle of it. This will become an error in a future release.'
|
||||
);
|
||||
} else {
|
||||
this.#stats = { valid: false };
|
||||
throw new Error(
|
||||
'Invalid order: would cause a beforeAll or afterAll to be run multiple times'
|
||||
);
|
||||
@@ -126,37 +117,6 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#wrapChildren(node, segmentNumber) {
|
||||
const result = [],
|
||||
segmentChildren = this.#stats[node.id].segments[segmentNumber].nodes;
|
||||
|
||||
for (let i = 0; i < segmentChildren.length; i++) {
|
||||
result.push(
|
||||
this.#executeNode(segmentChildren[i].owner, segmentChildren[i].index)
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#executeNode(node, segmentNumber) {
|
||||
if (node.children) {
|
||||
return {
|
||||
fn: done => {
|
||||
const wrappedChildren = this.#wrapChildren(node, segmentNumber);
|
||||
const willExecute = this.#stats[node.id].willExecute;
|
||||
this.#executeSuiteSegment(node, willExecute, wrappedChildren, done);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
fn: done => {
|
||||
this.#executeSpec(node, this.#stats[node.id].excluded, done);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function segmentChildren(node, orderedChildren, stats, executableIndex) {
|
||||
|
||||
Reference in New Issue
Block a user