(name, fn, options)
| 1092 | } |
| 1093 | |
| 1094 | createHook(name, fn, options) { |
| 1095 | validateOneOf(name, 'hook name', kHookNames); |
| 1096 | // eslint-disable-next-line no-use-before-define |
| 1097 | const hook = new TestHook(fn, options); |
| 1098 | if (name === 'before' || name === 'after') { |
| 1099 | hook.run = runOnce(hook.run, kRunOnceOptions); |
| 1100 | } |
| 1101 | if (name === 'before' && this.startTime !== null) { |
| 1102 | // Test has already started, run the hook immediately |
| 1103 | PromisePrototypeThen(hook.run(this.getRunArgs()), () => { |
| 1104 | if (hook.error != null) { |
| 1105 | this.fail(hook.error); |
| 1106 | } |
| 1107 | }); |
| 1108 | } |
| 1109 | if (name === 'afterEach') { |
| 1110 | // afterEach hooks for the current test should run in the order that they |
| 1111 | // are created. However, the current test's afterEach hooks should run |
| 1112 | // prior to any ancestor afterEach hooks. |
| 1113 | ArrayPrototypeSplice(this.hooks[name], this.hooks.ownAfterEachCount, 0, hook); |
| 1114 | this.hooks.ownAfterEachCount++; |
| 1115 | } else { |
| 1116 | ArrayPrototypePush(this.hooks[name], hook); |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | fail(err) { |
| 1121 | if (this.error !== null) { |
no test coverage detected