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

Method onResult

packages/jest-core/src/TestScheduler.ts:139–183  ·  view source on GitHub ↗
(test: Test, testResult: TestResult)

Source from the content-addressed store, hash-verified

137 const runInBand = shouldRunInBand(tests, timings, this._globalConfig);
138
139 const onResult = async (test: Test, testResult: TestResult) => {
140 if (watcher.isInterrupted()) {
141 return;
142 }
143
144 if (testResult.testResults.length === 0) {
145 const message = 'Your test suite must contain at least one test.';
146
147 return onFailure(test, {
148 message,
149 stack: new Error(message).stack,
150 });
151 }
152
153 // Throws when the context is leaked after executing a test.
154 if (testResult.leaks) {
155 const message =
156 `${chalk.red.bold(
157 'EXPERIMENTAL FEATURE!\n',
158 )}Your test suite is leaking memory. Please ensure all references are cleaned.\n` +
159 '\n' +
160 'There is a number of things that can leak memory:\n' +
161 ' - Async operations that have not finished (e.g. fs.readFile).\n' +
162 ' - Timers not properly mocked (e.g. setInterval, setTimeout).\n' +
163 ' - Keeping references to the global scope.';
164
165 return onFailure(test, {
166 message,
167 stack: new Error(message).stack,
168 });
169 }
170
171 addResult(aggregatedResults, testResult);
172 await this._dispatcher.onTestFileResult(
173 test,
174 testResult,
175 aggregatedResults,
176 );
177 return this._bailIfNeeded(
178 testContexts,
179 aggregatedResults,
180 watcher,
181 tests,
182 );
183 };
184
185 const onFailure = async (test: Test, error: SerializableError) => {
186 if (watcher.isInterrupted()) {

Callers

nothing calls this directly

Calls 4

_bailIfNeededMethod · 0.95
addResultFunction · 0.90
isInterruptedMethod · 0.80
onTestFileResultMethod · 0.45

Tested by

no test coverage detected