Test TreeProcessor's public interface, not internal state

This commit is contained in:
Steve Gravrock
2025-08-16 09:10:09 -07:00
parent ea3fc88803
commit b89a870a59
3 changed files with 52 additions and 96 deletions

View File

@@ -11430,7 +11430,6 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
processTree() { processTree() {
this.#processNode(this.#tree, true); this.#processNode(this.#tree, true);
this.#processed = true; this.#processed = true;
return this.#stats;
} }
childrenOfTopSuite() { childrenOfTopSuite() {

View File

@@ -31,14 +31,11 @@ describe('TreeProcessor', function() {
processor = new jasmineUnderTest.TreeProcessor({ processor = new jasmineUnderTest.TreeProcessor({
tree: leaf, tree: leaf,
runnableIds: [leaf.id] runnableIds: [leaf.id]
}), });
result = processor.processTree();
expect(result[leaf.id]).toEqual({ processor.processTree();
excluded: false,
willExecute: true, expect(processor.isExcluded(leaf)).toEqual(false);
segments: jasmine.any(Array)
});
}); });
it('processes a single pending leaf', function() { it('processes a single pending leaf', function() {
@@ -46,14 +43,11 @@ describe('TreeProcessor', function() {
processor = new jasmineUnderTest.TreeProcessor({ processor = new jasmineUnderTest.TreeProcessor({
tree: leaf, tree: leaf,
runnableIds: [leaf.id] runnableIds: [leaf.id]
}), });
result = processor.processTree();
expect(result[leaf.id]).toEqual({ processor.processTree();
excluded: false,
willExecute: false, expect(processor.isExcluded(leaf)).toEqual(false);
segments: jasmine.any(Array)
});
}); });
it('processes a single non-specified leaf', function() { it('processes a single non-specified leaf', function() {
@@ -61,14 +55,11 @@ describe('TreeProcessor', function() {
processor = new jasmineUnderTest.TreeProcessor({ processor = new jasmineUnderTest.TreeProcessor({
tree: leaf, tree: leaf,
runnableIds: [] runnableIds: []
}), });
result = processor.processTree();
expect(result[leaf.id]).toEqual({ processor.processTree();
excluded: true,
willExecute: false, expect(processor.isExcluded(leaf)).toEqual(true);
segments: jasmine.any(Array)
});
}); });
it('processes a single excluded leaf', function() { it('processes a single excluded leaf', function() {
@@ -79,14 +70,11 @@ describe('TreeProcessor', function() {
excludeNode: function() { excludeNode: function() {
return true; return true;
} }
}), });
result = processor.processTree();
expect(result[leaf.id]).toEqual({ processor.processTree();
excluded: true,
willExecute: false, expect(processor.isExcluded(leaf)).toEqual(true);
segments: jasmine.any(Array)
});
}); });
it('processes a tree with a single leaf with the root specified', function() { it('processes a tree with a single leaf with the root specified', function() {
@@ -95,20 +83,13 @@ describe('TreeProcessor', function() {
processor = new jasmineUnderTest.TreeProcessor({ processor = new jasmineUnderTest.TreeProcessor({
tree: parent, tree: parent,
runnableIds: [parent.id] runnableIds: [parent.id]
}), });
result = processor.processTree();
expect(result[parent.id]).toEqual({ processor.processTree();
excluded: false,
willExecute: true,
segments: jasmine.any(Array)
});
expect(result[leaf.id]).toEqual({ expect(processor.isExcluded(parent)).toEqual(false);
excluded: false, expect(processor.childrenOfTopSuite()).toEqual([{ spec: leaf }]);
willExecute: true, expect(processor.isExcluded(leaf)).toEqual(false);
segments: jasmine.any(Array)
});
}); });
it('processes a tree with a single pending leaf, with the root specified', function() { it('processes a tree with a single pending leaf, with the root specified', function() {
@@ -117,20 +98,13 @@ describe('TreeProcessor', function() {
processor = new jasmineUnderTest.TreeProcessor({ processor = new jasmineUnderTest.TreeProcessor({
tree: parent, tree: parent,
runnableIds: [parent.id] runnableIds: [parent.id]
}), });
result = processor.processTree();
expect(result[parent.id]).toEqual({ processor.processTree();
excluded: false,
willExecute: false,
segments: jasmine.any(Array)
});
expect(result[leaf.id]).toEqual({ expect(processor.isExcluded(parent)).toEqual(true);
excluded: false, expect(processor.childrenOfTopSuite()).toEqual([{ spec: leaf }]);
willExecute: false, expect(processor.isExcluded(leaf)).toEqual(false);
segments: jasmine.any(Array)
});
}); });
it('processes a complicated tree with the root specified', function() { it('processes a complicated tree with the root specified', function() {
@@ -151,56 +125,40 @@ describe('TreeProcessor', function() {
processor = new jasmineUnderTest.TreeProcessor({ processor = new jasmineUnderTest.TreeProcessor({
tree: root, tree: root,
runnableIds: [root.id] runnableIds: [root.id]
}), });
result = processor.processTree();
expect(result[root.id]).toEqual({ processor.processTree();
excluded: false,
willExecute: true,
segments: jasmine.any(Array)
});
expect(result[parentOfPendings.id]).toEqual({ expect(processor.isExcluded(parent)).toEqual(false);
excluded: false, expect(processor.childrenOfTopSuite()).toEqual([
willExecute: false, { suite: parent, segmentNumber: 0 },
segments: jasmine.any(Array) { suite: parentOfPendings, segmentNumber: 0 }
}); ]);
expect(result[childless.id]).toEqual({ expect(processor.isExcluded(parentOfPendings)).toEqual(true);
excluded: false, expect(processor.childrenOfSuiteSegment(parentOfPendings, 0)).toEqual([
willExecute: false, { suite: childless, segmentNumber: 0 },
segments: jasmine.any(Array) { suite: pendingNode, segmentNumber: 0 }
}); ]);
expect(result[pendingLeaf.id]).toEqual({ expect(processor.isExcluded(childless)).toEqual(true);
excluded: false, expect(processor.childrenOfSuiteSegment(childless, 0)).toEqual([]);
willExecute: false,
segments: jasmine.any(Array)
});
expect(result[executableLeaf.id]).toEqual({ expect(processor.isExcluded(pendingLeaf)).toEqual(false);
excluded: false, expect(processor.isExcluded(executableLeaf)).toEqual(false);
willExecute: true,
segments: jasmine.any(Array)
});
expect(result[parent.id]).toEqual({ expect(processor.isExcluded(parent)).toEqual(false);
excluded: false, expect(processor.childrenOfSuiteSegment(parent, 0)).toEqual([
willExecute: true, { spec: pendingLeaf },
segments: jasmine.any(Array) { spec: executableLeaf }
}); ]);
expect(result[pendingNode.id]).toEqual({ expect(processor.isExcluded(pendingNode)).toEqual(true);
excluded: false, expect(processor.childrenOfSuiteSegment(pendingNode, 0)).toEqual([
willExecute: false, { spec: childOfPending }
segments: jasmine.any(Array) ]);
});
expect(result[childOfPending.id]).toEqual({ expect(processor.isExcluded(childOfPending)).toEqual(false);
excluded: false,
willExecute: false,
segments: jasmine.any(Array)
});
}); });
it('throws if the specified order would re-enter a node that does not allow re-entry', function() { it('throws if the specified order would re-enter a node that does not allow re-entry', function() {

View File

@@ -31,7 +31,6 @@ getJasmineRequireObj().TreeProcessor = function(j$) {
processTree() { processTree() {
this.#processNode(this.#tree, true); this.#processNode(this.#tree, true);
this.#processed = true; this.#processed = true;
return this.#stats;
} }
childrenOfTopSuite() { childrenOfTopSuite() {