Skip to content

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

Merged
sheremet-va merged 24 commits into
vitest-dev:mainfrom
hi-ogawa:fix/issue-10871
Oct 19, 2026
Merged

sheremet-va merged 24 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

There were multiple issues with previous code:

  • timersModule = __vitest_required__.timers and timersPromiseModule were stashed during fake timer module scope but __vitest_required__ wasn't setup yet at that point.
  • __vitest_required__.timers is originally import timers from "node:timers" and this only patches esm-default and 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 and also guards node builtin mocking capability under new useFakeTimers({ fakeNodeBuiltins: true }) option.

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 4 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>
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 ea4fd58
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6ad5e901404d0a632f32b217
😎 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
hi-ogawa and others added 16 commits September 1, 2026 10:23
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
@hi-ogawa
hi-ogawa marked this pull request as ready for review September 1, 2026 05:37
hi-ogawa and others added 2 commits September 1, 2026 14:37
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
@hi-ogawa hi-ogawa added this to the 5.1.0 milestone Sep 16, 2026
Co-authored-by: Codex (GPT-6) <noreply@openai.com>
@sheremet-va

Copy link
Copy Markdown
Member

Conflict! 😢

# Conflicts:
#	packages/vitest/src/integrations/mock/timers.ts
#	packages/vitest/src/integrations/vi.ts
@hi-ogawa
hi-ogawa requested a review from sheremet-va October 19, 2026 10:09
@sheremet-va
sheremet-va merged commit fbe973c into vitest-dev:main Oct 19, 2026
29 checks passed
@hi-ogawa
hi-ogawa deleted the fix/issue-10871 branch October 20, 2026 01:01
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

2 participants