@@ -286,6 +286,9 @@ class Test extends AsyncResource {
286
286
beforeEach : [ ] ,
287
287
afterEach : [ ] ,
288
288
} ;
289
+ this . completedCounters = {
290
+ all : 0 , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0
291
+ } ;
289
292
this . waitingOn = 0 ;
290
293
this . finished = false ;
291
294
}
@@ -577,9 +580,32 @@ class Test extends AsyncResource {
577
580
this . postRun ( ) ;
578
581
}
579
582
580
- postRun ( pendingSubtestsError ) {
581
- const counters = { __proto__ : null , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0 } ;
583
+ countSubtest ( subtest ) {
584
+ if ( subtest . skipReporting || subtest . counted ) {
585
+ return ;
586
+ }
587
+ subtest . counted = true ;
588
+ // Check SKIP and TODO tests first, as those should not be counted as
589
+ // failures.
590
+ if ( subtest . skipped ) {
591
+ this . completedCounters . skipped ++ ;
592
+ } else if ( subtest . isTodo ) {
593
+ this . completedCounters . todo ++ ;
594
+ } else if ( subtest . cancelled ) {
595
+ this . completedCounters . cancelled ++ ;
596
+ } else if ( ! subtest . passed ) {
597
+ this . completedCounters . failed ++ ;
598
+ } else {
599
+ this . completedCounters . passed ++ ;
600
+ }
601
+
602
+ if ( ! subtest . passed ) {
603
+ this . completedCounters . totalFailed ++ ;
604
+ }
605
+ this . completedCounters . all ++ ;
606
+ }
582
607
608
+ postRun ( pendingSubtestsError ) {
583
609
// If the test was failed before it even started, then the end time will
584
610
// be earlier than the start time. Correct that here.
585
611
if ( this . endTime < this . startTime ) {
@@ -592,34 +618,15 @@ class Test extends AsyncResource {
592
618
this . pendingSubtests = [ ] ;
593
619
for ( let i = 0 ; i < this . subtests . length ; i ++ ) {
594
620
const subtest = this . subtests [ i ] ;
595
-
596
621
if ( ! subtest . finished ) {
597
622
subtest . cancel ( pendingSubtestsError ) ;
598
623
subtest . postRun ( pendingSubtestsError ) ;
599
624
}
600
-
601
- // Check SKIP and TODO tests first, as those should not be counted as
602
- // failures.
603
- if ( subtest . skipped ) {
604
- counters . skipped ++ ;
605
- } else if ( subtest . isTodo ) {
606
- counters . todo ++ ;
607
- } else if ( subtest . cancelled ) {
608
- counters . cancelled ++ ;
609
- } else if ( ! subtest . passed ) {
610
- counters . failed ++ ;
611
- } else {
612
- counters . passed ++ ;
613
- }
614
-
615
- if ( ! subtest . passed ) {
616
- counters . totalFailed ++ ;
617
- }
618
625
}
619
626
620
- if ( ( this . passed || this . parent === null ) && counters . totalFailed > 0 ) {
621
- const subtestString = `subtest${ counters . totalFailed > 1 ? 's' : '' } ` ;
622
- const msg = `${ counters . totalFailed } ${ subtestString } failed` ;
627
+ if ( ( this . passed || this . parent === null ) && this . completedCounters . totalFailed > 0 ) {
628
+ const subtestString = `subtest${ this . completedCounters . totalFailed > 1 ? 's' : '' } ` ;
629
+ const msg = `${ this . completedCounters . totalFailed } ${ subtestString } failed` ;
623
630
624
631
this . fail ( new ERR_TEST_FAILURE ( msg , kSubtestsFailed ) ) ;
625
632
}
@@ -632,20 +639,21 @@ class Test extends AsyncResource {
632
639
this . parent . addReadySubtest ( this ) ;
633
640
this . parent . processReadySubtestRange ( false ) ;
634
641
this . parent . processPendingSubtests ( ) ;
642
+ this . parent . countSubtest ( this ) ;
635
643
} else if ( ! this . reported ) {
636
644
this . reported = true ;
637
- this . reporter . plan ( this . nesting , kFilename , this . subtests . length ) ;
645
+ this . reporter . plan ( this . nesting , kFilename , this . completedCounters . all ) ;
638
646
639
647
for ( let i = 0 ; i < this . diagnostics . length ; i ++ ) {
640
648
this . reporter . diagnostic ( this . nesting , kFilename , this . diagnostics [ i ] ) ;
641
649
}
642
650
643
- this . reporter . diagnostic ( this . nesting , kFilename , `tests ${ this . subtests . length } ` ) ;
644
- this . reporter . diagnostic ( this . nesting , kFilename , `pass ${ counters . passed } ` ) ;
645
- this . reporter . diagnostic ( this . nesting , kFilename , `fail ${ counters . failed } ` ) ;
646
- this . reporter . diagnostic ( this . nesting , kFilename , `cancelled ${ counters . cancelled } ` ) ;
647
- this . reporter . diagnostic ( this . nesting , kFilename , `skipped ${ counters . skipped } ` ) ;
648
- this . reporter . diagnostic ( this . nesting , kFilename , `todo ${ counters . todo } ` ) ;
651
+ this . reporter . diagnostic ( this . nesting , kFilename , `tests ${ this . completedCounters . all } ` ) ;
652
+ this . reporter . diagnostic ( this . nesting , kFilename , `pass ${ this . completedCounters . passed } ` ) ;
653
+ this . reporter . diagnostic ( this . nesting , kFilename , `fail ${ this . completedCounters . failed } ` ) ;
654
+ this . reporter . diagnostic ( this . nesting , kFilename , `cancelled ${ this . completedCounters . cancelled } ` ) ;
655
+ this . reporter . diagnostic ( this . nesting , kFilename , `skipped ${ this . completedCounters . skipped } ` ) ;
656
+ this . reporter . diagnostic ( this . nesting , kFilename , `todo ${ this . completedCounters . todo } ` ) ;
649
657
this . reporter . diagnostic ( this . nesting , kFilename , `duration_ms ${ this . #duration( ) } ` ) ;
650
658
651
659
if ( this . coverage ) {
0 commit comments