@@ -299,6 +299,7 @@ class MiniReporter {
299
299
writeErr ( evt ) {
300
300
if ( evt . err . name === 'TSError' && evt . err . object && evt . err . object . diagnosticText ) {
301
301
this . lineWriter . writeLine ( colors . errorStack ( trimOffNewlines ( evt . err . object . diagnosticText ) ) ) ;
302
+ this . lineWriter . writeLine ( ) ;
302
303
return ;
303
304
}
304
305
@@ -308,37 +309,39 @@ class MiniReporter {
308
309
if ( excerpt ) {
309
310
this . lineWriter . writeLine ( ) ;
310
311
this . lineWriter . writeLine ( excerpt ) ;
312
+ this . lineWriter . writeLine ( ) ;
311
313
}
312
314
}
313
315
314
316
if ( evt . err . avaAssertionError ) {
315
317
const result = formatSerializedError ( evt . err ) ;
316
318
if ( result . printMessage ) {
317
- this . lineWriter . writeLine ( ) ;
318
319
this . lineWriter . writeLine ( evt . err . message ) ;
320
+ this . lineWriter . writeLine ( ) ;
319
321
}
320
322
321
323
if ( result . formatted ) {
322
- this . lineWriter . writeLine ( ) ;
323
324
this . lineWriter . writeLine ( result . formatted ) ;
325
+ this . lineWriter . writeLine ( ) ;
324
326
}
325
327
326
328
const message = improperUsageMessages . forError ( evt . err ) ;
327
329
if ( message ) {
328
- this . lineWriter . writeLine ( ) ;
329
330
this . lineWriter . writeLine ( message ) ;
331
+ this . lineWriter . writeLine ( ) ;
330
332
}
331
333
} else if ( evt . err . nonErrorObject ) {
332
334
this . lineWriter . writeLine ( trimOffNewlines ( evt . err . formatted ) ) ;
333
- } else {
334
335
this . lineWriter . writeLine ( ) ;
336
+ } else {
335
337
this . lineWriter . writeLine ( evt . err . summary ) ;
338
+ this . lineWriter . writeLine ( ) ;
336
339
}
337
340
338
341
const formatted = this . formatErrorStack ( evt . err ) ;
339
342
if ( formatted . length > 0 ) {
340
- this . lineWriter . writeLine ( ) ;
341
343
this . lineWriter . writeLine ( formatted . join ( '\n' ) ) ;
344
+ this . lineWriter . writeLine ( ) ;
342
345
}
343
346
}
344
347
@@ -360,8 +363,12 @@ class MiniReporter {
360
363
return [ error . stack ] ;
361
364
}
362
365
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
+
365
372
for ( const log of evt . logs ) {
366
373
const logLines = indentString ( colors . log ( log ) , 4 ) ;
367
374
const logLinesWithLeadingFigure = logLines . replace (
@@ -370,7 +377,15 @@ class MiniReporter {
370
377
) ;
371
378
this . lineWriter . writeLine ( logLinesWithLeadingFigure ) ;
372
379
}
380
+
381
+ if ( surroundLines ) {
382
+ this . lineWriter . writeLine ( ) ;
383
+ }
384
+
385
+ return true ;
373
386
}
387
+
388
+ return false ;
374
389
}
375
390
376
391
writeTestSummary ( evt ) {
@@ -385,8 +400,10 @@ class MiniReporter {
385
400
386
401
writeFailure ( evt ) {
387
402
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
+
390
407
this . writeErr ( evt ) ;
391
408
}
392
409
@@ -409,28 +426,28 @@ class MiniReporter {
409
426
this . spinner . stop ( ) ;
410
427
cliCursor . show ( this . reportStream ) ;
411
428
429
+ let firstLinePostfix = this . watching ?
430
+ ' ' + chalk . gray . dim ( '[' + new Date ( ) . toLocaleTimeString ( 'en-US' , { hour12 : false } ) + ']' ) :
431
+ '' ;
432
+
412
433
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 ) ) ;
414
435
this . lineWriter . writeLine ( ) ;
415
436
return ;
416
437
}
417
438
418
439
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 ) ) ;
420
441
this . lineWriter . writeLine ( ) ;
421
442
return ;
422
443
}
423
444
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 ;
430
446
if ( this . filesWithMissingAvaImports . size > 0 ) {
431
447
for ( const testFile of this . filesWithMissingAvaImports ) {
432
448
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 ) ;
433
449
firstLinePostfix = '' ;
450
+ wroteSomething = true ;
434
451
}
435
452
}
436
453
@@ -439,13 +456,16 @@ class MiniReporter {
439
456
if ( ! this . filesWithMissingAvaImports . has ( testFile ) ) {
440
457
this . lineWriter . writeLine ( colors . error ( `${ figures . cross } No tests found in ${ this . relativeFile ( testFile ) } ` ) + firstLinePostfix ) ;
441
458
firstLinePostfix = '' ;
459
+ wroteSomething = true ;
442
460
}
443
461
}
444
462
}
445
463
446
464
if ( this . lineNumberErrors . length > 0 ) {
447
465
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 ;
449
469
}
450
470
}
451
471
@@ -454,84 +474,35 @@ class MiniReporter {
454
474
if ( ! this . filesWithMissingAvaImports . has ( testFile ) && ! this . filesWithoutDeclaredTests . has ( testFile ) ) {
455
475
this . lineWriter . writeLine ( colors . error ( `${ figures . cross } Line numbers for ${ this . relativeFile ( testFile ) } did not match any tests` ) + firstLinePostfix ) ;
456
476
firstLinePostfix = '' ;
477
+ wroteSomething = true ;
457
478
}
458
479
}
459
480
}
460
481
461
- if ( this . filesWithMissingAvaImports . size > 0 || this . filesWithoutDeclaredTests . size > 0 || this . filesWithoutMatchedLineNumbers . size > 0 ) {
482
+ if ( wroteSomething ) {
462
483
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 ) ) ;
505
485
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 ;
509
487
}
510
488
511
- const shouldWriteFailFastDisclaimer = this . failFastEnabled && ( this . stats . remainingTests > 0 || this . stats . files > this . stats . finishedWorkers ) ;
512
-
513
489
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 ;
516
491
517
492
const last = this . failures [ this . failures . length - 1 ] ;
518
493
for ( const evt of this . failures ) {
519
494
this . writeFailure ( evt ) ;
520
495
if ( evt !== last || writeTrailingLines ) {
521
496
this . lineWriter . writeLine ( ) ;
522
497
this . lineWriter . writeLine ( ) ;
523
- this . lineWriter . writeLine ( ) ;
524
498
}
499
+
500
+ wroteSomething = true ;
525
501
}
526
502
}
527
503
528
504
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 ;
535
506
536
507
const last = this . internalErrors [ this . internalErrors . length - 1 ] ;
537
508
for ( const evt of this . internalErrors ) {
@@ -548,16 +519,13 @@ class MiniReporter {
548
519
this . lineWriter . writeLine ( ) ;
549
520
this . lineWriter . writeLine ( ) ;
550
521
}
522
+
523
+ wroteSomething = true ;
551
524
}
552
525
}
553
526
554
527
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 ;
561
529
562
530
const last = this . uncaughtExceptions [ this . uncaughtExceptions . length - 1 ] ;
563
531
for ( const evt of this . uncaughtExceptions ) {
@@ -567,33 +535,33 @@ class MiniReporter {
567
535
if ( evt !== last || writeTrailingLines ) {
568
536
this . lineWriter . writeLine ( ) ;
569
537
this . lineWriter . writeLine ( ) ;
570
- this . lineWriter . writeLine ( ) ;
571
538
}
539
+
540
+ wroteSomething = true ;
572
541
}
573
542
}
574
543
575
544
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
-
583
545
const last = this . unhandledRejections [ this . unhandledRejections . length - 1 ] ;
584
546
for ( const evt of this . unhandledRejections ) {
585
547
this . lineWriter . writeLine ( colors . title ( `Unhandled rejection in ${ this . relativeFile ( evt . testFile ) } ` ) ) ;
586
548
this . lineWriter . writeLine ( ) ;
587
549
this . writeErr ( evt ) ;
588
- if ( evt !== last || writeTrailingLines ) {
589
- this . lineWriter . writeLine ( ) ;
550
+ if ( evt !== last ) {
590
551
this . lineWriter . writeLine ( ) ;
591
552
this . lineWriter . writeLine ( ) ;
592
553
}
554
+
555
+ wroteSomething = true ;
593
556
}
594
557
}
595
558
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 ) ) {
597
565
let remaining = '' ;
598
566
if ( this . stats . remainingTests > 0 ) {
599
567
remaining += `At least ${ this . stats . remainingTests } ${ plur ( 'test was' , 'tests were' , this . stats . remainingTests ) } skipped` ;
@@ -613,7 +581,48 @@ class MiniReporter {
613
581
this . lineWriter . writeLine ( colors . information ( `\`--fail-fast\` is on. ${ remaining } .` ) ) ;
614
582
}
615
583
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
+ }
617
626
}
618
627
}
619
628
module . exports = MiniReporter ;
0 commit comments