1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.PROGRESS_BAR_WIDTH = void 0;
|
7 | exports.default = getSummary;
|
8 |
|
9 | function _chalk() {
|
10 | const data = _interopRequireDefault(require('chalk'));
|
11 |
|
12 | _chalk = function () {
|
13 | return data;
|
14 | };
|
15 |
|
16 | return data;
|
17 | }
|
18 |
|
19 | function _jestUtil() {
|
20 | const data = require('jest-util');
|
21 |
|
22 | _jestUtil = function () {
|
23 | return data;
|
24 | };
|
25 |
|
26 | return data;
|
27 | }
|
28 |
|
29 | function _interopRequireDefault(obj) {
|
30 | return obj && obj.__esModule ? obj : {default: obj};
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const PROGRESS_BAR_WIDTH = 40;
|
40 | exports.PROGRESS_BAR_WIDTH = PROGRESS_BAR_WIDTH;
|
41 |
|
42 | function getValuesCurrentTestCases(currentTestCases = []) {
|
43 | let numFailingTests = 0;
|
44 | let numPassingTests = 0;
|
45 | let numPendingTests = 0;
|
46 | let numTodoTests = 0;
|
47 | let numTotalTests = 0;
|
48 | currentTestCases.forEach(testCase => {
|
49 | switch (testCase.testCaseResult.status) {
|
50 | case 'failed': {
|
51 | numFailingTests++;
|
52 | break;
|
53 | }
|
54 |
|
55 | case 'passed': {
|
56 | numPassingTests++;
|
57 | break;
|
58 | }
|
59 |
|
60 | case 'skipped': {
|
61 | numPendingTests++;
|
62 | break;
|
63 | }
|
64 |
|
65 | case 'todo': {
|
66 | numTodoTests++;
|
67 | break;
|
68 | }
|
69 | }
|
70 |
|
71 | numTotalTests++;
|
72 | });
|
73 | return {
|
74 | numFailingTests,
|
75 | numPassingTests,
|
76 | numPendingTests,
|
77 | numTodoTests,
|
78 | numTotalTests
|
79 | };
|
80 | }
|
81 |
|
82 | function renderTime(runTime, estimatedTime, width) {
|
83 |
|
84 | const renderedTime =
|
85 | estimatedTime && runTime >= estimatedTime + 1
|
86 | ? _chalk().default.bold.yellow((0, _jestUtil().formatTime)(runTime, 0))
|
87 | : (0, _jestUtil().formatTime)(runTime, 0);
|
88 | let time = `${_chalk().default.bold('Time:')} ${renderedTime}`;
|
89 |
|
90 | if (runTime < estimatedTime) {
|
91 | time += `, estimated ${(0, _jestUtil().formatTime)(estimatedTime, 0)}`;
|
92 | }
|
93 |
|
94 |
|
95 | if (estimatedTime > 2 && runTime < estimatedTime && width) {
|
96 | const availableWidth = Math.min(PROGRESS_BAR_WIDTH, width);
|
97 | const length = Math.min(
|
98 | Math.floor((runTime / estimatedTime) * availableWidth),
|
99 | availableWidth
|
100 | );
|
101 |
|
102 | if (availableWidth >= 2) {
|
103 | time += `\n${_chalk().default.green('█').repeat(length)}${_chalk()
|
104 | .default.white('█')
|
105 | .repeat(availableWidth - length)}`;
|
106 | }
|
107 | }
|
108 |
|
109 | return time;
|
110 | }
|
111 |
|
112 | function getSummary(aggregatedResults, options) {
|
113 | let runTime = (Date.now() - aggregatedResults.startTime) / 1000;
|
114 |
|
115 | if (options && options.roundTime) {
|
116 | runTime = Math.floor(runTime);
|
117 | }
|
118 |
|
119 | const valuesForCurrentTestCases = getValuesCurrentTestCases(
|
120 | options === null || options === void 0 ? void 0 : options.currentTestCases
|
121 | );
|
122 | const estimatedTime = (options && options.estimatedTime) || 0;
|
123 | const snapshotResults = aggregatedResults.snapshot;
|
124 | const snapshotsAdded = snapshotResults.added;
|
125 | const snapshotsFailed = snapshotResults.unmatched;
|
126 | const snapshotsOutdated = snapshotResults.unchecked;
|
127 | const snapshotsFilesRemoved = snapshotResults.filesRemoved;
|
128 | const snapshotsDidUpdate = snapshotResults.didUpdate;
|
129 | const snapshotsPassed = snapshotResults.matched;
|
130 | const snapshotsTotal = snapshotResults.total;
|
131 | const snapshotsUpdated = snapshotResults.updated;
|
132 | const suitesFailed = aggregatedResults.numFailedTestSuites;
|
133 | const suitesPassed = aggregatedResults.numPassedTestSuites;
|
134 | const suitesPending = aggregatedResults.numPendingTestSuites;
|
135 | const suitesRun = suitesFailed + suitesPassed;
|
136 | const suitesTotal = aggregatedResults.numTotalTestSuites;
|
137 | const testsFailed = aggregatedResults.numFailedTests;
|
138 | const testsPassed = aggregatedResults.numPassedTests;
|
139 | const testsPending = aggregatedResults.numPendingTests;
|
140 | const testsTodo = aggregatedResults.numTodoTests;
|
141 | const testsTotal = aggregatedResults.numTotalTests;
|
142 | const width = (options && options.width) || 0;
|
143 | const suites = `${
|
144 | _chalk().default.bold('Test Suites: ') +
|
145 | (suitesFailed
|
146 | ? `${_chalk().default.bold.red(`${suitesFailed} failed`)}, `
|
147 | : '') +
|
148 | (suitesPending
|
149 | ? `${_chalk().default.bold.yellow(`${suitesPending} skipped`)}, `
|
150 | : '') +
|
151 | (suitesPassed
|
152 | ? `${_chalk().default.bold.green(`${suitesPassed} passed`)}, `
|
153 | : '') +
|
154 | (suitesRun !== suitesTotal ? `${suitesRun} of ${suitesTotal}` : suitesTotal)
|
155 | } total`;
|
156 | const updatedTestsFailed =
|
157 | testsFailed + valuesForCurrentTestCases.numFailingTests;
|
158 | const updatedTestsPending =
|
159 | testsPending + valuesForCurrentTestCases.numPendingTests;
|
160 | const updatedTestsTodo = testsTodo + valuesForCurrentTestCases.numTodoTests;
|
161 | const updatedTestsPassed =
|
162 | testsPassed + valuesForCurrentTestCases.numPassingTests;
|
163 | const updatedTestsTotal =
|
164 | testsTotal + valuesForCurrentTestCases.numTotalTests;
|
165 | const tests = `${
|
166 | _chalk().default.bold('Tests: ') +
|
167 | (updatedTestsFailed > 0
|
168 | ? `${_chalk().default.bold.red(`${updatedTestsFailed} failed`)}, `
|
169 | : '') +
|
170 | (updatedTestsPending > 0
|
171 | ? `${_chalk().default.bold.yellow(`${updatedTestsPending} skipped`)}, `
|
172 | : '') +
|
173 | (updatedTestsTodo > 0
|
174 | ? `${_chalk().default.bold.magenta(`${updatedTestsTodo} todo`)}, `
|
175 | : '') +
|
176 | (updatedTestsPassed > 0
|
177 | ? `${_chalk().default.bold.green(`${updatedTestsPassed} passed`)}, `
|
178 | : '')
|
179 | }${updatedTestsTotal} total`;
|
180 | const snapshots = `${
|
181 | _chalk().default.bold('Snapshots: ') +
|
182 | (snapshotsFailed
|
183 | ? `${_chalk().default.bold.red(`${snapshotsFailed} failed`)}, `
|
184 | : '') +
|
185 | (snapshotsOutdated && !snapshotsDidUpdate
|
186 | ? `${_chalk().default.bold.yellow(`${snapshotsOutdated} obsolete`)}, `
|
187 | : '') +
|
188 | (snapshotsOutdated && snapshotsDidUpdate
|
189 | ? `${_chalk().default.bold.green(`${snapshotsOutdated} removed`)}, `
|
190 | : '') +
|
191 | (snapshotsFilesRemoved && !snapshotsDidUpdate
|
192 | ? `${_chalk().default.bold.yellow(
|
193 | `${(0, _jestUtil().pluralize)(
|
194 | 'file',
|
195 | snapshotsFilesRemoved
|
196 | )} obsolete`
|
197 | )}, `
|
198 | : '') +
|
199 | (snapshotsFilesRemoved && snapshotsDidUpdate
|
200 | ? `${_chalk().default.bold.green(
|
201 | `${(0, _jestUtil().pluralize)('file', snapshotsFilesRemoved)} removed`
|
202 | )}, `
|
203 | : '') +
|
204 | (snapshotsUpdated
|
205 | ? `${_chalk().default.bold.green(`${snapshotsUpdated} updated`)}, `
|
206 | : '') +
|
207 | (snapshotsAdded
|
208 | ? `${_chalk().default.bold.green(`${snapshotsAdded} written`)}, `
|
209 | : '') +
|
210 | (snapshotsPassed
|
211 | ? `${_chalk().default.bold.green(`${snapshotsPassed} passed`)}, `
|
212 | : '')
|
213 | }${snapshotsTotal} total`;
|
214 | const time = renderTime(runTime, estimatedTime, width);
|
215 | return [suites, tests, snapshots, time].join('\n');
|
216 | }
|