@@ -526,7 +526,7 @@ class Test extends AsyncResource {
526526 } ;
527527
528528 #cancel( error ) {
529- if ( this . endTime !== null ) {
529+ if ( this . endTime !== null || this . error !== null ) {
530530 return ;
531531 }
532532
@@ -564,17 +564,15 @@ class Test extends AsyncResource {
564564 return ;
565565 }
566566
567- this . endTime = hrtime ( ) ;
568567 this . passed = false ;
569568 this . error = err ;
570569 }
571570
572571 pass ( ) {
573- if ( this . endTime !== null ) {
572+ if ( this . error !== null ) {
574573 return ;
575574 }
576575
577- this . endTime = hrtime ( ) ;
578576 this . passed = true ;
579577 }
580578
@@ -711,9 +709,6 @@ class Test extends AsyncResource {
711709 await afterEach ( ) ;
712710 await after ( ) ;
713711 } catch ( err ) {
714- // If one of the after hooks has thrown unset endTime so that the
715- // catch below can do its cancel/fail logic.
716- this . endTime = null ;
717712 throw err ;
718713 }
719714 } catch ( err ) {
@@ -761,13 +756,10 @@ class Test extends AsyncResource {
761756 }
762757
763758 postRun ( pendingSubtestsError ) {
759+ // If the test was cancelled before it started, then the start and end
760+ // times need to be corrected.
764761 this . startTime ??= hrtime ( ) ;
765-
766- // If the test was failed before it even started, then the end time will
767- // be earlier than the start time. Correct that here.
768- if ( this . endTime < this . startTime ) {
769- this . endTime = hrtime ( ) ;
770- }
762+ this . endTime ??= hrtime ( ) ;
771763
772764 // The test has run, so recursively cancel any outstanding subtests and
773765 // mark this test as failed if any subtests failed.
@@ -974,6 +966,7 @@ class TestHook extends Test {
974966 error . failureType = kHookFailure ;
975967 }
976968
969+ this . endTime ??= hrtime ( ) ;
977970 parent . reporter . fail ( 0 , loc , parent . subtests . length + 1 , loc . file , {
978971 __proto__ : null ,
979972 duration_ms : this . duration ( ) ,
0 commit comments