@exodus/test 1.0.0-rc.87 → 1.0.0-rc.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/jest.timers.js +11 -1
package/package.json
CHANGED
package/src/jest.timers.js
CHANGED
|
@@ -65,14 +65,24 @@ export function runOnlyPendingTimers() {
|
|
|
65
65
|
return this
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// We have to tick in divisors of 1000, or e.g. 6s will mismatch a bit from 1s + 5s
|
|
69
|
+
const divisors1000 = [1000, 500, 250, 200, 125, 100, 50, 40, 25, 20, 10, 8, 5, 4, 2, 1]
|
|
70
|
+
|
|
71
|
+
function divisor1000(x) {
|
|
72
|
+
if (x <= 1) return 1 // fast path
|
|
73
|
+
for (const d of divisors1000) if (x >= d) return d
|
|
74
|
+
return 1 // unreachable
|
|
75
|
+
}
|
|
76
|
+
|
|
68
77
|
// We split this into multiple steps to run timers scheduled during the time we are running
|
|
69
78
|
function splitTime(time, min = 1000) {
|
|
70
79
|
const minSteps = Math.min(min, time) // usually just split e.g. 5 seconds into 1000 * 5ms
|
|
71
|
-
const step =
|
|
80
|
+
const step = divisor1000(Math.floor(time / minSteps))
|
|
72
81
|
const steps = Math.floor(time / step) // up to 2x higher than minSteps
|
|
73
82
|
const last = time - steps * step
|
|
74
83
|
// 1999 -> { step: 1, steps: 1999, last: 0 }
|
|
75
84
|
// 2001 -> { step: 2, steps: 1000, last: 1 }
|
|
85
|
+
// 6000 -> { step: 5, steps: 1200, last: 0 }
|
|
76
86
|
return { step, steps, last }
|
|
77
87
|
}
|
|
78
88
|
|