ava 3.7.1 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +18 -1
- package/lib/api.js +9 -2
- package/lib/assert.js +62 -6
- package/lib/cli.js +28 -15
- package/lib/code-excerpt.js +1 -1
- package/lib/concordance-options.js +0 -1
- package/lib/fork.js +3 -1
- package/lib/globs.js +17 -13
- package/lib/like-selector.js +37 -0
- package/lib/line-numbers.js +64 -0
- package/lib/load-config.js +1 -1
- package/lib/reporters/beautify-stack.js +73 -0
- package/lib/reporters/colors.js +1 -0
- package/lib/reporters/default.js +834 -0
- package/lib/reporters/tap.js +3 -2
- package/lib/run-status.js +8 -2
- package/lib/runner.js +21 -3
- package/lib/serialize-error.js +30 -17
- package/lib/test.js +43 -1
- package/lib/watcher.js +4 -1
- package/lib/worker/line-numbers.js +90 -0
- package/lib/worker/subprocess.js +21 -6
- package/package.json +27 -72
- package/readme.md +1 -1
- package/lib/beautify-stack.js +0 -75
- package/lib/reporters/mini.js +0 -573
- package/lib/reporters/verbose.js +0 -440
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const stream = require('stream');
|
|
5
|
+
|
|
6
|
+
const cliCursor = require('cli-cursor');
|
|
7
|
+
const figures = require('figures');
|
|
8
|
+
const indentString = require('indent-string');
|
|
9
|
+
const ora = require('ora');
|
|
10
|
+
const plur = require('plur');
|
|
11
|
+
const prettyMs = require('pretty-ms');
|
|
12
|
+
const trimOffNewlines = require('trim-off-newlines');
|
|
13
|
+
|
|
14
|
+
const chalk = require('../chalk').get();
|
|
15
|
+
const codeExcerpt = require('../code-excerpt');
|
|
16
|
+
const beautifyStack = require('./beautify-stack');
|
|
17
|
+
const colors = require('./colors');
|
|
18
|
+
const formatSerializedError = require('./format-serialized-error');
|
|
19
|
+
const improperUsageMessages = require('./improper-usage-messages');
|
|
20
|
+
const prefixTitle = require('./prefix-title');
|
|
21
|
+
const whileCorked = require('./while-corked');
|
|
22
|
+
|
|
23
|
+
const nodeInternals = require('stack-utils').nodeInternals();
|
|
24
|
+
|
|
25
|
+
class LineWriter extends stream.Writable {
|
|
26
|
+
constructor(dest) {
|
|
27
|
+
super();
|
|
28
|
+
|
|
29
|
+
this.dest = dest;
|
|
30
|
+
this.columns = dest.columns || 80;
|
|
31
|
+
this.lastLineIsEmpty = false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_write(chunk, _, callback) {
|
|
35
|
+
this.dest.write(chunk);
|
|
36
|
+
callback();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
writeLine(string) {
|
|
40
|
+
if (string) {
|
|
41
|
+
this.write(indentString(string, 2) + os.EOL);
|
|
42
|
+
this.lastLineIsEmpty = false;
|
|
43
|
+
} else {
|
|
44
|
+
this.write(os.EOL);
|
|
45
|
+
this.lastLineIsEmpty = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
ensureEmptyLine() {
|
|
50
|
+
if (!this.lastLineIsEmpty) {
|
|
51
|
+
this.writeLine();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class LineWriterWithSpinner extends LineWriter {
|
|
57
|
+
constructor(dest, spinner) {
|
|
58
|
+
super(dest);
|
|
59
|
+
|
|
60
|
+
this.lastSpinnerText = '';
|
|
61
|
+
this.spinner = spinner;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_write(chunk, _, callback) {
|
|
65
|
+
this.spinner.clear();
|
|
66
|
+
this._writeWithSpinner(chunk.toString('utf8'));
|
|
67
|
+
|
|
68
|
+
callback();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_writev(pieces, callback) {
|
|
72
|
+
// Discard the current spinner output. Any lines that were meant to be
|
|
73
|
+
// preserved should be rewritten.
|
|
74
|
+
this.spinner.clear();
|
|
75
|
+
|
|
76
|
+
const last = pieces.pop();
|
|
77
|
+
for (const piece of pieces) {
|
|
78
|
+
this.dest.write(piece.chunk);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this._writeWithSpinner(last.chunk.toString('utf8'));
|
|
82
|
+
callback();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_writeWithSpinner(string) {
|
|
86
|
+
if (!this.spinner.isSpinning) {
|
|
87
|
+
this.dest.write(string);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.lastSpinnerText = string;
|
|
92
|
+
// Ignore whitespace at the end of the chunk. We're continiously rewriting
|
|
93
|
+
// the last line through the spinner. Also be careful to remove the indent
|
|
94
|
+
// as the spinner adds its own.
|
|
95
|
+
this.spinner.text = string.trimEnd().slice(2);
|
|
96
|
+
this.spinner.render();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class Reporter {
|
|
101
|
+
constructor({
|
|
102
|
+
verbose,
|
|
103
|
+
reportStream,
|
|
104
|
+
stdStream,
|
|
105
|
+
projectDir,
|
|
106
|
+
watching,
|
|
107
|
+
spinner,
|
|
108
|
+
durationThreshold
|
|
109
|
+
}) {
|
|
110
|
+
this.verbose = verbose;
|
|
111
|
+
this.reportStream = reportStream;
|
|
112
|
+
this.stdStream = stdStream;
|
|
113
|
+
this.watching = watching;
|
|
114
|
+
this.relativeFile = file => path.relative(projectDir, file);
|
|
115
|
+
this.consumeStateChange = whileCorked(this.reportStream, this.consumeStateChange);
|
|
116
|
+
|
|
117
|
+
if (this.verbose) {
|
|
118
|
+
this.durationThreshold = durationThreshold || 100;
|
|
119
|
+
this.spinner = null;
|
|
120
|
+
this.lineWriter = new LineWriter(this.reportStream);
|
|
121
|
+
this.endRun = whileCorked(this.reportStream, this.endRun);
|
|
122
|
+
} else {
|
|
123
|
+
this.spinner = ora({
|
|
124
|
+
isEnabled: true,
|
|
125
|
+
color: spinner ? spinner.color : 'gray',
|
|
126
|
+
discardStdin: !watching,
|
|
127
|
+
hideCursor: false,
|
|
128
|
+
spinner: spinner || (process.platform === 'win32' ? 'line' : 'dots'),
|
|
129
|
+
stream: reportStream
|
|
130
|
+
});
|
|
131
|
+
this.lineWriter = new LineWriterWithSpinner(this.reportStream, this.spinner);
|
|
132
|
+
this.endRun = whileCorked(this.reportStream, whileCorked(this.lineWriter, this.endRun));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.reset();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
reset() {
|
|
139
|
+
if (this.removePreviousListener) {
|
|
140
|
+
this.removePreviousListener();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.prefixTitle = (testFile, title) => title;
|
|
144
|
+
|
|
145
|
+
this.runningTestFiles = new Map();
|
|
146
|
+
this.filesWithMissingAvaImports = new Set();
|
|
147
|
+
this.filesWithoutDeclaredTests = new Set();
|
|
148
|
+
this.filesWithoutMatchedLineNumbers = new Set();
|
|
149
|
+
|
|
150
|
+
this.failures = [];
|
|
151
|
+
this.internalErrors = [];
|
|
152
|
+
this.knownFailures = [];
|
|
153
|
+
this.lineNumberErrors = [];
|
|
154
|
+
this.uncaughtExceptions = [];
|
|
155
|
+
this.unhandledRejections = [];
|
|
156
|
+
|
|
157
|
+
this.previousFailures = 0;
|
|
158
|
+
|
|
159
|
+
this.failFastEnabled = false;
|
|
160
|
+
this.lastLineIsEmpty = false;
|
|
161
|
+
this.matching = false;
|
|
162
|
+
|
|
163
|
+
this.removePreviousListener = null;
|
|
164
|
+
this.stats = null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
startRun(plan) {
|
|
168
|
+
if (plan.bailWithoutReporting) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this.reset();
|
|
173
|
+
|
|
174
|
+
this.failFastEnabled = plan.failFastEnabled;
|
|
175
|
+
this.matching = plan.matching;
|
|
176
|
+
this.previousFailures = plan.previousFailures;
|
|
177
|
+
this.emptyParallelRun = plan.status.emptyParallelRun;
|
|
178
|
+
|
|
179
|
+
if (this.watching || plan.files.length > 1) {
|
|
180
|
+
this.prefixTitle = (testFile, title) => prefixTitle(plan.filePathPrefix, testFile, title);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
this.removePreviousListener = plan.status.on('stateChange', evt => {
|
|
184
|
+
this.consumeStateChange(evt);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
if (this.watching && plan.runVector > 1) {
|
|
188
|
+
this.lineWriter.write(chalk.gray.dim('\u2500'.repeat(this.lineWriter.columns)) + os.EOL);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (this.spinner === null) {
|
|
192
|
+
this.lineWriter.writeLine();
|
|
193
|
+
} else {
|
|
194
|
+
cliCursor.hide(this.reportStream);
|
|
195
|
+
this.lineWriter.writeLine();
|
|
196
|
+
this.spinner.start();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
consumeStateChange(event) { // eslint-disable-line complexity
|
|
201
|
+
const fileStats = this.stats && event.testFile ? this.stats.byFile.get(event.testFile) : null;
|
|
202
|
+
|
|
203
|
+
switch (event.type) { // eslint-disable-line default-case
|
|
204
|
+
case 'hook-failed': {
|
|
205
|
+
this.failures.push(event);
|
|
206
|
+
this.writeTestSummary(event);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
case 'stats': {
|
|
211
|
+
this.stats = event.stats;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
case 'test-failed': {
|
|
216
|
+
this.failures.push(event);
|
|
217
|
+
this.writeTestSummary(event);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
case 'test-passed': {
|
|
222
|
+
if (event.knownFailing) {
|
|
223
|
+
this.knownFailures.push(event);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this.writeTestSummary(event);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
case 'timeout': {
|
|
231
|
+
this.lineWriter.writeLine(colors.error(`\n${figures.cross} Timed out while running tests`));
|
|
232
|
+
this.lineWriter.writeLine('');
|
|
233
|
+
this.writePendingTests(event);
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
case 'interrupt': {
|
|
238
|
+
this.lineWriter.writeLine(colors.error(`\n${figures.cross} Exiting due to SIGINT`));
|
|
239
|
+
this.lineWriter.writeLine('');
|
|
240
|
+
this.writePendingTests(event);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
case 'internal-error': {
|
|
245
|
+
this.internalErrors.push(event);
|
|
246
|
+
|
|
247
|
+
if (event.testFile) {
|
|
248
|
+
this.write(colors.error(`${figures.cross} Internal error when running ${this.relativeFile(event.testFile)}`));
|
|
249
|
+
} else {
|
|
250
|
+
this.write(colors.error(`${figures.cross} Internal error`));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (this.verbose) {
|
|
254
|
+
this.lineWriter.writeLine(colors.stack(event.err.summary));
|
|
255
|
+
this.lineWriter.writeLine(colors.errorStack(event.err.stack));
|
|
256
|
+
this.lineWriter.writeLine();
|
|
257
|
+
this.lineWriter.writeLine();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
case 'line-number-selection-error': {
|
|
264
|
+
this.lineNumberErrors.push(event);
|
|
265
|
+
|
|
266
|
+
this.write(colors.information(`${figures.warning} Could not parse ${this.relativeFile(event.testFile)} for line number selection`));
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
case 'missing-ava-import': {
|
|
271
|
+
this.filesWithMissingAvaImports.add(event.testFile);
|
|
272
|
+
|
|
273
|
+
this.write(colors.error(`${figures.cross} No tests found in ${this.relativeFile(event.testFile)}, make sure to import "ava" at the top of your test file`));
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
case 'hook-finished': {
|
|
278
|
+
if (this.verbose && event.logs.length > 0) {
|
|
279
|
+
this.lineWriter.writeLine(` ${this.prefixTitle(event.testFile, event.title)}`);
|
|
280
|
+
this.writeLogs(event);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
case 'selected-test': {
|
|
287
|
+
if (this.verbose) {
|
|
288
|
+
if (event.skip) {
|
|
289
|
+
this.lineWriter.writeLine(colors.skip(`- ${this.prefixTitle(event.testFile, event.title)}`));
|
|
290
|
+
} else if (event.todo) {
|
|
291
|
+
this.lineWriter.writeLine(colors.todo(`- ${this.prefixTitle(event.testFile, event.title)}`));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
case 'uncaught-exception': {
|
|
299
|
+
this.uncaughtExceptions.push(event);
|
|
300
|
+
|
|
301
|
+
if (this.verbose) {
|
|
302
|
+
this.lineWriter.ensureEmptyLine();
|
|
303
|
+
this.lineWriter.writeLine(colors.title(`Uncaught exception in ${this.relativeFile(event.testFile)}`));
|
|
304
|
+
this.lineWriter.writeLine();
|
|
305
|
+
this.writeErr(event);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
case 'unhandled-rejection': {
|
|
312
|
+
this.unhandledRejections.push(event);
|
|
313
|
+
|
|
314
|
+
if (this.verbose) {
|
|
315
|
+
this.lineWriter.ensureEmptyLine();
|
|
316
|
+
this.lineWriter.writeLine(colors.title(`Unhandled rejection in ${this.relativeFile(event.testFile)}`));
|
|
317
|
+
this.lineWriter.writeLine();
|
|
318
|
+
this.writeErr(event);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
case 'worker-failed': {
|
|
325
|
+
if (fileStats.declaredTests === 0) {
|
|
326
|
+
this.filesWithoutDeclaredTests.add(event.testFile);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (this.verbose && !this.filesWithMissingAvaImports.has(event.testFile)) {
|
|
330
|
+
if (event.nonZeroExitCode) {
|
|
331
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} ${this.relativeFile(event.testFile)} exited with a non-zero exit code: ${event.nonZeroExitCode}`));
|
|
332
|
+
} else {
|
|
333
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} ${this.relativeFile(event.testFile)} exited due to ${event.signal}`));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
case 'worker-finished': {
|
|
341
|
+
if (!event.forcedExit && !this.filesWithMissingAvaImports.has(event.testFile)) {
|
|
342
|
+
if (fileStats.declaredTests === 0) {
|
|
343
|
+
this.filesWithoutDeclaredTests.add(event.testFile);
|
|
344
|
+
|
|
345
|
+
this.write(colors.error(`${figures.cross} No tests found in ${this.relativeFile(event.testFile)}`));
|
|
346
|
+
} else if (fileStats.selectingLines && fileStats.selectedTests === 0) {
|
|
347
|
+
this.filesWithoutMatchedLineNumbers.add(event.testFile);
|
|
348
|
+
|
|
349
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} Line numbers for ${this.relativeFile(event.testFile)} did not match any tests`));
|
|
350
|
+
} else if (this.verbose && !this.failFastEnabled && fileStats.remainingTests > 0) {
|
|
351
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} ${fileStats.remainingTests} ${plur('test', fileStats.remainingTests)} remaining in ${this.relativeFile(event.testFile)}`));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
case 'worker-stderr': {
|
|
359
|
+
// Forcibly clear the spinner, writing the chunk corrupts the TTY.
|
|
360
|
+
if (this.spinner !== null) {
|
|
361
|
+
this.spinner.clear();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
this.stdStream.write(event.chunk);
|
|
365
|
+
// If the chunk does not end with a linebreak, *forcibly* write one to
|
|
366
|
+
// ensure it remains visible in the TTY.
|
|
367
|
+
// Tests cannot assume their standard output is not interrupted. Indeed
|
|
368
|
+
// we multiplex stdout and stderr into a single stream. However as
|
|
369
|
+
// long as stdStream is different from reportStream users can read
|
|
370
|
+
// their original output by redirecting the streams.
|
|
371
|
+
if (event.chunk[event.chunk.length - 1] !== 0x0A) {
|
|
372
|
+
this.reportStream.write(os.EOL);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (this.spinner !== null) {
|
|
376
|
+
this.lineWriter.write(this.lineWriter.lastSpinnerText);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
case 'worker-stdout': {
|
|
383
|
+
// Forcibly clear the spinner, writing the chunk corrupts the TTY.
|
|
384
|
+
if (this.spinner !== null) {
|
|
385
|
+
this.spinner.clear();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
this.stdStream.write(event.chunk);
|
|
389
|
+
// If the chunk does not end with a linebreak, *forcibly* write one to
|
|
390
|
+
// ensure it remains visible in the TTY.
|
|
391
|
+
// Tests cannot assume their standard output is not interrupted. Indeed
|
|
392
|
+
// we multiplex stdout and stderr into a single stream. However as
|
|
393
|
+
// long as stdStream is different from reportStream users can read
|
|
394
|
+
// their original output by redirecting the streams.
|
|
395
|
+
if (event.chunk[event.chunk.length - 1] !== 0x0A) {
|
|
396
|
+
this.reportStream.write(os.EOL);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (this.spinner !== null) {
|
|
400
|
+
this.lineWriter.write(this.lineWriter.lastSpinnerText);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
writePendingTests(evt) {
|
|
407
|
+
for (const [file, testsInFile] of evt.pendingTests) {
|
|
408
|
+
if (testsInFile.size === 0) {
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
this.lineWriter.writeLine(`${testsInFile.size} tests were pending in ${this.relativeFile(file)}\n`);
|
|
413
|
+
for (const title of testsInFile) {
|
|
414
|
+
this.lineWriter.writeLine(`${figures.circleDotted} ${this.prefixTitle(file, title)}`);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
this.lineWriter.writeLine('');
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
write(string) {
|
|
422
|
+
if (this.verbose) {
|
|
423
|
+
this.lineWriter.writeLine(string);
|
|
424
|
+
} else {
|
|
425
|
+
this.writeWithCounts(string);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
writeWithCounts(string) {
|
|
430
|
+
if (!this.stats) {
|
|
431
|
+
return this.lineWriter.writeLine(string);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
string = string || '';
|
|
435
|
+
if (string !== '') {
|
|
436
|
+
string += os.EOL;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
let firstLinePostfix = this.watching ? ' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']') : '';
|
|
440
|
+
|
|
441
|
+
if (this.stats.passedTests > 0) {
|
|
442
|
+
string += os.EOL + colors.pass(`${this.stats.passedTests} passed`) + firstLinePostfix;
|
|
443
|
+
firstLinePostfix = '';
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (this.stats.passedKnownFailingTests > 0) {
|
|
447
|
+
string += os.EOL + colors.error(`${this.stats.passedKnownFailingTests} ${plur('known failure', this.stats.passedKnownFailingTests)}`);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (this.stats.failedHooks > 0) {
|
|
451
|
+
string += os.EOL + colors.error(`${this.stats.failedHooks} ${plur('hook', this.stats.failedHooks)} failed`) + firstLinePostfix;
|
|
452
|
+
firstLinePostfix = '';
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (this.stats.failedTests > 0) {
|
|
456
|
+
string += os.EOL + colors.error(`${this.stats.failedTests} ${plur('test', this.stats.failedTests)} failed`) + firstLinePostfix;
|
|
457
|
+
firstLinePostfix = '';
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (this.stats.skippedTests > 0) {
|
|
461
|
+
string += os.EOL + colors.skip(`${this.stats.skippedTests} skipped`);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (this.stats.todoTests > 0) {
|
|
465
|
+
string += os.EOL + colors.todo(`${this.stats.todoTests} todo`);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
this.lineWriter.writeLine(string);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
writeErr(event) {
|
|
472
|
+
if (event.err.name === 'TSError' && event.err.object && event.err.object.diagnosticText) {
|
|
473
|
+
this.lineWriter.writeLine(colors.errorStack(trimOffNewlines(event.err.object.diagnosticText)));
|
|
474
|
+
this.lineWriter.writeLine();
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (event.err.source) {
|
|
479
|
+
this.lineWriter.writeLine(colors.errorSource(`${this.relativeFile(event.err.source.file)}:${event.err.source.line}`));
|
|
480
|
+
const excerpt = codeExcerpt(event.err.source, {maxWidth: this.reportStream.columns - 2});
|
|
481
|
+
if (excerpt) {
|
|
482
|
+
this.lineWriter.writeLine();
|
|
483
|
+
this.lineWriter.writeLine(excerpt);
|
|
484
|
+
this.lineWriter.writeLine();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (event.err.avaAssertionError) {
|
|
489
|
+
const result = formatSerializedError(event.err);
|
|
490
|
+
if (result.printMessage) {
|
|
491
|
+
this.lineWriter.writeLine(event.err.message);
|
|
492
|
+
this.lineWriter.writeLine();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
if (result.formatted) {
|
|
496
|
+
this.lineWriter.writeLine(result.formatted);
|
|
497
|
+
this.lineWriter.writeLine();
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const message = improperUsageMessages.forError(event.err);
|
|
501
|
+
if (message) {
|
|
502
|
+
this.lineWriter.writeLine(message);
|
|
503
|
+
this.lineWriter.writeLine();
|
|
504
|
+
}
|
|
505
|
+
} else if (event.err.nonErrorObject) {
|
|
506
|
+
this.lineWriter.writeLine(trimOffNewlines(event.err.formatted));
|
|
507
|
+
this.lineWriter.writeLine();
|
|
508
|
+
} else {
|
|
509
|
+
this.lineWriter.writeLine(event.err.summary);
|
|
510
|
+
this.lineWriter.writeLine();
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const formatted = this.formatErrorStack(event.err);
|
|
514
|
+
if (formatted.length > 0) {
|
|
515
|
+
this.lineWriter.writeLine(formatted.join('\n'));
|
|
516
|
+
this.lineWriter.writeLine();
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
formatErrorStack(error) {
|
|
521
|
+
if (!error.stack) {
|
|
522
|
+
return [];
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if (error.shouldBeautifyStack) {
|
|
526
|
+
return beautifyStack(error.stack).map(line => {
|
|
527
|
+
if (nodeInternals.some(internal => internal.test(line))) {
|
|
528
|
+
return colors.errorStackInternal(`${figures.pointerSmall} ${line}`);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return colors.errorStack(`${figures.pointerSmall} ${line}`);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return [error.stack];
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
writeLogs(event, surroundLines) {
|
|
539
|
+
if (event.logs && event.logs.length > 0) {
|
|
540
|
+
if (surroundLines) {
|
|
541
|
+
this.lineWriter.writeLine();
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
for (const log of event.logs) {
|
|
545
|
+
const logLines = indentString(colors.log(log), 4);
|
|
546
|
+
const logLinesWithLeadingFigure = logLines.replace(/^ {4}/, ` ${colors.information(figures.info)} `);
|
|
547
|
+
this.lineWriter.writeLine(logLinesWithLeadingFigure);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (surroundLines) {
|
|
551
|
+
this.lineWriter.writeLine();
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
writeTestSummary(event) {
|
|
561
|
+
if (event.type === 'hook-failed' || event.type === 'test-failed') {
|
|
562
|
+
if (this.verbose) {
|
|
563
|
+
this.write(`${colors.error(figures.cross)} ${this.prefixTitle(event.testFile, event.title)} ${colors.error(event.err.message)}`);
|
|
564
|
+
} else {
|
|
565
|
+
this.write(this.prefixTitle(event.testFile, event.title));
|
|
566
|
+
}
|
|
567
|
+
} else if (event.knownFailing) {
|
|
568
|
+
if (this.verbose) {
|
|
569
|
+
this.write(`${colors.error(figures.tick)} ${colors.error(this.prefixTitle(event.testFile, event.title))}`);
|
|
570
|
+
} else {
|
|
571
|
+
this.write(colors.error(this.prefixTitle(event.testFile, event.title)));
|
|
572
|
+
}
|
|
573
|
+
} else if (this.verbose) {
|
|
574
|
+
const duration = event.duration > this.durationThreshold ? colors.duration(' (' + prettyMs(event.duration) + ')') : '';
|
|
575
|
+
this.write(`${colors.pass(figures.tick)} ${this.prefixTitle(event.testFile, event.title)}${duration}`);
|
|
576
|
+
} else {
|
|
577
|
+
this.write(this.prefixTitle(event.testFile, event.title));
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (this.verbose) {
|
|
581
|
+
this.writeLogs(event);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
writeFailure(event) {
|
|
586
|
+
this.lineWriter.writeLine(colors.title(this.prefixTitle(event.testFile, event.title)));
|
|
587
|
+
if (!this.writeLogs(event, true)) {
|
|
588
|
+
this.lineWriter.writeLine();
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
this.writeErr(event);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
endRun() {// eslint-disable-line complexity
|
|
595
|
+
let firstLinePostfix = this.watching ? ` ${chalk.gray.dim(`[${new Date().toLocaleTimeString('en-US', {hour12: false})}]`)}` : '';
|
|
596
|
+
let wroteSomething = false;
|
|
597
|
+
|
|
598
|
+
if (!this.verbose) {
|
|
599
|
+
this.spinner.stop();
|
|
600
|
+
cliCursor.show(this.reportStream);
|
|
601
|
+
} else if (this.emptyParallelRun) {
|
|
602
|
+
this.lineWriter.writeLine('No files tested in this parallel run');
|
|
603
|
+
this.lineWriter.writeLine();
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
if (!this.stats) {
|
|
608
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any files to test` + firstLinePostfix));
|
|
609
|
+
this.lineWriter.writeLine();
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (this.matching && this.stats.selectedTests === 0) {
|
|
614
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any matching tests` + firstLinePostfix));
|
|
615
|
+
this.lineWriter.writeLine();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (this.verbose) {
|
|
620
|
+
this.lineWriter.writeLine(colors.log(figures.line));
|
|
621
|
+
this.lineWriter.writeLine();
|
|
622
|
+
} else {
|
|
623
|
+
if (this.filesWithMissingAvaImports.size > 0) {
|
|
624
|
+
for (const testFile of this.filesWithMissingAvaImports) {
|
|
625
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} No tests found in ${this.relativeFile(testFile)}, make sure to import "ava" at the top of your test file`) + firstLinePostfix);
|
|
626
|
+
firstLinePostfix = '';
|
|
627
|
+
wroteSomething = true;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
if (this.filesWithoutDeclaredTests.size > 0) {
|
|
632
|
+
for (const testFile of this.filesWithoutDeclaredTests) {
|
|
633
|
+
if (!this.filesWithMissingAvaImports.has(testFile)) {
|
|
634
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} No tests found in ${this.relativeFile(testFile)}`) + firstLinePostfix);
|
|
635
|
+
firstLinePostfix = '';
|
|
636
|
+
wroteSomething = true;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (this.lineNumberErrors.length > 0) {
|
|
642
|
+
for (const event of this.lineNumberErrors) {
|
|
643
|
+
this.lineWriter.writeLine(colors.information(`${figures.warning} Could not parse ${this.relativeFile(event.testFile)} for line number selection` + firstLinePostfix));
|
|
644
|
+
firstLinePostfix = '';
|
|
645
|
+
wroteSomething = true;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
if (this.filesWithoutMatchedLineNumbers.size > 0) {
|
|
650
|
+
for (const testFile of this.filesWithoutMatchedLineNumbers) {
|
|
651
|
+
if (!this.filesWithMissingAvaImports.has(testFile) && !this.filesWithoutDeclaredTests.has(testFile)) {
|
|
652
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} Line numbers for ${this.relativeFile(testFile)} did not match any tests`) + firstLinePostfix);
|
|
653
|
+
firstLinePostfix = '';
|
|
654
|
+
wroteSomething = true;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
if (wroteSomething) {
|
|
660
|
+
this.lineWriter.writeLine();
|
|
661
|
+
this.lineWriter.writeLine(colors.log(figures.line));
|
|
662
|
+
this.lineWriter.writeLine();
|
|
663
|
+
wroteSomething = false;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (this.failures.length > 0) {
|
|
668
|
+
const writeTrailingLines = this.internalErrors.length > 0 || this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;
|
|
669
|
+
|
|
670
|
+
const lastFailure = this.failures[this.failures.length - 1];
|
|
671
|
+
for (const event of this.failures) {
|
|
672
|
+
this.writeFailure(event);
|
|
673
|
+
if (event !== lastFailure) {
|
|
674
|
+
this.lineWriter.writeLine();
|
|
675
|
+
this.lineWriter.writeLine();
|
|
676
|
+
} else if (!this.verbose && writeTrailingLines) {
|
|
677
|
+
this.lineWriter.writeLine();
|
|
678
|
+
this.lineWriter.writeLine();
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
wroteSomething = true;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
if (this.verbose) {
|
|
685
|
+
this.lineWriter.writeLine(colors.log(figures.line));
|
|
686
|
+
this.lineWriter.writeLine();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
if (!this.verbose) {
|
|
691
|
+
if (this.internalErrors.length > 0) {
|
|
692
|
+
const writeTrailingLines = this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;
|
|
693
|
+
|
|
694
|
+
const last = this.internalErrors[this.internalErrors.length - 1];
|
|
695
|
+
for (const event of this.internalErrors) {
|
|
696
|
+
if (event.testFile) {
|
|
697
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} Internal error when running ${this.relativeFile(event.testFile)}`));
|
|
698
|
+
} else {
|
|
699
|
+
this.lineWriter.writeLine(colors.error(`${figures.cross} Internal error`));
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
this.lineWriter.writeLine(colors.stack(event.err.summary));
|
|
703
|
+
this.lineWriter.writeLine(colors.errorStack(event.err.stack));
|
|
704
|
+
if (event !== last || writeTrailingLines) {
|
|
705
|
+
this.lineWriter.writeLine();
|
|
706
|
+
this.lineWriter.writeLine();
|
|
707
|
+
this.lineWriter.writeLine();
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
wroteSomething = true;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
if (this.uncaughtExceptions.length > 0) {
|
|
715
|
+
const writeTrailingLines = this.unhandledRejections.length > 0;
|
|
716
|
+
|
|
717
|
+
const last = this.uncaughtExceptions[this.uncaughtExceptions.length - 1];
|
|
718
|
+
for (const event of this.uncaughtExceptions) {
|
|
719
|
+
this.lineWriter.writeLine(colors.title(`Uncaught exception in ${this.relativeFile(event.testFile)}`));
|
|
720
|
+
this.lineWriter.writeLine();
|
|
721
|
+
this.writeErr(event);
|
|
722
|
+
if (event !== last || writeTrailingLines) {
|
|
723
|
+
this.lineWriter.writeLine();
|
|
724
|
+
this.lineWriter.writeLine();
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
wroteSomething = true;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
if (this.unhandledRejections.length > 0) {
|
|
732
|
+
const last = this.unhandledRejections[this.unhandledRejections.length - 1];
|
|
733
|
+
for (const event of this.unhandledRejections) {
|
|
734
|
+
this.lineWriter.writeLine(colors.title(`Unhandled rejection in ${this.relativeFile(event.testFile)}`));
|
|
735
|
+
this.lineWriter.writeLine();
|
|
736
|
+
this.writeErr(event);
|
|
737
|
+
if (event !== last) {
|
|
738
|
+
this.lineWriter.writeLine();
|
|
739
|
+
this.lineWriter.writeLine();
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
wroteSomething = true;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
if (wroteSomething) {
|
|
747
|
+
this.lineWriter.writeLine(colors.log(figures.line));
|
|
748
|
+
this.lineWriter.writeLine();
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (this.failFastEnabled && (this.stats.remainingTests > 0 || this.stats.files > this.stats.finishedWorkers)) {
|
|
753
|
+
let remaining = '';
|
|
754
|
+
if (this.stats.remainingTests > 0) {
|
|
755
|
+
remaining += `At least ${this.stats.remainingTests} ${plur('test was', 'tests were', this.stats.remainingTests)} skipped`;
|
|
756
|
+
if (this.stats.files > this.stats.finishedWorkers) {
|
|
757
|
+
remaining += ', as well as ';
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (this.stats.files > this.stats.finishedWorkers) {
|
|
762
|
+
const skippedFileCount = this.stats.files - this.stats.finishedWorkers;
|
|
763
|
+
remaining += `${skippedFileCount} ${plur('test file', 'test files', skippedFileCount)}`;
|
|
764
|
+
if (this.stats.remainingTests === 0) {
|
|
765
|
+
remaining += ` ${plur('was', 'were', skippedFileCount)} skipped`;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
this.lineWriter.writeLine(colors.information(`\`--fail-fast\` is on. ${remaining}.`));
|
|
770
|
+
if (this.verbose) {
|
|
771
|
+
this.lineWriter.writeLine();
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
if (this.verbose && this.stats.parallelRuns) {
|
|
776
|
+
const {
|
|
777
|
+
currentFileCount,
|
|
778
|
+
currentIndex,
|
|
779
|
+
totalRuns
|
|
780
|
+
} = this.stats.parallelRuns;
|
|
781
|
+
this.lineWriter.writeLine(colors.information(`Ran ${currentFileCount} test ${plur('file', currentFileCount)} out of ${this.stats.files} for job ${currentIndex + 1} of ${totalRuns}`));
|
|
782
|
+
this.lineWriter.writeLine();
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
if (this.stats.failedHooks > 0) {
|
|
786
|
+
this.lineWriter.writeLine(colors.error(`${this.stats.failedHooks} ${plur('hook', this.stats.failedHooks)} failed`) + firstLinePostfix);
|
|
787
|
+
firstLinePostfix = '';
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
if (this.stats.failedTests > 0) {
|
|
791
|
+
this.lineWriter.writeLine(colors.error(`${this.stats.failedTests} ${plur('test', this.stats.failedTests)} failed`) + firstLinePostfix);
|
|
792
|
+
firstLinePostfix = '';
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (
|
|
796
|
+
this.stats.failedHooks === 0 &&
|
|
797
|
+
this.stats.failedTests === 0 &&
|
|
798
|
+
this.stats.passedTests > 0
|
|
799
|
+
) {
|
|
800
|
+
this.lineWriter.writeLine(colors.pass(`${this.stats.passedTests} ${plur('test', this.stats.passedTests)} passed`) + firstLinePostfix
|
|
801
|
+
);
|
|
802
|
+
firstLinePostfix = '';
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (this.stats.passedKnownFailingTests > 0) {
|
|
806
|
+
this.lineWriter.writeLine(colors.error(`${this.stats.passedKnownFailingTests} ${plur('known failure', this.stats.passedKnownFailingTests)}`));
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (this.stats.skippedTests > 0) {
|
|
810
|
+
this.lineWriter.writeLine(colors.skip(`${this.stats.skippedTests} ${plur('test', this.stats.skippedTests)} skipped`));
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (this.stats.todoTests > 0) {
|
|
814
|
+
this.lineWriter.writeLine(colors.todo(`${this.stats.todoTests} ${plur('test', this.stats.todoTests)} todo`));
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (this.stats.unhandledRejections > 0) {
|
|
818
|
+
this.lineWriter.writeLine(colors.error(`${this.stats.unhandledRejections} unhandled ${plur('rejection', this.stats.unhandledRejections)}`));
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
if (this.stats.uncaughtExceptions > 0) {
|
|
822
|
+
this.lineWriter.writeLine(colors.error(`${this.stats.uncaughtExceptions} uncaught ${plur('exception', this.stats.uncaughtExceptions)}`));
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
if (this.previousFailures > 0) {
|
|
826
|
+
this.lineWriter.writeLine(colors.error(`${this.previousFailures} previous ${plur('failure', this.previousFailures)} in test files that were not rerun`));
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
if (this.watching) {
|
|
830
|
+
this.lineWriter.writeLine();
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
module.exports = Reporter;
|