You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use fakeTimers does not mock imports from node:timers or node:timers/promisesΒ #10871
vi.useFakeTimers() did not mock setTimeout imported from node:timers or node:timers/promises. The fake timers patch read the timer modules at module load time, before vitest_required is populated, so the module methods were never patched, and Node snapshots ESM named import bindings at first load.
The PR registers node:timers and node:timers/promises as live module stubs in the module runner and reads the timer modules lazily inside the fake timers install(). Regression tests added in test/unit/test/timers-node.test.ts (named, default, namespace, promises, and require imports), passing in the threads, forks, and vmThreads pools. It also fixes the Windows typechecker OOM test that was already failing on main.
Apparently, docs have never mentioned faketimers mocking node:timers and node:timers/promises, so technically it's not settled what's the expected behavior. Also enabling mocking for this may be considered breaking change.
Apparently, docs have never mentioned faketimers mocking node:timers and node:timers/promises, so technically it's not settled what's the expected behavior. Also enabling mocking for this may be considered breaking change.
I'd say adding support (or fixing it) for mocking node:timers built-in module is just a feature. But to mock those by default in useFakeTimers() is breaking change.
Activity
fix: mock node:timers imports when fake timers are active
fix: mock node:timers imports when fake timers are active
atharv-sys32 commentedon Aug 5, 2026
Hi @sheremet-va. Opened a fix for this: #10878.
vi.useFakeTimers() did not mock setTimeout imported from node:timers or node:timers/promises. The fake timers patch read the timer modules at module load time, before vitest_required is populated, so the module methods were never patched, and Node snapshots ESM named import bindings at first load.
The PR registers node:timers and node:timers/promises as live module stubs in the module runner and reads the timer modules lazily inside the fake timers install(). Regression tests added in test/unit/test/timers-node.test.ts (named, default, namespace, promises, and require imports), passing in the threads, forks, and vmThreads pools. It also fixes the Windows typechecker OOM test that was already failing on main.
Would appreciate a look.
hi-ogawa commentedon Aug 10, 2026
Apparently, docs have never mentioned faketimers mocking
node:timersandnode:timers/promises, so technically it's not settled what's the expected behavior. Also enabling mocking for this may be considered breaking change.Nokel81 commentedon Aug 10, 2026
Fair, I was mostly going off of the changelogs.
AriPerkkio commentedon Aug 14, 2026
I'd say adding support (or fixing it) for mocking
node:timersbuilt-in module is just a feature. But to mock those by default inuseFakeTimers()is breaking change.Nokel81 commentedon Aug 17, 2026
Fair enough, I would be fine if I could say
useFakeTimers({ toFake: ["node:timers", "node:timers/promises"] })hi-ogawa commentedon Aug 21, 2026
We discussed and are going to implement
fakeNodeBuiltinsflag like:We can introduce as default
falseto be non breaking change. Then in the future, can enable default true in Vitest 6.