MCPcopy Index your code
hub / github.com/nodejs/node / createHook

Method createHook

lib/internal/test_runner/test.js:1094–1118  ·  view source on GitHub ↗
(name, fn, options)

Source from the content-addressed store, hash-verified

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) {

Callers 15

createHookFunction · 0.80
updatePromiseHookModeFunction · 0.80
beforeMethod · 0.80
afterMethod · 0.80
beforeEachMethod · 0.80
afterEachMethod · 0.80
hookFunction · 0.80
toggleTraceCategoryStateFunction · 0.80
mainFunction · 0.80

Calls 3

runMethod · 0.95
getRunArgsMethod · 0.95
failMethod · 0.95

Tested by

no test coverage detected