Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition in test runner when using "define" in the vite configuration #6976

Open
6 tasks done
timothympace opened this issue Nov 27, 2024 · 0 comments
Open
6 tasks done

Comments

@timothympace
Copy link

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.6

Used Package Manager

pnpm

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant