@@ -526,7 +526,7 @@ class Test extends AsyncResource {
526
526
} ;
527
527
528
528
#cancel( error ) {
529
- if ( this . endTime !== null ) {
529
+ if ( this . endTime !== null || this . error !== null ) {
530
530
return ;
531
531
}
532
532
@@ -564,17 +564,15 @@ class Test extends AsyncResource {
564
564
return ;
565
565
}
566
566
567
- this . endTime = hrtime ( ) ;
568
567
this . passed = false ;
569
568
this . error = err ;
570
569
}
571
570
572
571
pass ( ) {
573
- if ( this . endTime !== null ) {
572
+ if ( this . error !== null ) {
574
573
return ;
575
574
}
576
575
577
- this . endTime = hrtime ( ) ;
578
576
this . passed = true ;
579
577
}
580
578
@@ -711,9 +709,6 @@ class Test extends AsyncResource {
711
709
await afterEach ( ) ;
712
710
await after ( ) ;
713
711
} 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 ;
717
712
throw err ;
718
713
}
719
714
} catch ( err ) {
@@ -761,13 +756,10 @@ class Test extends AsyncResource {
761
756
}
762
757
763
758
postRun ( pendingSubtestsError ) {
759
+ // If the test was cancelled before it started, then the start and end
760
+ // times need to be corrected.
764
761
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 ( ) ;
771
763
772
764
// The test has run, so recursively cancel any outstanding subtests and
773
765
// mark this test as failed if any subtests failed.
@@ -974,6 +966,7 @@ class TestHook extends Test {
974
966
error . failureType = kHookFailure ;
975
967
}
976
968
969
+ this . endTime ??= hrtime ( ) ;
977
970
parent . reporter . fail ( 0 , loc , parent . subtests . length + 1 , loc . file , {
978
971
__proto__ : null ,
979
972
duration_ms : this . duration ( ) ,
0 commit comments