vitest-dev / vitest-dev/vitest

Calling sinon.useFakeTimers() inside a test causes Vitest to hang

Open
#7,790 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.