Skip to content

Commit

Permalink
fix(coverage): respect source maps of pre-transpiled sources (#5367)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Mar 12, 2024
1 parent 6d1b145 commit 6eda473
Show file tree
Hide file tree
Showing 10 changed files with 978 additions and 1 deletion.
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
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/[email protected]',
'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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 6eda473

Please sign in to comment.