vitest-dev / vitest-dev/vitest
Calling sinon.useFakeTimers() inside a test causes Vitest to hang
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
Calling sinon.useFakeTimers() in a test causes the test to hang:
> test
> vitest
DEV v3.1.1 /Users/josh/repos/repros
❯ index.test.js 0/1
Test Files 0 passed (1)
Tests 0 passed (1)
Start at 09:26:11
Duration 12.34s
After a minute it exits with an error:
DEV v3.1.1 /Users/josh/repos/repros
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: [vitest-worker]: Timeout calling "snapshotSaved"
❯ Object.onTimeoutError node_modules/vitest/dist/chunks/rpc.DGgL5dw7.js:62:10
❯ Timeout._onTimeout node_modules/vitest/dist/chunks/index.68735LiX.js:55:41
❯ listOnTimeout node:internal/timers:594:17
❯ processTimers node:internal/timers:529:7
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Test Files (1)
Tests (1)
Errors 1 error
Start at 09:27:40
Duration 60.19s (transform 11ms, setup 0ms, collect 17ms, tests 0ms, environment 0ms, prepare 36ms)
Reproduction
Minimum reproduction: https://github.com/JoshuaKGoldberg/repros/tree/vitest-hanging-with-sinon-useFakeTimers
The full use case is a package that wraps a Sinon API: https://github.com/JoshuaKGoldberg/sinon-timers-repeatable/pull/894
System Info
System:
OS: macOS 13.2
CPU: (10) arm64 Apple M1 Max
Memory: 132.53 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
pnpm: 10.6.1 - ~/.nvm/versions/node/v22.12.0/bin/pnpm
Browsers:
Chrome: 134.0.6998.166
Safari: 16.3
npmPackages:
vitest: ^3.1.1 => 3.1.1
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the minimal reproduction from the linked vitest-hanging-with-sinon-useFakeTimers repository with Vitest 3.1.1 and sinon.useFakeTimers(). Trace the worker RPC path around the reported snapshotSaved timeout, then add a regression test showing the test run completes without hanging or timing out.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100