11import * as assert from "assert" ;
22import * as util from "util" ;
3- import type { Clock } from "@sinonjs/fake-timers" ;
43
54// Grab the setTimeout from global before jest overwrites it with useFakeTimers
65const setTimeoutBypassingFakes = global . setTimeout ;
@@ -127,18 +126,15 @@ export function setupFakeTimers() {
127126 ) } '`,
128127 ) ;
129128
130- const clock = ( Date as any ) . clock ;
131- assertSinonJsClock ( clock ) ;
132-
133- if ( targetTimestamp < clock . now ) {
134- clock . setSystemTime ( targetTimestamp ) ;
129+ if ( targetTimestamp < Date . now ( ) ) {
130+ jest . setSystemTime ( targetTimestamp ) ;
135131 } else {
136- while ( clock . now + increment < targetTimestamp ) {
132+ while ( Date . now ( ) + increment < targetTimestamp ) {
137133 jest . advanceTimersByTime ( increment ) ;
138134 await aFewRunLoops ( ) ;
139135 }
140- if ( clock . now < targetTimestamp ) {
141- jest . advanceTimersByTime ( targetTimestamp - clock . now ) ;
136+ if ( Date . now ( ) < targetTimestamp ) {
137+ jest . advanceTimersByTime ( targetTimestamp - Date . now ( ) ) ;
142138 await aFewRunLoops ( ) ;
143139 }
144140 }
@@ -149,16 +145,6 @@ export function setupFakeTimers() {
149145 return { setTime, realNow } ;
150146}
151147
152- function assertSinonJsClock ( clock : any ) : asserts clock is Clock {
153- if (
154- ! clock ||
155- typeof clock . now !== "number" ||
156- typeof clock . setSystemTime !== "function"
157- ) {
158- throw new Error ( `Expected sinonjs clock!` ) ;
159- }
160- }
161-
162148/** One second in milliseconds */
163149export const SECOND = 1000 ;
164150/** One minute in milliseconds */
0 commit comments