@@ -286,6 +286,10 @@ 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+ } ;
289293 this . waitingOn = 0 ;
290294 this . finished = false ;
291295 }
@@ -404,6 +408,7 @@ class Test extends AsyncResource {
404408 kCancelledByParent
405409 )
406410 ) ;
411+ this . error . failureType = kCancelledByParent ;
407412 this . startTime = this . startTime || this . endTime ; // If a test was canceled before it was started, e.g inside a hook
408413 this . cancelled = true ;
409414 this . #abortController. abort ( ) ;
@@ -577,9 +582,32 @@ class Test extends AsyncResource {
577582 this . postRun ( ) ;
578583 }
579584
580- postRun ( pendingSubtestsError ) {
581- const counters = { __proto__ : null , failed : 0 , passed : 0 , cancelled : 0 , skipped : 0 , todo : 0 , totalFailed : 0 } ;
585+ countSubtest ( subtest ) {
586+ if ( subtest . skipReporting || subtest . counted ) {
587+ return ;
588+ }
589+ subtest . counted = true ;
590+ // Check SKIP and TODO tests first, as those should not be counted as
591+ // 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 ++ ;
600+ } else {
601+ this . completedCounters . passed ++ ;
602+ }
603+
604+ if ( ! subtest . passed ) {
605+ this . completedCounters . totalFailed ++ ;
606+ }
607+ this . completedCounters . all ++ ;
608+ }
582609
610+ postRun ( pendingSubtestsError ) {
583611 // If the test was failed before it even started, then the end time will
584612 // be earlier than the start time. Correct that here.
585613 if ( this . endTime < this . startTime ) {
@@ -592,34 +620,15 @@ class Test extends AsyncResource {
592620 this . pendingSubtests = [ ] ;
593621 for ( let i = 0 ; i < this . subtests . length ; i ++ ) {
594622 const subtest = this . subtests [ i ] ;
595-
596623 if ( ! subtest . finished ) {
597624 subtest . cancel ( pendingSubtestsError ) ;
598625 subtest . postRun ( pendingSubtestsError ) ;
599626 }
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- }
618627 }
619628
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` ;
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` ;
623632
624633 this . fail ( new ERR_TEST_FAILURE ( msg , kSubtestsFailed ) ) ;
625634 }
@@ -632,20 +641,21 @@ class Test extends AsyncResource {
632641 this . parent . addReadySubtest ( this ) ;
633642 this . parent . processReadySubtestRange ( false ) ;
634643 this . parent . processPendingSubtests ( ) ;
644+ this . parent . countSubtest ( this ) ;
635645 } else if ( ! this . reported ) {
636646 this . reported = true ;
637- this . reporter . plan ( this . nesting , kFilename , this . subtests . length ) ;
647+ this . reporter . plan ( this . nesting , kFilename , this . completedCounters . all ) ;
638648
639649 for ( let i = 0 ; i < this . diagnostics . length ; i ++ ) {
640650 this . reporter . diagnostic ( this . nesting , kFilename , this . diagnostics [ i ] ) ;
641651 }
642652
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 } ` ) ;
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 } ` ) ;
649659 this . reporter . diagnostic ( this . nesting , kFilename , `duration_ms ${ this . #duration( ) } ` ) ;
650660
651661 if ( this . coverage ) {
0 commit comments