@@ -34,6 +34,7 @@ const { MockTracker } = require('internal/test_runner/mock');
34
34
const { TestsStream } = require ( 'internal/test_runner/tests_stream' ) ;
35
35
const {
36
36
createDeferredCallback,
37
+ countCompletedTest,
37
38
isTestFailureError,
38
39
parseCommandLine,
39
40
} = require ( 'internal/test_runner/utils' ) ;
@@ -186,6 +187,7 @@ class Test extends AsyncResource {
186
187
this . runOnlySubtests = this . only ;
187
188
this . testNumber = 0 ;
188
189
this . timeout = kDefaultTimeout ;
190
+ this . root = this ;
189
191
} else {
190
192
const nesting = parent . parent === null ? parent . nesting :
191
193
parent . nesting + 1 ;
@@ -197,6 +199,7 @@ class Test extends AsyncResource {
197
199
this . runOnlySubtests = ! this . only ;
198
200
this . testNumber = parent . subtests . length + 1 ;
199
201
this . timeout = parent . timeout ;
202
+ this . root = parent . root ;
200
203
}
201
204
202
205
switch ( typeof concurrency ) {
@@ -575,31 +578,7 @@ class Test extends AsyncResource {
575
578
this . postRun ( ) ;
576
579
}
577
580
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
-
599
581
postRun ( pendingSubtestsError ) {
600
- const counters = {
601
- __proto__ : null , all : 0 , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0 ,
602
- } ;
603
582
// If the test was failed before it even started, then the end time will
604
583
// be earlier than the start time. Correct that here.
605
584
if ( this . endTime < this . startTime ) {
@@ -610,19 +589,22 @@ class Test extends AsyncResource {
610
589
// The test has run, so recursively cancel any outstanding subtests and
611
590
// mark this test as failed if any subtests failed.
612
591
this . pendingSubtests = [ ] ;
592
+ let failed = 0 ;
613
593
for ( let i = 0 ; i < this . subtests . length ; i ++ ) {
614
594
const subtest = this . subtests [ i ] ;
615
595
616
596
if ( ! subtest . finished ) {
617
597
subtest . #cancel( pendingSubtestsError ) ;
618
598
subtest . postRun ( pendingSubtestsError ) ;
619
599
}
620
- subtest . countSubtest ( counters ) ;
600
+ if ( ! subtest . passed ) {
601
+ failed ++ ;
602
+ }
621
603
}
622
604
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` ;
626
608
627
609
this . fail ( new ERR_TEST_FAILURE ( msg , kSubtestsFailed ) ) ;
628
610
}
@@ -637,18 +619,19 @@ class Test extends AsyncResource {
637
619
this . parent . processPendingSubtests ( ) ;
638
620
} else if ( ! this . reported ) {
639
621
this . reported = true ;
640
- this . reporter . plan ( this . nesting , kFilename , counters . all ) ;
622
+ this . reporter . plan ( this . nesting , kFilename , this . root . harness . counters . planned ) ;
641
623
642
624
for ( let i = 0 ; i < this . diagnostics . length ; i ++ ) {
643
625
this . reporter . diagnostic ( this . nesting , kFilename , this . diagnostics [ i ] ) ;
644
626
}
645
627
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 } ` ) ;
652
635
this . reporter . diagnostic ( this . nesting , kFilename , `duration_ms ${ this . #duration( ) } ` ) ;
653
636
654
637
if ( this . harness ?. coverage ) {
@@ -689,6 +672,7 @@ class Test extends AsyncResource {
689
672
}
690
673
691
674
report ( ) {
675
+ countCompletedTest ( this ) ;
692
676
if ( this . subtests . length > 0 ) {
693
677
this . reporter . plan ( this . subtests [ 0 ] . nesting , kFilename , this . subtests . length ) ;
694
678
} else {
@@ -703,6 +687,10 @@ class Test extends AsyncResource {
703
687
directive = this . reporter . getTodo ( this . message ) ;
704
688
}
705
689
690
+ if ( this . reportedType ) {
691
+ details . type = this . reportedType ;
692
+ }
693
+
706
694
if ( this . passed ) {
707
695
this . reporter . ok ( this . nesting , kFilename , this . testNumber , this . name , details , directive ) ;
708
696
} else {
@@ -746,6 +734,7 @@ class TestHook extends Test {
746
734
}
747
735
748
736
class Suite extends Test {
737
+ reportedType = 'suite' ;
749
738
constructor ( options ) {
750
739
super ( options ) ;
751
740
0 commit comments