UNPKG

4.76 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.makeEmptyAggregatedTestResult =
7 exports.createEmptyTestResult =
8 exports.buildFailureTestResult =
9 exports.addResult =
10 void 0;
11/**
12 * Copyright (c) Meta Platforms, Inc. and affiliates.
13 *
14 * This source code is licensed under the MIT license found in the
15 * LICENSE file in the root directory of this source tree.
16 */
17
18const makeEmptyAggregatedTestResult = () => ({
19 numFailedTestSuites: 0,
20 numFailedTests: 0,
21 numPassedTestSuites: 0,
22 numPassedTests: 0,
23 numPendingTestSuites: 0,
24 numPendingTests: 0,
25 numRuntimeErrorTestSuites: 0,
26 numTodoTests: 0,
27 numTotalTestSuites: 0,
28 numTotalTests: 0,
29 openHandles: [],
30 snapshot: {
31 added: 0,
32 didUpdate: false,
33 // is set only after the full run
34 failure: false,
35 filesAdded: 0,
36 // combines individual test results + removed files after the full run
37 filesRemoved: 0,
38 filesRemovedList: [],
39 filesUnmatched: 0,
40 filesUpdated: 0,
41 matched: 0,
42 total: 0,
43 unchecked: 0,
44 uncheckedKeysByFile: [],
45 unmatched: 0,
46 updated: 0
47 },
48 startTime: 0,
49 success: true,
50 testResults: [],
51 wasInterrupted: false
52});
53exports.makeEmptyAggregatedTestResult = makeEmptyAggregatedTestResult;
54const buildFailureTestResult = (testPath, err) => ({
55 console: undefined,
56 displayName: undefined,
57 failureMessage: null,
58 leaks: false,
59 numFailingTests: 0,
60 numPassingTests: 0,
61 numPendingTests: 0,
62 numTodoTests: 0,
63 openHandles: [],
64 perfStats: {
65 end: 0,
66 runtime: 0,
67 slow: false,
68 start: 0
69 },
70 skipped: false,
71 snapshot: {
72 added: 0,
73 fileDeleted: false,
74 matched: 0,
75 unchecked: 0,
76 uncheckedKeys: [],
77 unmatched: 0,
78 updated: 0
79 },
80 testExecError: err,
81 testFilePath: testPath,
82 testResults: []
83});
84
85// Add individual test result to an aggregated test result
86exports.buildFailureTestResult = buildFailureTestResult;
87const addResult = (aggregatedResults, testResult) => {
88 // `todos` are new as of Jest 24, and not all runners return it.
89 // Set it to `0` to avoid `NaN`
90 if (!testResult.numTodoTests) {
91 testResult.numTodoTests = 0;
92 }
93 aggregatedResults.testResults.push(testResult);
94 aggregatedResults.numTotalTests +=
95 testResult.numPassingTests +
96 testResult.numFailingTests +
97 testResult.numPendingTests +
98 testResult.numTodoTests;
99 aggregatedResults.numFailedTests += testResult.numFailingTests;
100 aggregatedResults.numPassedTests += testResult.numPassingTests;
101 aggregatedResults.numPendingTests += testResult.numPendingTests;
102 aggregatedResults.numTodoTests += testResult.numTodoTests;
103 if (testResult.testExecError) {
104 aggregatedResults.numRuntimeErrorTestSuites++;
105 }
106 if (testResult.skipped) {
107 aggregatedResults.numPendingTestSuites++;
108 } else if (testResult.numFailingTests > 0 || testResult.testExecError) {
109 aggregatedResults.numFailedTestSuites++;
110 } else {
111 aggregatedResults.numPassedTestSuites++;
112 }
113
114 // Snapshot data
115 if (testResult.snapshot.added) {
116 aggregatedResults.snapshot.filesAdded++;
117 }
118 if (testResult.snapshot.fileDeleted) {
119 aggregatedResults.snapshot.filesRemoved++;
120 }
121 if (testResult.snapshot.unmatched) {
122 aggregatedResults.snapshot.filesUnmatched++;
123 }
124 if (testResult.snapshot.updated) {
125 aggregatedResults.snapshot.filesUpdated++;
126 }
127 aggregatedResults.snapshot.added += testResult.snapshot.added;
128 aggregatedResults.snapshot.matched += testResult.snapshot.matched;
129 aggregatedResults.snapshot.unchecked += testResult.snapshot.unchecked;
130 if (
131 testResult.snapshot.uncheckedKeys != null &&
132 testResult.snapshot.uncheckedKeys.length > 0
133 ) {
134 aggregatedResults.snapshot.uncheckedKeysByFile.push({
135 filePath: testResult.testFilePath,
136 keys: testResult.snapshot.uncheckedKeys
137 });
138 }
139 aggregatedResults.snapshot.unmatched += testResult.snapshot.unmatched;
140 aggregatedResults.snapshot.updated += testResult.snapshot.updated;
141 aggregatedResults.snapshot.total +=
142 testResult.snapshot.added +
143 testResult.snapshot.matched +
144 testResult.snapshot.unmatched +
145 testResult.snapshot.updated;
146};
147exports.addResult = addResult;
148const createEmptyTestResult = () => ({
149 leaks: false,
150 // That's legacy code, just adding it as needed for typing
151 numFailingTests: 0,
152 numPassingTests: 0,
153 numPendingTests: 0,
154 numTodoTests: 0,
155 openHandles: [],
156 perfStats: {
157 end: 0,
158 runtime: 0,
159 slow: false,
160 start: 0
161 },
162 skipped: false,
163 snapshot: {
164 added: 0,
165 fileDeleted: false,
166 matched: 0,
167 unchecked: 0,
168 uncheckedKeys: [],
169 unmatched: 0,
170 updated: 0
171 },
172 testFilePath: '',
173 testResults: []
174});
175exports.createEmptyTestResult = createEmptyTestResult;