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
Relative paths in test.alias
cause uncovered files in c8
reports
#2425
Comments
Does it matter what file is in vitest/packages/vite-node/src/client.ts Line 323 in d424c1f
|
Changing the But the vitest/packages/vite-node/src/client.ts Lines 347 to 351 in d424c1f
The Relative Path{ "test": { "alias": "@some-alias": "./src" } } const __vite_ssr_import_1__ = await __vite_ssr_import__("/@id/src/math"); vm.runInThisContext(code, {
filename: "src/math",
lineOffset: 0,
columnOffset: -codeDefinition.length,
}) {
"scriptId": "761",
"url": "src/math", // Not OK
"functions": [...] Absolute path{ test: { alias: "@some-alias": path.resolve("./src") } } const __vite_ssr_import_1__ = await __vite_ssr_import__("/src/math.ts"); vm.runInThisContext(code, {
filename: "/Users/x/y/vitest-c8-test-alias/src/math.ts",
lineOffset: 0,
columnOffset: -codeDefinition.length,
}) {
"scriptId": "761",
"url": "file:///Users/x/y/vitest-c8-test-alias/src/math.ts", // Works OK
"functions": [ |
And can we do something about it? I am not sure it's Vitest responsibility, since we fully rely on Vite 🤔 But it's maybe also out of scope for Vite, because everything works fine there 😄 Maybe we need to ask Vite people how they figure out what to do with |
It seems they unwrap it: Maybe we also just need to remove if (id.startsWith('/@id/')
fsPath = await resolveId(fsPath) // I am using fsPath, because it's normalised already |
Move vitest/packages/vite-node/src/client.ts Line 196 in d424c1f
const request = async (dep: string) => {
+ if (dep.startsWith('/@id/')) {
+ console.log('dep before', dep)
+ dep = await resolveId(dep.replace('/@id', ''))
+ console.log('dep now', dep)
+ }
const depFsPath = toFilePath(normalizeRequestId(dep, this.options.base), this.root)
|
Maybe we can even use |
We don't need to change |
@AriPerkkio can you check #2439? I didn't unwrap ID, but it still seems to work. |
Describe the bug
There has been couple of reports that
c8
coverage reports can be missing files. I finally received a reproduction repository and was able to debug this issue.If user configures
test.alias
using relative paths, the coverage report fromc8
can be missing files that are imported using the aliased path. Using absolute paths intest.alias
works always. Does this look like a bug inrollup-plugin-alias
or something that could be handled on Vitest's or Vite's side?Relative path
Tests run OK. Coverage report is empty.
The
rollup-plugin-alias
used by Vite is here returning{ id: './src/math' }
forresolveId('@some-alias/math')
.The final transformed test case contains following import:
The V8 coverage reports contain paths which are not File URLs.
c8
does not pick these up.Absolute path
Coverage report is complete.
Here
rollup-plugin-alias
is returning full path, including extension,{ id: '/Users/x/y/vitest-c8-test-alias/src/math.ts' }
forresolveId('@some-alias/math')
.The final transformed test case contains following import:
The V8 coverage reports contain File URLs now.
c8
can process these successfully:Reproduction
Make sure you download this as
c8
does not work on Stackblitz: https://stackblitz.com/edit/vitest-dev-vitest-n4nrrsSystem Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: