@@ -286,10 +286,6 @@ class Test extends AsyncResource {
286286 beforeEach : [ ] ,
287287 afterEach : [ ] ,
288288 } ;
289- this . completedCounters = {
290- __proto__ : null ,
291- all : 0 , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0
292- } ;
293289 this . waitingOn = 0 ;
294290 this . finished = false ;
295291 }
@@ -582,32 +578,31 @@ class Test extends AsyncResource {
582578 this . postRun ( ) ;
583579 }
584580
585- countSubtest ( subtest ) {
586- if ( subtest . skipReporting || subtest . counted ) {
587- return ;
588- }
589- subtest . counted = true ;
581+ countSubtest ( counters ) {
590582 // Check SKIP and TODO tests first, as those should not be counted as
591583 // failures.
592- if ( subtest . skipped ) {
593- this . completedCounters . skipped ++ ;
594- } else if ( subtest . isTodo ) {
595- this . completedCounters . todo ++ ;
596- } else if ( subtest . cancelled ) {
597- this . completedCounters . cancelled ++ ;
598- } else if ( ! subtest . passed ) {
599- this . completedCounters . failed ++ ;
584+ if ( this . skipped ) {
585+ counters . skipped ++ ;
586+ } else if ( this . isTodo ) {
587+ counters . todo ++ ;
588+ } else if ( this . cancelled ) {
589+ counters . cancelled ++ ;
590+ } else if ( ! this . passed ) {
591+ counters . failed ++ ;
600592 } else {
601- this . completedCounters . passed ++ ;
593+ counters . passed ++ ;
602594 }
603595
604- if ( ! subtest . passed ) {
605- this . completedCounters . totalFailed ++ ;
596+ if ( ! this . passed ) {
597+ counters . totalFailed ++ ;
606598 }
607- this . completedCounters . all ++ ;
599+ counters . all ++ ;
608600 }
609601
610602 postRun ( pendingSubtestsError ) {
603+ const counters = {
604+ __proto__ : null , all : 0 , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0
605+ } ;
611606 // If the test was failed before it even started, then the end time will
612607 // be earlier than the start time. Correct that here.
613608 if ( this . endTime < this . startTime ) {
@@ -620,15 +615,17 @@ class Test extends AsyncResource {
620615 this . pendingSubtests = [ ] ;
621616 for ( let i = 0 ; i < this . subtests . length ; i ++ ) {
622617 const subtest = this . subtests [ i ] ;
618+
623619 if ( ! subtest . finished ) {
624620 subtest . cancel ( pendingSubtestsError ) ;
625621 subtest . postRun ( pendingSubtestsError ) ;
626622 }
623+ subtest . countSubtest ( counters ) ;
627624 }
628625
629- if ( ( this . passed || this . parent === null ) && this . completedCounters . totalFailed > 0 ) {
630- const subtestString = `subtest${ this . completedCounters . totalFailed > 1 ? 's' : '' } ` ;
631- const msg = `${ this . completedCounters . totalFailed } ${ subtestString } failed` ;
626+ if ( ( this . passed || this . parent === null ) && counters . totalFailed > 0 ) {
627+ const subtestString = `subtest${ counters . totalFailed > 1 ? 's' : '' } ` ;
628+ const msg = `${ counters . totalFailed } ${ subtestString } failed` ;
632629
633630 this . fail ( new ERR_TEST_FAILURE ( msg , kSubtestsFailed ) ) ;
634631 }
@@ -641,21 +638,20 @@ class Test extends AsyncResource {
641638 this . parent . addReadySubtest ( this ) ;
642639 this . parent . processReadySubtestRange ( false ) ;
643640 this . parent . processPendingSubtests ( ) ;
644- this . parent . countSubtest ( this ) ;
645641 } else if ( ! this . reported ) {
646642 this . reported = true ;
647- this . reporter . plan ( this . nesting , kFilename , this . completedCounters . all ) ;
643+ this . reporter . plan ( this . nesting , kFilename , counters . all ) ;
648644
649645 for ( let i = 0 ; i < this . diagnostics . length ; i ++ ) {
650646 this . reporter . diagnostic ( this . nesting , kFilename , this . diagnostics [ i ] ) ;
651647 }
652648
653- this . reporter . diagnostic ( this . nesting , kFilename , `tests ${ this . completedCounters . all } ` ) ;
654- this . reporter . diagnostic ( this . nesting , kFilename , `pass ${ this . completedCounters . passed } ` ) ;
655- this . reporter . diagnostic ( this . nesting , kFilename , `fail ${ this . completedCounters . failed } ` ) ;
656- this . reporter . diagnostic ( this . nesting , kFilename , `cancelled ${ this . completedCounters . cancelled } ` ) ;
657- this . reporter . diagnostic ( this . nesting , kFilename , `skipped ${ this . completedCounters . skipped } ` ) ;
658- this . reporter . diagnostic ( this . nesting , kFilename , `todo ${ this . completedCounters . todo } ` ) ;
649+ this . reporter . diagnostic ( this . nesting , kFilename , `tests ${ counters . all } ` ) ;
650+ this . reporter . diagnostic ( this . nesting , kFilename , `pass ${ counters . passed } ` ) ;
651+ this . reporter . diagnostic ( this . nesting , kFilename , `fail ${ counters . failed } ` ) ;
652+ this . reporter . diagnostic ( this . nesting , kFilename , `cancelled ${ counters . cancelled } ` ) ;
653+ this . reporter . diagnostic ( this . nesting , kFilename , `skipped ${ counters . skipped } ` ) ;
654+ this . reporter . diagnostic ( this . nesting , kFilename , `todo ${ counters . todo } ` ) ;
659655 this . reporter . diagnostic ( this . nesting , kFilename , `duration_ms ${ this . #duration( ) } ` ) ;
660656
661657 if ( this . coverage ) {
0 commit comments