-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Describe the bug
I've come across what appears to be a race condition in the vitest test runner. It occurs when using the define configuration option in the vitest config and then referencing a variable defined through it in the import tree of a test file.
I'm not positive of the conditions that reproduce this, but I was able to get a minimal reproduction (linked below). Unfortunately, it can take A LOT of runs (I'm seeing within 30 minutes of repeatedly running the test command) for it to choke, hence why I believe it's race condition.
The best I can tell is that this happens when there is some non-trivial period of time spent importing/resolving/parsing modules in the import path and then referencing a variable in the define from there. The reproduction does this with an artificial delay in a shared file that all the tests import, with some random amount of wait time in it (scoped to a min/max that seems to best reproduce it)
Reproduction
See: https://github.com/timothympace/vitest-define-bug
There is info in the README, but I'll also copy paste it here:
Steps to reproduce
Run:
pnpm repro-bug
Wait for failure. It could take A LOT of runs. I've seen it take up to 30 minutes to reproduce, and it wouldn't shock me if it takes hours even.
System Info
System:
OS: macOS 15.1.1
CPU: (10) arm64 Apple M1 Max
Memory: 240.14 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.2.0 - ~/Library/Caches/fnm_multishells/22284_1732553878425/bin/node
Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/22284_1732553878425/bin/yarn
npm: 9.6.6 - ~/Library/Caches/fnm_multishells/22284_1732553878425/bin/npm
pnpm: 9.5.0 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 131.0.6778.86
Safari: 18.1.1
npmPackages:
vitest: ^2.1.6 => 2.1.6Used Package Manager
pnpm
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.