Describe the bug
Prior to Vitest 0.34, when using the 'jsdom' environment, I was able to write components that imported assets using the new URL('@my-styleguide/brand/logo.png', import.meta.url) syntax, and the resulting paths would run through a resolver, and ultimately render as URLs resembling https://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 the ssr 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
System:
OS: macOS 13.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 48.28 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 16.20.1 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.19.4 - /opt/homebrew/bin/npm
Browsers:
Chrome: 115.0.5790.170
Firefox: 102.12.0
Safari: 16.5.1
npmPackages:
vite: ^4.4.9 => 4.4.9
vitest: ^0.34.1 => 0.34.1
Used Package Manager
npm
Validations
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 thessrtransform 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
System: OS: macOS 13.4.1 CPU: (10) arm64 Apple M1 Pro Memory: 48.28 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.20.1 - /opt/homebrew/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.19.4 - /opt/homebrew/bin/npm Browsers: Chrome: 115.0.5790.170 Firefox: 102.12.0 Safari: 16.5.1 npmPackages: vite: ^4.4.9 => 4.4.9 vitest: ^0.34.1 => 0.34.1Used Package Manager
npm
Validations