Skip to content
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

fix(coverage): env-replacer to remove query params from sourcemaps filenames #2584

Merged
merged 2 commits into from Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Expand Up @@ -70,6 +70,7 @@ exports[`c8 json report 1`] = `
"0": 1,
"1": 0,
"2": 2,
"3": 0,
},
"fnMap": {
"0": {
Expand Down Expand Up @@ -144,6 +145,30 @@ exports[`c8 json report 1`] = `
},
"name": "coveredMethod",
},
"3": {
"decl": {
"end": {
"column": 6,
"line": 22,
},
"start": {
"column": 4,
"line": 20,
},
},
"line": 20,
"loc": {
"end": {
"column": 6,
"line": 22,
},
"start": {
"column": 4,
"line": 20,
},
},
"name": "uncoveredMethodUsingImportMeta",
},
},
"path": "<process-cwd>/src/Counter/Counter.component.ts",
"s": {
Expand All @@ -160,6 +185,10 @@ exports[`c8 json report 1`] = `
"18": 1,
"19": 1,
"2": 1,
"20": 0,
"21": 0,
"22": 1,
"23": 1,
"3": 1,
"4": 1,
"5": 1,
Expand Down Expand Up @@ -271,7 +300,7 @@ exports[`c8 json report 1`] = `
},
"18": {
"end": {
"column": 4,
"column": 0,
"line": 19,
},
"start": {
Expand All @@ -281,7 +310,7 @@ exports[`c8 json report 1`] = `
},
"19": {
"end": {
"column": 2,
"column": 38,
"line": 20,
},
"start": {
Expand All @@ -299,6 +328,46 @@ exports[`c8 json report 1`] = `
"line": 3,
},
},
"20": {
"end": {
"column": 94,
"line": 21,
},
"start": {
"column": 0,
"line": 21,
},
},
"21": {
"end": {
"column": 6,
"line": 22,
},
"start": {
"column": 0,
"line": 22,
},
},
"22": {
"end": {
"column": 4,
"line": 23,
},
"start": {
"column": 0,
"line": 23,
},
},
"23": {
"end": {
"column": 2,
"line": 24,
},
"start": {
"column": 0,
"line": 24,
},
},
"3": {
"end": {
"column": 18,
Expand Down
Expand Up @@ -9,6 +9,7 @@ exports[`istanbul json report 1`] = `
"0": 1,
"1": 0,
"2": 2,
"3": 0,
},
"fnMap": {
"0": {
Expand Down Expand Up @@ -80,13 +81,37 @@ exports[`istanbul json report 1`] = `
},
"name": "(anonymous_2)",
},
"3": {
"decl": {
"end": {
"column": 37,
"line": 20,
},
"start": {
"column": 4,
"line": 20,
},
},
"loc": {
"end": {
"column": null,
"line": 22,
},
"start": {
"column": 37,
"line": 20,
},
},
"name": "(anonymous_3)",
},
},
"path": "<process-cwd>/src/Counter/Counter.component.ts",
"s": {
"0": 1,
"1": 1,
"2": 0,
"3": 2,
"4": 0,
},
"statementMap": {
"0": {
Expand Down Expand Up @@ -129,6 +154,16 @@ exports[`istanbul json report 1`] = `
"line": 17,
},
},
"4": {
"end": {
"column": null,
"line": 21,
},
"start": {
"column": 6,
"line": 21,
},
},
},
},
"<process-cwd>/src/Counter/Counter.vue": {
Expand Down
4 changes: 4 additions & 0 deletions test/coverage-test/src/Counter/Counter.component.ts
Expand Up @@ -16,5 +16,9 @@ export default defineComponent({
coveredMethod() {
return 'This line should be covered'
},

uncoveredMethodUsingImportMeta() {
return `Source maps tend to break when import meta is used: ${import.meta.env.BASE_URL}`
},
},
})