1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | function _chalk() {
|
9 | const data = _interopRequireDefault(require('chalk'));
|
10 |
|
11 | _chalk = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _stringLength() {
|
19 | const data = _interopRequireDefault(require('string-length'));
|
20 |
|
21 | _stringLength = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | var _getSummary = _interopRequireDefault(require('./getSummary'));
|
29 |
|
30 | var _printDisplayName = _interopRequireDefault(require('./printDisplayName'));
|
31 |
|
32 | var _trimAndFormatPath = _interopRequireDefault(require('./trimAndFormatPath'));
|
33 |
|
34 | var _wrapAnsiString = _interopRequireDefault(require('./wrapAnsiString'));
|
35 |
|
36 | function _interopRequireDefault(obj) {
|
37 | return obj && obj.__esModule ? obj : {default: obj};
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | const RUNNING_TEXT = ' RUNS ';
|
47 | const RUNNING = `${_chalk().default.reset.inverse.yellow.bold(RUNNING_TEXT)} `;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | class CurrentTestList {
|
55 | _array;
|
56 |
|
57 | constructor() {
|
58 | this._array = [];
|
59 | }
|
60 |
|
61 | add(testPath, config) {
|
62 | const index = this._array.indexOf(null);
|
63 |
|
64 | const record = {
|
65 | config,
|
66 | testPath
|
67 | };
|
68 |
|
69 | if (index !== -1) {
|
70 | this._array[index] = record;
|
71 | } else {
|
72 | this._array.push(record);
|
73 | }
|
74 | }
|
75 |
|
76 | delete(testPath) {
|
77 | const record = this._array.find(
|
78 | record => record !== null && record.testPath === testPath
|
79 | );
|
80 |
|
81 | this._array[this._array.indexOf(record || null)] = null;
|
82 | }
|
83 |
|
84 | get() {
|
85 | return this._array;
|
86 | }
|
87 | }
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | class Status {
|
95 | _cache;
|
96 | _callback;
|
97 | _currentTests;
|
98 | _currentTestCases;
|
99 | _done;
|
100 | _emitScheduled;
|
101 | _estimatedTime;
|
102 | _interval;
|
103 | _aggregatedResults;
|
104 | _showStatus;
|
105 |
|
106 | constructor() {
|
107 | this._cache = null;
|
108 | this._currentTests = new CurrentTestList();
|
109 | this._currentTestCases = [];
|
110 | this._done = false;
|
111 | this._emitScheduled = false;
|
112 | this._estimatedTime = 0;
|
113 | this._showStatus = false;
|
114 | }
|
115 |
|
116 | onChange(callback) {
|
117 | this._callback = callback;
|
118 | }
|
119 |
|
120 | runStarted(aggregatedResults, options) {
|
121 | this._estimatedTime = (options && options.estimatedTime) || 0;
|
122 | this._showStatus = options && options.showStatus;
|
123 | this._interval = setInterval(() => this._tick(), 1000);
|
124 | this._aggregatedResults = aggregatedResults;
|
125 |
|
126 | this._debouncedEmit();
|
127 | }
|
128 |
|
129 | runFinished() {
|
130 | this._done = true;
|
131 | if (this._interval) clearInterval(this._interval);
|
132 |
|
133 | this._emit();
|
134 | }
|
135 |
|
136 | addTestCaseResult(test, testCaseResult) {
|
137 | this._currentTestCases.push({
|
138 | test,
|
139 | testCaseResult
|
140 | });
|
141 |
|
142 | if (!this._showStatus) {
|
143 | this._emit();
|
144 | } else {
|
145 | this._debouncedEmit();
|
146 | }
|
147 | }
|
148 |
|
149 | testStarted(testPath, config) {
|
150 | this._currentTests.add(testPath, config);
|
151 |
|
152 | if (!this._showStatus) {
|
153 | this._emit();
|
154 | } else {
|
155 | this._debouncedEmit();
|
156 | }
|
157 | }
|
158 |
|
159 | testFinished(_config, testResult, aggregatedResults) {
|
160 | const {testFilePath} = testResult;
|
161 | this._aggregatedResults = aggregatedResults;
|
162 |
|
163 | this._currentTests.delete(testFilePath);
|
164 |
|
165 | this._currentTestCases = this._currentTestCases.filter(({test}) => {
|
166 | if (_config !== test.context.config) {
|
167 | return true;
|
168 | }
|
169 |
|
170 | return test.path !== testFilePath;
|
171 | });
|
172 |
|
173 | this._debouncedEmit();
|
174 | }
|
175 |
|
176 | get() {
|
177 | if (this._cache) {
|
178 | return this._cache;
|
179 | }
|
180 |
|
181 | if (this._done) {
|
182 | return {
|
183 | clear: '',
|
184 | content: ''
|
185 | };
|
186 | }
|
187 |
|
188 | const width = process.stdout.columns;
|
189 | let content = '\n';
|
190 |
|
191 | this._currentTests.get().forEach(record => {
|
192 | if (record) {
|
193 | const {config, testPath} = record;
|
194 | const projectDisplayName = config.displayName
|
195 | ? `${(0, _printDisplayName.default)(config)} `
|
196 | : '';
|
197 | const prefix = RUNNING + projectDisplayName;
|
198 | content += `${(0, _wrapAnsiString.default)(
|
199 | prefix +
|
200 | (0, _trimAndFormatPath.default)(
|
201 | (0, _stringLength().default)(prefix),
|
202 | config,
|
203 | testPath,
|
204 | width
|
205 | ),
|
206 | width
|
207 | )}\n`;
|
208 | }
|
209 | });
|
210 |
|
211 | if (this._showStatus && this._aggregatedResults) {
|
212 | content += `\n${(0, _getSummary.default)(this._aggregatedResults, {
|
213 | currentTestCases: this._currentTestCases,
|
214 | estimatedTime: this._estimatedTime,
|
215 | roundTime: true,
|
216 | width
|
217 | })}`;
|
218 | }
|
219 |
|
220 | let height = 0;
|
221 |
|
222 | for (let i = 0; i < content.length; i++) {
|
223 | if (content[i] === '\n') {
|
224 | height++;
|
225 | }
|
226 | }
|
227 |
|
228 | const clear = '\r\x1B[K\r\x1B[1A'.repeat(height);
|
229 | return (this._cache = {
|
230 | clear,
|
231 | content
|
232 | });
|
233 | }
|
234 |
|
235 | _emit() {
|
236 | this._cache = null;
|
237 | if (this._callback) this._callback();
|
238 | }
|
239 |
|
240 | _debouncedEmit() {
|
241 | if (!this._emitScheduled) {
|
242 |
|
243 |
|
244 | this._emitScheduled = true;
|
245 | setTimeout(() => {
|
246 | this._emit();
|
247 |
|
248 | this._emitScheduled = false;
|
249 | }, 100);
|
250 | }
|
251 | }
|
252 |
|
253 | _tick() {
|
254 | this._debouncedEmit();
|
255 | }
|
256 | }
|
257 |
|
258 | exports.default = Status;
|