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

Undefined define constants error when --pool=forks #5273

Closed
6 tasks done
IanVS opened this issue Feb 22, 2024 · 1 comment · Fixed by #5284
Closed
6 tasks done

Undefined define constants error when --pool=forks #5273

IanVS opened this issue Feb 22, 2024 · 1 comment · Fixed by #5284
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@IanVS
Copy link
Contributor

IanVS commented Feb 22, 2024

Describe the bug

I attempted to set --pool='forks' to debug some hanging tests that I've been having intermittently, and started to get a few test failures about global constants not being defined. I'm guessing it's a consequence of running the tests using child_process, but it surprised me a bit nonetheless.

I'm not sure if anything can be done to address this from vitest, but it might be worth at the very least adding a note in the documentation to clarify that define values should not be undefined?

Reproduction

https://github.com/IanVS/reproduction-vitest-define-pool-forks

System Info

System:
    OS: macOS 14.0
    CPU: (12) arm64 Apple M2 Max
    Memory: 1.81 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/Library/Caches/fnm_multishells/35181_1708624240853/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/35181_1708624240853/bin/yarn
    npm: 9.5.1 - ~/Library/Caches/fnm_multishells/35181_1708624240853/bin/npm
    pnpm: 8.8.0 - ~/Library/Caches/fnm_multishells/35181_1708624240853/bin/pnpm
  Browsers:
    Safari: 17.0
  npmPackages:
    vite: ^5.1.4 => 5.1.4
    vitest: ^1.3.1 => 1.3.1

Used Package Manager

pnpm

Validations

@AriPerkkio
Copy link
Member

AriPerkkio commented Feb 22, 2024

The difference between these two pools is that child_process uses node:v8.serialize when it's passing the configuration to worker. It seems to lose objects with undefined values - similar as JSON.stringify does. If you change the configuration to define: { __GLOBAL__: 123 } you can see that it is passed.

We already have some work-arounds when passing regexps to test runners through node:v8.serialize. I think similar approach could be used here.

@AriPerkkio AriPerkkio added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Feb 22, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants