MCPcopy
hub / github.com/jestjs/jest / treeProcessor

Function treeProcessor

packages/jest-jasmine2/src/treeProcessor.ts:45–88  ·  view source on GitHub ↗
(options: Options)

Source from the content-addressed store, hash-verified

43}
44
45export default function treeProcessor(options: Options): void {
46 const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} =
47 options;
48
49 function isEnabled(node: TreeNode, parentEnabled: boolean) {
50 return parentEnabled || runnableIds.includes(node.id);
51 }
52
53 function getNodeHandler(node: TreeNode, parentEnabled: boolean) {
54 const enabled = isEnabled(node, parentEnabled);
55 return node.children
56 ? getNodeWithChildrenHandler(node, enabled)
57 : getNodeWithoutChildrenHandler(node, enabled);
58 }
59
60 function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) {
61 return async function fn(done: (error?: unknown) => void = noop) {
62 nodeStart(node);
63 await queueRunnerFactory({
64 onException: (error: Error) => node.onException(error),
65 queueableFns: wrapChildren(node, enabled),
66 userContext: node.sharedUserContext(),
67 });
68 nodeComplete(node);
69 done();
70 };
71 }
72
73 function wrapChildren(node: TreeNode, enabled: boolean) {
74 if (!node.children) {
75 throw new Error('`node.children` is not defined.');
76 }
77 const children = node.children.map(child => ({
78 fn: getNodeHandler(child, enabled),
79 }));
80 if (hasNoEnabledTest(node)) {
81 return children;
82 }
83 return [...node.beforeAllFns, ...children, ...node.afterAllFns];
84 }
85
86 const treeHandler = getNodeHandler(tree, false);
87 return treeHandler();
88}

Callers 1

constructorMethod · 0.85

Calls 1

getNodeHandlerFunction · 0.85

Tested by

no test coverage detected