@@ -10,10 +10,12 @@ const {
1010 ArrayPrototypeSplice,
1111 ArrayPrototypeUnshift,
1212 ArrayPrototypeUnshiftApply,
13+ BigInt,
1314 Error,
1415 FunctionPrototype,
1516 MathFloor,
1617 MathMax,
18+ MathRound,
1719 Number,
1820 NumberPrototypeToFixed,
1921 ObjectFreeze,
@@ -803,14 +805,25 @@ class Test extends AsyncResource {
803805 const previousAttempt = this . root . harness . previousRuns [ this . attempt - 1 ] ?. [ testIdentifier ] ;
804806 if ( previousAttempt != null ) {
805807 this . passedAttempt = previousAttempt . passed_on_attempt ;
808+ if ( previousAttempt . duration_ms !== undefined ) {
809+ this . replayedDurationNs = BigInt ( MathRound ( previousAttempt . duration_ms * 1_000_000 ) ) ;
810+ }
806811 this . fn = ( ) => {
812+ // Restore the original duration on the synthetic replay. Suites are
813+ // skipped here because Suite.run() unconditionally reassigns
814+ // startTime later; only non-suite tests benefit from setting it.
815+ if ( this . reportedType !== 'suite' ) {
816+ this . startTime = hrtime ( ) ;
817+ this . endTime = this . startTime + ( this . replayedDurationNs ?? 0n ) ;
818+ }
807819 for ( let i = 0 ; i < ( previousAttempt . children ?. length ?? 0 ) ; i ++ ) {
808820 const child = previousAttempt . children [ i ] ;
809821 const t = this . createSubtest ( Test , child . name , { __proto__ : null } , noop , {
810822 __proto__ : null ,
811823 loc : [ child . line , child . column , child . file ] ,
812824 } , noop ) ;
813- t . endTime = t . startTime = hrtime ( ) ;
825+ t . startTime = hrtime ( ) ;
826+ t . endTime = t . startTime + ( t . replayedDurationNs ?? 0n ) ;
814827 // For suites, Suite.run() starts the subtests via SafePromiseAll.
815828 // Starting them here as well would run them twice, re-invoking the
816829 // synthetic children-creator against a now-incremented disambiguator
0 commit comments