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

Function createProcessEventHandler

lib/internal/test_runner/harness.js:118–167  ·  view source on GitHub ↗
(eventName, rootTest)

Source from the content-addressed store, hash-verified

116}
117
118function createProcessEventHandler(eventName, rootTest) {
119 return (err) => {
120 if (rootTest.harness.bootstrapPromise) {
121 // Something went wrong during the asynchronous portion of bootstrapping
122 // the test runner. Since the test runner is not setup properly, we can't
123 // do anything but throw the error.
124 throw err;
125 }
126
127 const test = testResources.get(executionAsyncId());
128
129 // Check if this error is coming from a reporter. If it is, throw it.
130 if (test === reporterScope) {
131 throw err;
132 }
133
134 // Check if this error is coming from a test or test hook. If it is, fail the test.
135 if (!test || test.finished || test.hookType) {
136 // If the test is already finished or the resource that created the error
137 // is not mapped to a Test, report this as a top level diagnostic.
138 let msg;
139
140 if (test) {
141 const name = test.hookType ? `Test hook "${test.hookType}"` : `Test "${test.name}"`;
142 let locInfo = '';
143 if (test.loc) {
144 const relPath = relative(rootTest.config.cwd, test.loc.file);
145 locInfo = ` at ${relPath}:${test.loc.line}:${test.loc.column}`;
146 }
147
148 msg = `Error: ${name}${locInfo} generated asynchronous ` +
149 'activity after the test ended. This activity created the error ' +
150 `"${err}" and would have caused the test to fail, but instead ` +
151 `triggered an ${eventName} event.`;
152 } else {
153 msg = 'Error: A resource generated asynchronous activity after ' +
154 `the test ended. This activity created the error "${err}" which ` +
155 `triggered an ${eventName} event, caught by the test runner.`;
156 }
157
158 rootTest.diagnostic(msg);
159 rootTest.harness.success = false;
160 process.exitCode = kGenericUserError;
161 return;
162 }
163
164 test.fail(new ERR_TEST_FAILURE(err, eventName));
165 test.abortController.abort();
166 };
167}
168
169function configureCoverage(rootTest, globalOptions) {
170 if (!globalOptions.coverage) {

Callers 1

setupProcessStateFunction · 0.85

Calls 6

executionAsyncIdFunction · 0.85
relativeFunction · 0.85
getMethod · 0.65
abortMethod · 0.65
diagnosticMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…