@@ -34,6 +34,7 @@ const { MockTracker } = require('internal/test_runner/mock');
3434const { TestsStream } = require ( 'internal/test_runner/tests_stream' ) ;
3535const {
3636 createDeferredCallback,
37+ countCompletedTest,
3738 isTestFailureError,
3839 parseCommandLine,
3940} = require ( 'internal/test_runner/utils' ) ;
@@ -186,6 +187,7 @@ class Test extends AsyncResource {
186187 this . runOnlySubtests = this . only ;
187188 this . testNumber = 0 ;
188189 this . timeout = kDefaultTimeout ;
190+ this . root = this ;
189191 } else {
190192 const nesting = parent . parent === null ? parent . nesting :
191193 parent . nesting + 1 ;
@@ -197,6 +199,7 @@ class Test extends AsyncResource {
197199 this . runOnlySubtests = ! this . only ;
198200 this . testNumber = parent . subtests . length + 1 ;
199201 this . timeout = parent . timeout ;
202+ this . root = parent . root ;
200203 }
201204
202205 switch ( typeof concurrency ) {
@@ -575,31 +578,7 @@ class Test extends AsyncResource {
575578 this . postRun ( ) ;
576579 }
577580
578- countSubtest ( counters ) {
579- // Check SKIP and TODO tests first, as those should not be counted as
580- // failures.
581- if ( this . skipped ) {
582- counters . skipped ++ ;
583- } else if ( this . isTodo ) {
584- counters . todo ++ ;
585- } else if ( this . cancelled ) {
586- counters . cancelled ++ ;
587- } else if ( ! this . passed ) {
588- counters . failed ++ ;
589- } else {
590- counters . passed ++ ;
591- }
592-
593- if ( ! this . passed ) {
594- counters . totalFailed ++ ;
595- }
596- counters . all ++ ;
597- }
598-
599581 postRun ( pendingSubtestsError ) {
600- const counters = {
601- __proto__ : null , all : 0 , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0 ,
602- } ;
603582 // If the test was failed before it even started, then the end time will
604583 // be earlier than the start time. Correct that here.
605584 if ( this . endTime < this . startTime ) {
@@ -610,19 +589,22 @@ class Test extends AsyncResource {
610589 // The test has run, so recursively cancel any outstanding subtests and
611590 // mark this test as failed if any subtests failed.
612591 this . pendingSubtests = [ ] ;
592+ let failed = 0 ;
613593 for ( let i = 0 ; i < this . subtests . length ; i ++ ) {
614594 const subtest = this . subtests [ i ] ;
615595
616596 if ( ! subtest . finished ) {
617597 subtest . #cancel( pendingSubtestsError ) ;
618598 subtest . postRun ( pendingSubtestsError ) ;
619599 }
620- subtest . countSubtest ( counters ) ;
600+ if ( ! subtest . passed ) {
601+ failed ++ ;
602+ }
621603 }
622604
623- if ( ( this . passed || this . parent === null ) && counters . totalFailed > 0 ) {
624- const subtestString = `subtest${ counters . totalFailed > 1 ? 's' : '' } ` ;
625- const msg = `${ counters . totalFailed } ${ subtestString } failed` ;
605+ if ( ( this . passed || this . parent === null ) && failed > 0 ) {
606+ const subtestString = `subtest${ failed > 1 ? 's' : '' } ` ;
607+ const msg = `${ failed } ${ subtestString } failed` ;
626608
627609 this . fail ( new ERR_TEST_FAILURE ( msg , kSubtestsFailed ) ) ;
628610 }
@@ -637,18 +619,19 @@ class Test extends AsyncResource {
637619 this . parent . processPendingSubtests ( ) ;
638620 } else if ( ! this . reported ) {
639621 this . reported = true ;
640- this . reporter . plan ( this . nesting , kFilename , counters . all ) ;
622+ this . reporter . plan ( this . nesting , kFilename , this . root . harness . counters . planned ) ;
641623
642624 for ( let i = 0 ; i < this . diagnostics . length ; i ++ ) {
643625 this . reporter . diagnostic ( this . nesting , kFilename , this . diagnostics [ i ] ) ;
644626 }
645627
646- this . reporter . diagnostic ( this . nesting , kFilename , `tests ${ counters . all } ` ) ;
647- this . reporter . diagnostic ( this . nesting , kFilename , `pass ${ counters . passed } ` ) ;
648- this . reporter . diagnostic ( this . nesting , kFilename , `fail ${ counters . failed } ` ) ;
649- this . reporter . diagnostic ( this . nesting , kFilename , `cancelled ${ counters . cancelled } ` ) ;
650- this . reporter . diagnostic ( this . nesting , kFilename , `skipped ${ counters . skipped } ` ) ;
651- this . reporter . diagnostic ( this . nesting , kFilename , `todo ${ counters . todo } ` ) ;
628+ this . reporter . diagnostic ( this . nesting , kFilename , `tests ${ this . root . harness . counters . all } ` ) ;
629+ this . reporter . diagnostic ( this . nesting , kFilename , `suites ${ this . root . harness . counters . suites } ` ) ;
630+ this . reporter . diagnostic ( this . nesting , kFilename , `pass ${ this . root . harness . counters . passed } ` ) ;
631+ this . reporter . diagnostic ( this . nesting , kFilename , `fail ${ this . root . harness . counters . failed } ` ) ;
632+ this . reporter . diagnostic ( this . nesting , kFilename , `cancelled ${ this . root . harness . counters . cancelled } ` ) ;
633+ this . reporter . diagnostic ( this . nesting , kFilename , `skipped ${ this . root . harness . counters . skipped } ` ) ;
634+ this . reporter . diagnostic ( this . nesting , kFilename , `todo ${ this . root . harness . counters . todo } ` ) ;
652635 this . reporter . diagnostic ( this . nesting , kFilename , `duration_ms ${ this . #duration( ) } ` ) ;
653636
654637 if ( this . harness ?. coverage ) {
@@ -689,6 +672,7 @@ class Test extends AsyncResource {
689672 }
690673
691674 report ( ) {
675+ countCompletedTest ( this ) ;
692676 if ( this . subtests . length > 0 ) {
693677 this . reporter . plan ( this . subtests [ 0 ] . nesting , kFilename , this . subtests . length ) ;
694678 } else {
@@ -703,6 +687,10 @@ class Test extends AsyncResource {
703687 directive = this . reporter . getTodo ( this . message ) ;
704688 }
705689
690+ if ( this . reportedType ) {
691+ details . type = this . reportedType ;
692+ }
693+
706694 if ( this . passed ) {
707695 this . reporter . ok ( this . nesting , kFilename , this . testNumber , this . name , details , directive ) ;
708696 } else {
@@ -746,6 +734,7 @@ class TestHook extends Test {
746734}
747735
748736class Suite extends Test {
737+ reportedType = 'suite' ;
749738 constructor ( options ) {
750739 super ( options ) ;
751740
0 commit comments