Skip to content

feat: support fake timers for node:timers and node:timers/promise - #10899

Draft
hi-ogawa wants to merge 3 commits into
vitest-dev:mainfrom
hi-ogawa:fix/issue-10871
Draft

feat: support fake timers for node:timers and node:timers/promise#10899
hi-ogawa wants to merge 3 commits into
vitest-dev:mainfrom
hi-ogawa:fix/issue-10871

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Description

TODO

  • docs
  • simplify patches

Apparently, the doc has never mentioned the mocking behavior for node builtin node:timers mocking, so need to discuss whether this is intended. Also update doc accordingly.


There were multiple issues with previous approach:

  • stashing timersModule = __vitest_required__.timers (and async timer variant) runs during fake timer module scope and __vitest_required__ wasn't setup yet at that point.
  • __vitest_required__.timers is originally import timers from "node:timers" and this only patches default/cjs exports objects. In order to propagate the mocking to named imports import { setTimeout } from "node:timers", we can use node's syncBuiltinESMExports module util.

This PR fixes them by patching fake-timers more and wire-up syncBuiltinESMExports for normal runner and vm runner separately.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

hi-ogawa and others added 3 commits August 10, 2026 11:20
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
@hi-ogawa hi-ogawa changed the title Fix/issue 10871 fix: fix fake timers for node:timers and node:timers/promise Aug 10, 2026
@netlify

netlify Bot commented Aug 10, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c188b52
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a793d3e15f89700088e7ec4
😎 Deploy Preview https://deploy-preview-10899--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa changed the title fix: fix fake timers for node:timers and node:timers/promise fix: support fake timers for node:timers and node:timers/promise Aug 10, 2026
@hi-ogawa hi-ogawa changed the title fix: support fake timers for node:timers and node:timers/promise feat!: support fake timers for node:timers and node:timers/promise Aug 10, 2026
@hi-ogawa hi-ogawa changed the title feat!: support fake timers for node:timers and node:timers/promise feat: support fake timers for node:timers and node:timers/promise Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use fakeTimers does not mock imports from node:timers or node:timers/promises

1 participant