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
jsdom loading issue if threads false #835
Comments
Having the same issues with |
When the teardown runs (when threads are disabled), it breaks JSDOM It turns out that the teardown function is never called when running with threads enabled, so this issue went unnoticed for most developers. Fixes vitest-dev#835 The PR can be tested by running: ``` cd examples/vue pnpm run test -- --no-threads ``` This fails on `main` but no longer fails with this commit.
I tried to dig a bit more into this issue, and it turns out that the teardown function of the jsdom environment is never called when running with threads vitest/packages/vitest/src/integrations/env/jsdom.ts Lines 61 to 63 in cf226c5
This is because the worker pool never finishes and the finally here is never calledvitest/packages/vitest/src/runtime/setup.ts Lines 148 to 154 in cf226c5
It is only called with threads disabled (when there is no pool), and that leads to inconsistencies between the two modes. The same probably happens with the other environments like happy-dom as well. TL;DR:
|
I think one of the problems is tests using the same Also, I agree, teardown function may need improvement. I found that it already has |
Also, I want to point out that Vitest treats workers differently than Jest. Jest provides isolation with Please, don't expect |
@sheremet-va Thanks for your feedback. Yeah, I was trying to fix CI issues that occur since vitest 0.7+, and thought that If I understand correctly #1102, we would need to call |
It is called automatically. I've tried calling it in your repro, and came to this conclusion: I found that vue uses cached
I guess what happens is vue plugin imports some instance of vue, which gets cached and is returned every time. It's fine if it was |
So, to paint a full picture:
This is all tested on |
I have tried clearing the cache entirely and/or depending on what was required in So, as a patch solution, I propose But I guess it will only be usefull with WDYT, @antfu @patak-dev? |
Any news on this @antfu @patak-dev @sheremet-va? I'm experiencing a similar problem using Let me know if I can provide any additional information 👍 |
So, with This is usually ok, if you don't use For example, we can group files by different environments. We can also clear caches of dependencies that rely on having |
I also want to point out that I don't recommend using I guess usually, if you don't rely on some global variable, and cleanup/unmount after each test, it should be ok. But disable |
Describe the bug
Issue
When starting vitest with
threads: false
tests fail with:Cannot read properties of undefined (reading 'child')
The same test run while usingthreads: true
.Possible Causes
The test uses the @vue/test-utils package for component testing. These must be loaded after jsdom is loaded and the DOM is provided. (see this issue).
Failed workarounds
I tried loading jsdom via jsdom-global myself in a global setup hook, so far to no avail.
Reproduction
vite.config.js
Component.spec.js
Component.vue
setup
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: