'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
 
Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.default = treeProcessor;
 
/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
function treeProcessor(options) {
  const {
    nodeComplete,
    nodeStart,
    queueRunnerFactory,
    runnableIds,
    tree
  } = options;
 
  function isEnabled(node, parentEnabled) {
    return parentEnabled || runnableIds.indexOf(node.id) !== -1;
  }
 
  function getNodeHandler(node, parentEnabled) {
    const enabled = isEnabled(node, parentEnabled);
    return node.children
      ? getNodeWithChildrenHandler(node, enabled)
      : getNodeWithoutChildrenHandler(node, enabled);
  }
 
  function getNodeWithoutChildrenHandler(node, enabled) {
    return function fn(done = () => {}) {
      node.execute(done, enabled);
    };
  }
 
  function getNodeWithChildrenHandler(node, enabled) {
    return async function fn(done = () => {}) {
      nodeStart(node);
      await queueRunnerFactory({
        onException: error => node.onException(error),
        queueableFns: wrapChildren(node, enabled),
        userContext: node.sharedUserContext()
      });
      nodeComplete(node);
      done();
    };
  }
 
  function hasNoEnabledTest(node) {
    if (node.children) {
      return node.children.every(hasNoEnabledTest);
    }
 
    return node.disabled || node.markedPending;
  }
 
  function wrapChildren(node, enabled) {
    if (!node.children) {
      throw new Error('`node.children` is not defined.');
    }
 
    const children = node.children.map(child => ({
      fn: getNodeHandler(child, enabled)
    }));
 
    if (hasNoEnabledTest(node)) {
      return children;
    }
 
    return node.beforeAllFns.concat(children).concat(node.afterAllFns);
  }
 
  const treeHandler = getNodeHandler(tree, false);
  return treeHandler();
}