Skip to content

Commit

Permalink
fix(coverage): env-replacer to remove query params from sourcemaps
Browse files Browse the repository at this point in the history
- Fixes bugs where vue components lost coverage when import.meta.env is used
  • Loading branch information
AriPerkkio committed Dec 31, 2022
1 parent 548bd49 commit 7a972b8
Show file tree
Hide file tree
Showing 2 changed files with 427 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/vitest/src/node/plugins/envReplacer.ts
@@ -1,6 +1,7 @@
import MagicString from 'magic-string'
import type { Plugin } from 'vite'
import { stripLiteral } from 'strip-literal'
import { cleanUrl } from 'vite-node/utils'

// so people can reassign envs at runtime
// import.meta.env.VITE_NAME = 'app' -> process.env.VITE_NAME = 'app'
Expand All @@ -27,7 +28,12 @@ export const EnvReplacerPlugin = (): Plugin => {
if (s) {
return {
code: s.toString(),
map: s.generateMap({ hires: true, source: id }),
map: s.generateMap({
hires: true,

// Remove possible query parameters, e.g. vue's "?vue&type=script&src=true&lang.ts"
source: cleanUrl(id),
}),
}
}
},
Expand Down

0 comments on commit 7a972b8

Please sign in to comment.