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