MCPcopy
hub / github.com/jestjs/jest / readResultsAndExit

Function readResultsAndExit

packages/jest-cli/src/run.ts:104–148  ·  view source on GitHub ↗
(
  result: AggregatedResult | null,
  globalConfig: Config.GlobalConfig,
)

Source from the content-addressed store, hash-verified

102};
103
104const readResultsAndExit = (
105 result: AggregatedResult | null,
106 globalConfig: Config.GlobalConfig,
107) => {
108 const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
109
110 // Only exit if needed
111 process.on('exit', () => {
112 if (typeof code === 'number' && code !== 0) {
113 process.exitCode = code;
114 }
115 });
116
117 if (globalConfig.forceExit) {
118 if (!globalConfig.detectOpenHandles) {
119 console.warn(
120 `${chalk.bold(
121 'Force exiting Jest: ',
122 )}Have you considered using \`--detectOpenHandles\` to detect ` +
123 'async operations that kept running after all tests finished?',
124 );
125 }
126
127 exit(code);
128 } else if (
129 !globalConfig.detectOpenHandles &&
130 globalConfig.openHandlesTimeout !== 0
131 ) {
132 const timeout = globalConfig.openHandlesTimeout;
133 setTimeout(() => {
134 console.warn(
135 chalk.yellow.bold(
136 `Jest did not exit ${
137 timeout === 1000 ? 'one second' : `${timeout / 1000} seconds`
138 } after the test run has completed.\n\n'`,
139 ) +
140 chalk.yellow(
141 'This usually means that there are asynchronous operations that ' +
142 "weren't stopped in your tests. Consider running Jest with " +
143 '`--detectOpenHandles` to troubleshoot this issue.',
144 ),
145 );
146 }, timeout).unref();
147 }
148};

Callers 1

runFunction · 0.85

Calls 3

exitFunction · 0.85
onMethod · 0.65
warnMethod · 0.45

Tested by

no test coverage detected