@@ -286,6 +286,9 @@ class Test extends AsyncResource {
286286 beforeEach : [ ] ,
287287 afterEach : [ ] ,
288288 } ;
289+ this . completedCounters = {
290+ all : 0 , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0
291+ } ;
289292 this . waitingOn = 0 ;
290293 this . finished = false ;
291294 }
@@ -577,9 +580,32 @@ class Test extends AsyncResource {
577580 this . postRun ( ) ;
578581 }
579582
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+ }
582607
608+ postRun ( pendingSubtestsError ) {
583609 // If the test was failed before it even started, then the end time will
584610 // be earlier than the start time. Correct that here.
585611 if ( this . endTime < this . startTime ) {
@@ -592,34 +618,15 @@ class Test extends AsyncResource {
592618 this . pendingSubtests = [ ] ;
593619 for ( let i = 0 ; i < this . subtests . length ; i ++ ) {
594620 const subtest = this . subtests [ i ] ;
595-
596621 if ( ! subtest . finished ) {
597622 subtest . cancel ( pendingSubtestsError ) ;
598623 subtest . postRun ( pendingSubtestsError ) ;
599624 }
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- }
618625 }
619626
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` ;
623630
624631 this . fail ( new ERR_TEST_FAILURE ( msg , kSubtestsFailed ) ) ;
625632 }
@@ -632,20 +639,21 @@ class Test extends AsyncResource {
632639 this . parent . addReadySubtest ( this ) ;
633640 this . parent . processReadySubtestRange ( false ) ;
634641 this . parent . processPendingSubtests ( ) ;
642+ this . parent . countSubtest ( this ) ;
635643 } else if ( ! this . reported ) {
636644 this . reported = true ;
637- this . reporter . plan ( this . nesting , kFilename , this . subtests . length ) ;
645+ this . reporter . plan ( this . nesting , kFilename , this . completedCounters . all ) ;
638646
639647 for ( let i = 0 ; i < this . diagnostics . length ; i ++ ) {
640648 this . reporter . diagnostic ( this . nesting , kFilename , this . diagnostics [ i ] ) ;
641649 }
642650
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 } ` ) ;
649657 this . reporter . diagnostic ( this . nesting , kFilename , `duration_ms ${ this . #duration( ) } ` ) ;
650658
651659 if ( this . coverage ) {
0 commit comments