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

Method onRunComplete

packages/jest-reporters/src/NotifyReporter.ts:34–155  ·  view source on GitHub ↗
(
    testContexts: Set<TestContext>,
    result: AggregatedResult,
  )

Source from the content-addressed store, hash-verified

32 }
33
34 override onRunComplete(
35 testContexts: Set<TestContext>,
36 result: AggregatedResult,
37 ): void {
38 const success =
39 result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0;
40
41 const firstContext = testContexts.values().next();
42
43 const hasteFS =
44 firstContext && firstContext.value && firstContext.value.hasteFS;
45
46 let packageName;
47 if (hasteFS == null) {
48 packageName = this._globalConfig.rootDir;
49 } else {
50 // assuming root package.json is the first one
51 const [filePath] = hasteFS.matchFiles('package.json');
52
53 packageName =
54 filePath == null
55 ? this._globalConfig.rootDir
56 : hasteFS.getModuleName(filePath);
57 }
58
59 packageName = packageName == null ? '' : `${packageName} - `;
60
61 const notifyMode = this._globalConfig.notifyMode;
62 const statusChanged =
63 this._context.previousSuccess !== success || this._context.firstRun;
64 const testsHaveRun = result.numTotalTests !== 0;
65
66 if (
67 testsHaveRun &&
68 success &&
69 (notifyMode === 'always' ||
70 notifyMode === 'success' ||
71 notifyMode === 'success-change' ||
72 (notifyMode === 'change' && statusChanged) ||
73 (notifyMode === 'failure-change' && statusChanged))
74 ) {
75 const title = util.format('%s%d%% Passed', packageName, 100);
76 const message = `${isDarwin ? '\u2705 ' : ''}${pluralize(
77 'test',
78 result.numPassedTests,
79 )} passed`;
80
81 this._notifier.notify({
82 hint: 'int:transient:1',
83 icon,
84 message,
85 timeout: false,
86 title,
87 });
88 } else if (
89 testsHaveRun &&
90 !success &&
91 (notifyMode === 'always' ||

Callers 1

testModesFunction · 0.95

Calls 4

pluralizeFunction · 0.90
exitFunction · 0.85
matchFilesMethod · 0.65
getModuleNameMethod · 0.65

Tested by 1

testModesFunction · 0.76