vitest-dev / vscode

VS Code extension for Vitest
https://vitest.dev/vscode
MIT License
736 stars 83 forks source link

Extension setupFile.mjs fails to load when other setupFiles provided in a multi-project setting #347

Closed roryschadler closed 4 months ago

roryschadler commented 4 months ago

Describe the bug

When I run yarn test in this reproduction repo, the tests run as expected. When I use this extension to run the tests, the tests under typescript-project/server run fine, but those under typescript-project/client fail with the error below.

I get the same error if I remove the middleman typescript-project directory, and work in a plain two-project monorepo. I wonder if the issue is related to this comment under vite's server.fs.allow section:

When server.fs.allow is specified, the auto workspace root detection will be disabled. To extend the original behavior, a utility searchForWorkspaceRoot is exposed...

Reproduction

https://github.com/roryschadler/vitest-non-root-monorepo

Output

# Vitest Output Channel

[INFO 12:29:06 PM] [v0.6.1] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 12:29:06 PM] [API] Running Vitest: v1.5.0 (/Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/vitest.workspace.ts)
[INFO 12:29:07 PM] [API] Vitest process 6638 created
[INFO 12:29:10 PM] Running 1 file(s): /Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/
[INFO 12:38:41 PM] Running 1 file(s): /Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/
[INFO 12:39:00 PM] Running 1 file(s): /Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/

---

# Error from test results

Error: Failed to load url /Users/roryschadler/.vscode/extensions/vitest.explorer-0.6.1/dist/setupFile.mjs (resolved id: /Users/roryschadler/.vscode/extensions/vitest.explorer-0.6.1/dist/setupFile.mjs). Does the file exist?
    at loadAndTransform (file:///Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:53736:21)
    at async ViteNodeServer._transformRequest (file:///Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/node_modules/vite-node/dist/server.mjs:409:16)
    at async ViteNodeServer._fetchModule (file:///Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/node_modules/vite-node/dist/server.mjs:379:17)
    at async MessagePort.<anonymous> (file:///Users/roryschadler/testing/vitest-non-root-monorepo/typescript-project/node_modules/vitest/dist/vendor/index.8bPxjt7g.js:65:20)

Version

v0.6.1

Validations

NickM54 commented 4 months ago

I just installed the latest update and just started to run into this issue as well. One thing I noticed is this just started happening after I tried the Run test with Coverage option.

sheremet-va commented 4 months ago

Thank you for the reproduction! I found the error now.

roryschadler commented 4 months ago

Thank you for the speedy fix again @sheremet-va! v0.6.2 resolves the issue.