-
-
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
new URL(..., import.meta.url)
is not resolved in test files since 0.34
#3935
Comments
I was able to trace down the cause of this regression to the PR implementing would it be possible to have the |
new URL(..., import.meta.url)
is not resolved in test files 0.34new URL(..., import.meta.url)
is not resolved in test files since 0.34
I don't see the problem here. When running in Node.js the URL has the correct schema: |
This is an intentional change that was made to support |
I didn't realize that Vitest was doing its own thing for web workers on top of Vite - I tried setting up a web worker using the export const monaco = new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url)); but that gives the following error in Vitest 0.33:
In 0.34, the path is different, but the worker still fails:
|
The |
Describe the bug
Prior to Vitest 0.34, when using the
'jsdom'
environment, I was able to write components that imported assets using thenew URL('@my-styleguide/brand/logo.png', import.meta.url)
syntax, and the resulting paths would run through a resolver, and ultimately render as URLs resemblinghttps://localhost:3000/@fs/.../node_modules/@my-styleguide/brand/logo.png
. Since we use snapshot testing, I used a resolver hook to normalize these URLs into consistent URLs relative to the monorepo project root.However, since 0.34, this transformation is no longer happening and URLs all resolve with
file:///
. This usually only happens in 0.33 when thessr
transform mode is used.There's another potentially related issue in Vite where dependencies optimized through esbuild don't have their
new URL(..., import.meta.url)
expressions transformed:vitejs/vite#8427
Reproduction
https://github.com/kherock/vitest-new-url-bug
To reproduce the issue in the repo above, clone it, and upgrade it to vitest 0.34 by running
npm i -D vitest@0.34
.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: