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

Function setupProcessState

lib/internal/test_runner/harness.js:232–337  ·  view source on GitHub ↗
(root, globalOptions)

Source from the content-addressed store, hash-verified

230}
231
232function setupProcessState(root, globalOptions) {
233 const hook = createHook({
234 __proto__: null,
235 init(asyncId, type, triggerAsyncId, resource) {
236 if (resource instanceof Test) {
237 testResources.set(asyncId, resource);
238 return;
239 }
240
241 const parent = testResources.get(triggerAsyncId);
242
243 if (parent !== undefined) {
244 testResources.set(asyncId, parent);
245 }
246 },
247 destroy(asyncId) {
248 testResources.delete(asyncId);
249 },
250 });
251
252 hook.enable();
253
254 const exceptionHandler =
255 createProcessEventHandler('uncaughtException', root);
256 const rejectionHandler =
257 createProcessEventHandler('unhandledRejection', root);
258 const coverage = configureCoverage(root, globalOptions);
259
260 setupFailureStateFile(root, globalOptions);
261
262 const exitHandler = async (kill) => {
263 if (root.subtests.length === 0 && (root.hooks.before.length > 0 || root.hooks.after.length > 0)) {
264 // Run global before/after hooks in case there are no tests
265 await root.run();
266 }
267
268 if (kill !== true && root.subtestsPromise !== null) {
269 // Wait for all subtests to finish, but keep the process alive in case
270 // there are no ref'ed handles left.
271 const keepAlive = setInterval(() => {}, TIMEOUT_MAX);
272 await root.subtestsPromise.promise;
273 clearInterval(keepAlive);
274 }
275
276 root.postRun(new ERR_TEST_FAILURE(
277 'Promise resolution is still pending but the event loop has already resolved',
278 kCancelledByParent));
279
280 if (root.harness.globalTeardownFunction) {
281 await root.harness.globalTeardownFunction();
282 root.harness.globalTeardownFunction = null;
283 }
284
285 hook.disable();
286 process.removeListener('uncaughtException', exceptionHandler);
287 process.removeListener('unhandledRejection', rejectionHandler);
288 process.removeListener('beforeExit', exitHandler);
289 if (globalOptions.isTestRunner) {

Callers 1

createTestTreeFunction · 0.85

Calls 6

configureCoverageFunction · 0.85
setupFailureStateFileFunction · 0.85
createHookFunction · 0.50
enableMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected