| 1011 | } |
| 1012 | |
| 1013 | createSubtest(Factory, name, options, fn, overrides) { |
| 1014 | if (typeof name === 'function') { |
| 1015 | fn = name; |
| 1016 | } else if (name !== null && typeof name === 'object') { |
| 1017 | fn = options; |
| 1018 | options = name; |
| 1019 | } else if (typeof options === 'function') { |
| 1020 | fn = options; |
| 1021 | } |
| 1022 | |
| 1023 | if (options === null || typeof options !== 'object') { |
| 1024 | options = kEmptyObject; |
| 1025 | } |
| 1026 | |
| 1027 | let parent = this; |
| 1028 | |
| 1029 | // If this test has already ended, attach this test to the root test so |
| 1030 | // that the error can be properly reported. |
| 1031 | const preventAddingSubtests = this.finished || this.buildPhaseFinished; |
| 1032 | if (preventAddingSubtests) { |
| 1033 | while (parent.parent !== null) { |
| 1034 | parent = parent.parent; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | const test = new Factory({ __proto__: null, fn, name, parent, ...options, ...overrides }); |
| 1039 | |
| 1040 | if (parent.waitingOn === 0) { |
| 1041 | parent.waitingOn = test.childNumber; |
| 1042 | parent.subtestsPromise = PromiseWithResolvers(); |
| 1043 | } |
| 1044 | |
| 1045 | if (preventAddingSubtests) { |
| 1046 | test.fail( |
| 1047 | new ERR_TEST_FAILURE( |
| 1048 | 'test could not be started because its parent finished', |
| 1049 | kParentAlreadyFinished, |
| 1050 | ), |
| 1051 | ); |
| 1052 | } |
| 1053 | |
| 1054 | ArrayPrototypePush(parent.subtests, test); |
| 1055 | return test; |
| 1056 | } |
| 1057 | |
| 1058 | #abortHandler = () => { |
| 1059 | const error = this.outerSignal?.reason || new AbortError('The test was aborted'); |