1- // https://github.com/nodejs/node/blob/a69a30016cf3395b0bd775c1340ab6ecbac58296 /lib/internal/test_runner/test.js
1+ // https://github.com/nodejs/node/blob/3e57891ee2fde0971e18fc383c25acf8f90def05 /lib/internal/test_runner/test.js
22
33'use strict'
44
@@ -146,6 +146,7 @@ class TestContext {
146146class Test extends AsyncResource {
147147 #abortController
148148 #outerSignal
149+ #reportedSubtest
149150
150151 constructor ( options ) {
151152 super ( 'Test' )
@@ -312,7 +313,7 @@ class Test extends AsyncResource {
312313 }
313314
314315 if ( i === 1 && this . parent !== null ) {
315- this . reporter . subtest ( this . indent , this . name )
316+ this . reportSubtest ( )
316317 }
317318
318319 // Report the subtest's results and remove it from the ready map.
@@ -635,12 +636,6 @@ class Test extends AsyncResource {
635636 this . processReadySubtestRange ( true )
636637
637638 // Output this test's results and update the parent's waiting counter.
638- if ( this . subtests . length > 0 ) {
639- this . reporter . plan ( this . subtests [ 0 ] . indent , this . subtests . length )
640- } else {
641- this . reporter . subtest ( this . indent , this . name )
642- }
643-
644639 this . report ( )
645640 this . parent . waitingOn ++
646641 this . finished = true
@@ -652,6 +647,11 @@ class Test extends AsyncResource {
652647 }
653648
654649 report ( ) {
650+ if ( this . subtests . length > 0 ) {
651+ this . reporter . plan ( this . subtests [ 0 ] . indent , this . subtests . length )
652+ } else {
653+ this . reportSubtest ( )
654+ }
655655 let directive
656656
657657 if ( this . skipped ) {
@@ -670,6 +670,15 @@ class Test extends AsyncResource {
670670 this . reporter . diagnostic ( this . indent , this . diagnostics [ i ] )
671671 }
672672 }
673+
674+ reportSubtest ( ) {
675+ if ( this . #reportedSubtest || this . parent === null ) {
676+ return
677+ }
678+ this . #reportedSubtest = true
679+ this . parent . reportSubtest ( )
680+ this . reporter . subtest ( this . indent , this . name )
681+ }
673682}
674683
675684class TestHook extends Test {
0 commit comments