UNPKG

4.78 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.createEmptyTestResult =
7 exports.addResult =
8 exports.buildFailureTestResult =
9 exports.makeEmptyAggregatedTestResult =
10 void 0;
11
12/**
13 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
14 *
15 * This source code is licensed under the MIT license found in the
16 * LICENSE file in the root directory of this source tree.
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});
53
54exports.makeEmptyAggregatedTestResult = makeEmptyAggregatedTestResult;
55
56const buildFailureTestResult = (testPath, err) => ({
57 console: undefined,
58 displayName: undefined,
59 failureMessage: null,
60 leaks: false,
61 numFailingTests: 0,
62 numPassingTests: 0,
63 numPendingTests: 0,
64 numTodoTests: 0,
65 openHandles: [],
66 perfStats: {
67 end: 0,
68 runtime: 0,
69 slow: false,
70 start: 0
71 },
72 skipped: false,
73 snapshot: {
74 added: 0,
75 fileDeleted: false,
76 matched: 0,
77 unchecked: 0,
78 uncheckedKeys: [],
79 unmatched: 0,
80 updated: 0
81 },
82 testExecError: err,
83 testFilePath: testPath,
84 testResults: []
85}); // Add individual test result to an aggregated test result
86
87exports.buildFailureTestResult = buildFailureTestResult;
88
89const addResult = (aggregatedResults, testResult) => {
90 // `todos` are new as of Jest 24, and not all runners return it.
91 // Set it to `0` to avoid `NaN`
92 if (!testResult.numTodoTests) {
93 testResult.numTodoTests = 0;
94 }
95
96 aggregatedResults.testResults.push(testResult);
97 aggregatedResults.numTotalTests +=
98 testResult.numPassingTests +
99 testResult.numFailingTests +
100 testResult.numPendingTests +
101 testResult.numTodoTests;
102 aggregatedResults.numFailedTests += testResult.numFailingTests;
103 aggregatedResults.numPassedTests += testResult.numPassingTests;
104 aggregatedResults.numPendingTests += testResult.numPendingTests;
105 aggregatedResults.numTodoTests += testResult.numTodoTests;
106
107 if (testResult.testExecError) {
108 aggregatedResults.numRuntimeErrorTestSuites++;
109 }
110
111 if (testResult.skipped) {
112 aggregatedResults.numPendingTestSuites++;
113 } else if (testResult.numFailingTests > 0 || testResult.testExecError) {
114 aggregatedResults.numFailedTestSuites++;
115 } else {
116 aggregatedResults.numPassedTestSuites++;
117 } // Snapshot data
118
119 if (testResult.snapshot.added) {
120 aggregatedResults.snapshot.filesAdded++;
121 }
122
123 if (testResult.snapshot.fileDeleted) {
124 aggregatedResults.snapshot.filesRemoved++;
125 }
126
127 if (testResult.snapshot.unmatched) {
128 aggregatedResults.snapshot.filesUnmatched++;
129 }
130
131 if (testResult.snapshot.updated) {
132 aggregatedResults.snapshot.filesUpdated++;
133 }
134
135 aggregatedResults.snapshot.added += testResult.snapshot.added;
136 aggregatedResults.snapshot.matched += testResult.snapshot.matched;
137 aggregatedResults.snapshot.unchecked += testResult.snapshot.unchecked;
138
139 if (
140 testResult.snapshot.uncheckedKeys &&
141 testResult.snapshot.uncheckedKeys.length > 0
142 ) {
143 aggregatedResults.snapshot.uncheckedKeysByFile.push({
144 filePath: testResult.testFilePath,
145 keys: testResult.snapshot.uncheckedKeys
146 });
147 }
148
149 aggregatedResults.snapshot.unmatched += testResult.snapshot.unmatched;
150 aggregatedResults.snapshot.updated += testResult.snapshot.updated;
151 aggregatedResults.snapshot.total +=
152 testResult.snapshot.added +
153 testResult.snapshot.matched +
154 testResult.snapshot.unmatched +
155 testResult.snapshot.updated;
156};
157
158exports.addResult = addResult;
159
160const createEmptyTestResult = () => ({
161 leaks: false,
162 // That's legacy code, just adding it as needed for typing
163 numFailingTests: 0,
164 numPassingTests: 0,
165 numPendingTests: 0,
166 numTodoTests: 0,
167 openHandles: [],
168 perfStats: {
169 end: 0,
170 runtime: 0,
171 slow: false,
172 start: 0
173 },
174 skipped: false,
175 snapshot: {
176 added: 0,
177 fileDeleted: false,
178 matched: 0,
179 unchecked: 0,
180 uncheckedKeys: [],
181 unmatched: 0,
182 updated: 0
183 },
184 testFilePath: '',
185 testResults: []
186});
187
188exports.createEmptyTestResult = createEmptyTestResult;