-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Snapshots do not work with Yarn PnP #3426
Comments
https://github.com/koistya/vitest-workspaces
vitest/packages/snapshot/src/client.ts Lines 132 to 141 in 02dc9ea
^^^ |
And the previously initialized |
|
As long as all the "vitest" peer dependencies in all Yarn workspaces match exactly, there is a single instance of "vitest" (virtual) package and Vitest works as expected. |
Not sure what can be done here? Why does yarn create separate Vite instances? |
@sheremet-va PnP is more strict in regard to dependency resolution, if the same module has different peer dependencies it cannot be safely used from under different workspaces with their own set of peer dependencies for such module, because of the potential side effects. E.g. one workspace has "happy-dom" dependency, while the other doesn't.
In a multi-workspace scenario (via |
"easily" is a stretch, but I think I can find a way to fix that. Vitest always loads the "test runner" from the root Vitest:
If we can resolve it for each workspace, then it should fix the error. |
@sheremet-va Interestingly, when tests are being executed Vitest uses the correct instances of "vitest", but this particular hook is being run from under the (root?) instance of vitest: |
Vitest always uses the root worker to run tests (we can't change that), so
But when it runs tests, Vitest is resolved relative to the file it is imported from. If we resolve entry to the correct Vitest package, this should fix the error. You can already try this with something like this: const rootHtml = join(config.root, 'index.html')
const { id: vitestEntry } = await rpc().resolveId('vitest/dist/entry.js', rootHtml, 'node')
const { run } = await import(vitestEntry) |
@sheremet-va I'm testing with Vitest 0.32.0 and this issue still remains: https://github.com/koistya/vitest-workspaces
|
@sheremet-va We're on Vitest 0.34.4 and this issue still remains. We're using NX to orchestrate our monorepo. As a workaround I found that I can remove vitest from root package.json - and it looks like it's working. But then of course I get:
But is very brittle for example |
I just updated to v0.34.5 with pnpm and seeing something very similar. I can try to set up a repro if that would help... |
Update: ah, I just got a mismatch between |
Describe the bug
Reproduction
yarn config set pnp
)yarn vitest
It only works if all the peer dependencies in all Vitest workspaces match exactly, otherwise Yarn creates a separate virtual folder for each
vitest
instance which breaks the way Vitest works with inline snapshots. It looks like snapshot initialization happens in one "vitest" instance, while the test result matching uses a different "vitest" instance.You can check virtual packages using
yarn info --virtuals vitest
command, or by looking up forvitest-virtual
occurrences in.pnp.cjs
.Reproduction: https://github.com/koistya/vitest-workspaces
Referene: https://yarnpkg.com/advanced/pnp-spec#virtual-folders
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: