Skip to content

Commit baaf99a

Browse files
m5x5novemberborn
andauthored
Reporter improvements
* Always show stats last * Don't print known failing tests after stats * Tweak empty lines and separators Co-authored-by: Mark Wubben <mark@novemberborn.net>
1 parent dace976 commit baaf99a

File tree

62 files changed

+371
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+371
-384
lines changed

lib/reporters/mini.js

Lines changed: 102 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ class MiniReporter {
299299
writeErr(evt) {
300300
if (evt.err.name === 'TSError' && evt.err.object && evt.err.object.diagnosticText) {
301301
this.lineWriter.writeLine(colors.errorStack(trimOffNewlines(evt.err.object.diagnosticText)));
302+
this.lineWriter.writeLine();
302303
return;
303304
}
304305

@@ -308,37 +309,39 @@ class MiniReporter {
308309
if (excerpt) {
309310
this.lineWriter.writeLine();
310311
this.lineWriter.writeLine(excerpt);
312+
this.lineWriter.writeLine();
311313
}
312314
}
313315

314316
if (evt.err.avaAssertionError) {
315317
const result = formatSerializedError(evt.err);
316318
if (result.printMessage) {
317-
this.lineWriter.writeLine();
318319
this.lineWriter.writeLine(evt.err.message);
320+
this.lineWriter.writeLine();
319321
}
320322

321323
if (result.formatted) {
322-
this.lineWriter.writeLine();
323324
this.lineWriter.writeLine(result.formatted);
325+
this.lineWriter.writeLine();
324326
}
325327

326328
const message = improperUsageMessages.forError(evt.err);
327329
if (message) {
328-
this.lineWriter.writeLine();
329330
this.lineWriter.writeLine(message);
331+
this.lineWriter.writeLine();
330332
}
331333
} else if (evt.err.nonErrorObject) {
332334
this.lineWriter.writeLine(trimOffNewlines(evt.err.formatted));
333-
} else {
334335
this.lineWriter.writeLine();
336+
} else {
335337
this.lineWriter.writeLine(evt.err.summary);
338+
this.lineWriter.writeLine();
336339
}
337340

338341
const formatted = this.formatErrorStack(evt.err);
339342
if (formatted.length > 0) {
340-
this.lineWriter.writeLine();
341343
this.lineWriter.writeLine(formatted.join('\n'));
344+
this.lineWriter.writeLine();
342345
}
343346
}
344347

@@ -360,8 +363,12 @@ class MiniReporter {
360363
return [error.stack];
361364
}
362365

363-
writeLogs(evt) {
364-
if (evt.logs) {
366+
writeLogs(evt, surroundLines) {
367+
if (evt.logs && evt.logs.length > 0) {
368+
if (surroundLines) {
369+
this.lineWriter.writeLine();
370+
}
371+
365372
for (const log of evt.logs) {
366373
const logLines = indentString(colors.log(log), 4);
367374
const logLinesWithLeadingFigure = logLines.replace(
@@ -370,7 +377,15 @@ class MiniReporter {
370377
);
371378
this.lineWriter.writeLine(logLinesWithLeadingFigure);
372379
}
380+
381+
if (surroundLines) {
382+
this.lineWriter.writeLine();
383+
}
384+
385+
return true;
373386
}
387+
388+
return false;
374389
}
375390

376391
writeTestSummary(evt) {
@@ -385,8 +400,10 @@ class MiniReporter {
385400

386401
writeFailure(evt) {
387402
this.lineWriter.writeLine(`${colors.title(this.prefixTitle(evt.testFile, evt.title))}`);
388-
this.writeLogs(evt);
389-
this.lineWriter.writeLine();
403+
if (!this.writeLogs(evt, true)) {
404+
this.lineWriter.writeLine();
405+
}
406+
390407
this.writeErr(evt);
391408
}
392409

@@ -409,28 +426,28 @@ class MiniReporter {
409426
this.spinner.stop();
410427
cliCursor.show(this.reportStream);
411428

429+
let firstLinePostfix = this.watching ?
430+
' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']') :
431+
'';
432+
412433
if (!this.stats) {
413-
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any files to test`));
434+
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any files to test` + firstLinePostfix));
414435
this.lineWriter.writeLine();
415436
return;
416437
}
417438

418439
if (this.matching && this.stats.selectedTests === 0) {
419-
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any matching tests`));
440+
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any matching tests` + firstLinePostfix));
420441
this.lineWriter.writeLine();
421442
return;
422443
}
423444

424-
this.lineWriter.writeLine();
425-
426-
let firstLinePostfix = this.watching ?
427-
' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']') :
428-
'';
429-
445+
let wroteSomething = false;
430446
if (this.filesWithMissingAvaImports.size > 0) {
431447
for (const testFile of this.filesWithMissingAvaImports) {
432448
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);
433449
firstLinePostfix = '';
450+
wroteSomething = true;
434451
}
435452
}
436453

@@ -439,13 +456,16 @@ class MiniReporter {
439456
if (!this.filesWithMissingAvaImports.has(testFile)) {
440457
this.lineWriter.writeLine(colors.error(`${figures.cross} No tests found in ${this.relativeFile(testFile)}`) + firstLinePostfix);
441458
firstLinePostfix = '';
459+
wroteSomething = true;
442460
}
443461
}
444462
}
445463

446464
if (this.lineNumberErrors.length > 0) {
447465
for (const evt of this.lineNumberErrors) {
448-
this.lineWriter.writeLine(colors.information(`${figures.warning} Could not parse ${this.relativeFile(evt.testFile)} for line number selection`));
466+
this.lineWriter.writeLine(colors.information(`${figures.warning} Could not parse ${this.relativeFile(evt.testFile)} for line number selection` + firstLinePostfix));
467+
firstLinePostfix = '';
468+
wroteSomething = true;
449469
}
450470
}
451471

@@ -454,84 +474,35 @@ class MiniReporter {
454474
if (!this.filesWithMissingAvaImports.has(testFile) && !this.filesWithoutDeclaredTests.has(testFile)) {
455475
this.lineWriter.writeLine(colors.error(`${figures.cross} Line numbers for ${this.relativeFile(testFile)} did not match any tests`) + firstLinePostfix);
456476
firstLinePostfix = '';
477+
wroteSomething = true;
457478
}
458479
}
459480
}
460481

461-
if (this.filesWithMissingAvaImports.size > 0 || this.filesWithoutDeclaredTests.size > 0 || this.filesWithoutMatchedLineNumbers.size > 0) {
482+
if (wroteSomething) {
462483
this.lineWriter.writeLine();
463-
}
464-
465-
if (this.stats.failedHooks > 0) {
466-
this.lineWriter.writeLine(colors.error(`${this.stats.failedHooks} ${plur('hook', this.stats.failedHooks)} failed`) + firstLinePostfix);
467-
firstLinePostfix = '';
468-
}
469-
470-
if (this.stats.failedTests > 0) {
471-
this.lineWriter.writeLine(colors.error(`${this.stats.failedTests} ${plur('test', this.stats.failedTests)} failed`) + firstLinePostfix);
472-
firstLinePostfix = '';
473-
}
474-
475-
if (this.stats.failedHooks === 0 && this.stats.failedTests === 0 && this.stats.passedTests > 0) {
476-
this.lineWriter.writeLine(colors.pass(`${this.stats.passedTests} ${plur('test', this.stats.passedTests)} passed`) + firstLinePostfix);
477-
firstLinePostfix = '';
478-
}
479-
480-
if (this.stats.passedKnownFailingTests > 0) {
481-
this.lineWriter.writeLine(colors.error(`${this.stats.passedKnownFailingTests} ${plur('known failure', this.stats.passedKnownFailingTests)}`));
482-
}
483-
484-
if (this.stats.skippedTests > 0) {
485-
this.lineWriter.writeLine(colors.skip(`${this.stats.skippedTests} ${plur('test', this.stats.skippedTests)} skipped`));
486-
}
487-
488-
if (this.stats.todoTests > 0) {
489-
this.lineWriter.writeLine(colors.todo(`${this.stats.todoTests} ${plur('test', this.stats.todoTests)} todo`));
490-
}
491-
492-
if (this.stats.unhandledRejections > 0) {
493-
this.lineWriter.writeLine(colors.error(`${this.stats.unhandledRejections} unhandled ${plur('rejection', this.stats.unhandledRejections)}`));
494-
}
495-
496-
if (this.stats.uncaughtExceptions > 0) {
497-
this.lineWriter.writeLine(colors.error(`${this.stats.uncaughtExceptions} uncaught ${plur('exception', this.stats.uncaughtExceptions)}`));
498-
}
499-
500-
if (this.previousFailures > 0) {
501-
this.lineWriter.writeLine(colors.error(`${this.previousFailures} previous ${plur('failure', this.previousFailures)} in test files that were not rerun`));
502-
}
503-
504-
if (this.stats.passedKnownFailingTests > 0) {
484+
this.lineWriter.writeLine(colors.log(figures.line));
505485
this.lineWriter.writeLine();
506-
for (const evt of this.knownFailures) {
507-
this.lineWriter.writeLine(colors.error(this.prefixTitle(evt.testFile, evt.title)));
508-
}
486+
wroteSomething = false;
509487
}
510488

511-
const shouldWriteFailFastDisclaimer = this.failFastEnabled && (this.stats.remainingTests > 0 || this.stats.files > this.stats.finishedWorkers);
512-
513489
if (this.failures.length > 0) {
514-
const writeTrailingLines = shouldWriteFailFastDisclaimer || this.internalErrors.length > 0 || this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;
515-
this.lineWriter.writeLine();
490+
const writeTrailingLines = this.internalErrors.length > 0 || this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;
516491

517492
const last = this.failures[this.failures.length - 1];
518493
for (const evt of this.failures) {
519494
this.writeFailure(evt);
520495
if (evt !== last || writeTrailingLines) {
521496
this.lineWriter.writeLine();
522497
this.lineWriter.writeLine();
523-
this.lineWriter.writeLine();
524498
}
499+
500+
wroteSomething = true;
525501
}
526502
}
527503

528504
if (this.internalErrors.length > 0) {
529-
const writeLeadingLine = this.failures.length === 0;
530-
const writeTrailingLines = shouldWriteFailFastDisclaimer || this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;
531-
532-
if (writeLeadingLine) {
533-
this.lineWriter.writeLine();
534-
}
505+
const writeTrailingLines = this.uncaughtExceptions.length > 0 || this.unhandledRejections.length > 0;
535506

536507
const last = this.internalErrors[this.internalErrors.length - 1];
537508
for (const evt of this.internalErrors) {
@@ -548,16 +519,13 @@ class MiniReporter {
548519
this.lineWriter.writeLine();
549520
this.lineWriter.writeLine();
550521
}
522+
523+
wroteSomething = true;
551524
}
552525
}
553526

554527
if (this.uncaughtExceptions.length > 0) {
555-
const writeLeadingLine = this.failures.length === 0 && this.internalErrors.length === 0;
556-
const writeTrailingLines = shouldWriteFailFastDisclaimer || this.unhandledRejections.length > 0;
557-
558-
if (writeLeadingLine) {
559-
this.lineWriter.writeLine();
560-
}
528+
const writeTrailingLines = this.unhandledRejections.length > 0;
561529

562530
const last = this.uncaughtExceptions[this.uncaughtExceptions.length - 1];
563531
for (const evt of this.uncaughtExceptions) {
@@ -567,33 +535,33 @@ class MiniReporter {
567535
if (evt !== last || writeTrailingLines) {
568536
this.lineWriter.writeLine();
569537
this.lineWriter.writeLine();
570-
this.lineWriter.writeLine();
571538
}
539+
540+
wroteSomething = true;
572541
}
573542
}
574543

575544
if (this.unhandledRejections.length > 0) {
576-
const writeLeadingLine = this.failures.length === 0 && this.internalErrors.length === 0 && this.uncaughtExceptions.length === 0;
577-
const writeTrailingLines = shouldWriteFailFastDisclaimer;
578-
579-
if (writeLeadingLine) {
580-
this.lineWriter.writeLine();
581-
}
582-
583545
const last = this.unhandledRejections[this.unhandledRejections.length - 1];
584546
for (const evt of this.unhandledRejections) {
585547
this.lineWriter.writeLine(colors.title(`Unhandled rejection in ${this.relativeFile(evt.testFile)}`));
586548
this.lineWriter.writeLine();
587549
this.writeErr(evt);
588-
if (evt !== last || writeTrailingLines) {
589-
this.lineWriter.writeLine();
550+
if (evt !== last) {
590551
this.lineWriter.writeLine();
591552
this.lineWriter.writeLine();
592553
}
554+
555+
wroteSomething = true;
593556
}
594557
}
595558

596-
if (shouldWriteFailFastDisclaimer) {
559+
if (wroteSomething) {
560+
this.lineWriter.writeLine(colors.log(figures.line));
561+
this.lineWriter.writeLine();
562+
}
563+
564+
if (this.failFastEnabled && (this.stats.remainingTests > 0 || this.stats.files > this.stats.finishedWorkers)) {
597565
let remaining = '';
598566
if (this.stats.remainingTests > 0) {
599567
remaining += `At least ${this.stats.remainingTests} ${plur('test was', 'tests were', this.stats.remainingTests)} skipped`;
@@ -613,7 +581,48 @@ class MiniReporter {
613581
this.lineWriter.writeLine(colors.information(`\`--fail-fast\` is on. ${remaining}.`));
614582
}
615583

616-
this.lineWriter.writeLine();
584+
if (this.stats.failedHooks > 0) {
585+
this.lineWriter.writeLine(colors.error(`${this.stats.failedHooks} ${plur('hook', this.stats.failedHooks)} failed`) + firstLinePostfix);
586+
firstLinePostfix = '';
587+
}
588+
589+
if (this.stats.failedTests > 0) {
590+
this.lineWriter.writeLine(colors.error(`${this.stats.failedTests} ${plur('test', this.stats.failedTests)} failed`) + firstLinePostfix);
591+
firstLinePostfix = '';
592+
}
593+
594+
if (this.stats.failedHooks === 0 && this.stats.failedTests === 0 && this.stats.passedTests > 0) {
595+
this.lineWriter.writeLine(colors.pass(`${this.stats.passedTests} ${plur('test', this.stats.passedTests)} passed`) + firstLinePostfix);
596+
firstLinePostfix = '';
597+
}
598+
599+
if (this.stats.passedKnownFailingTests > 0) {
600+
this.lineWriter.writeLine(colors.error(`${this.stats.passedKnownFailingTests} ${plur('known failure', this.stats.passedKnownFailingTests)}`));
601+
}
602+
603+
if (this.stats.skippedTests > 0) {
604+
this.lineWriter.writeLine(colors.skip(`${this.stats.skippedTests} ${plur('test', this.stats.skippedTests)} skipped`));
605+
}
606+
607+
if (this.stats.todoTests > 0) {
608+
this.lineWriter.writeLine(colors.todo(`${this.stats.todoTests} ${plur('test', this.stats.todoTests)} todo`));
609+
}
610+
611+
if (this.stats.unhandledRejections > 0) {
612+
this.lineWriter.writeLine(colors.error(`${this.stats.unhandledRejections} unhandled ${plur('rejection', this.stats.unhandledRejections)}`));
613+
}
614+
615+
if (this.stats.uncaughtExceptions > 0) {
616+
this.lineWriter.writeLine(colors.error(`${this.stats.uncaughtExceptions} uncaught ${plur('exception', this.stats.uncaughtExceptions)}`));
617+
}
618+
619+
if (this.previousFailures > 0) {
620+
this.lineWriter.writeLine(colors.error(`${this.previousFailures} previous ${plur('failure', this.previousFailures)} in test files that were not rerun`));
621+
}
622+
623+
if (this.watching) {
624+
this.lineWriter.writeLine();
625+
}
617626
}
618627
}
619628
module.exports = MiniReporter;

0 commit comments

Comments
 (0)