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): respect source maps of pre-transpiled sources #5367

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
2 changes: 2 additions & 0 deletions eslint.config.js
Expand Up @@ -15,6 +15,8 @@ export default antfu(
'test/workspaces/results.json',
'test/reporters/fixtures/with-syntax-error.test.js',
'test/network-imports/public/slash@3.0.0.js',
'test/coverage-test/src/transpiled.js',
'test/coverage-test/src/original.ts',
'examples/**/mockServiceWorker.js',
'examples/sveltekit/.svelte-kit',
],
Expand Down
6 changes: 5 additions & 1 deletion packages/coverage-v8/src/provider.ts
Expand Up @@ -323,14 +323,18 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
}
}

const sources = [url]
if (map.sources && map.sources[0] && !url.endsWith(map.sources[0]))
sources[0] = new URL(map.sources[0], url).href

return {
originalSource: sourcesContent,
source: code || sourcesContent,
sourceMap: {
sourcemap: excludeGeneratedCode(code, {
...map,
version: 3,
sources: [url],
sources,
sourcesContent: [sourcesContent],
}),
},
Expand Down
Expand Up @@ -29,6 +29,7 @@ exports[`custom json report 1`] = `
"<process-cwd>/src/index.mts",
"<process-cwd>/src/multi-environment.ts",
"<process-cwd>/src/multi-suite.ts",
"<process-cwd>/src/transpiled.js",
"<process-cwd>/src/utils.ts",
],
}
Expand Down