Skip to content

Commit 6eda473

Browse files
authored
fix(coverage): respect source maps of pre-transpiled sources (#5367)
1 parent 6d1b145 commit 6eda473

File tree

10 files changed

+978
-1
lines changed

10 files changed

+978
-1
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export default antfu(
1515
'test/workspaces/results.json',
1616
'test/reporters/fixtures/with-syntax-error.test.js',
1717
'test/network-imports/public/slash@3.0.0.js',
18+
'test/coverage-test/src/transpiled.js',
19+
'test/coverage-test/src/original.ts',
1820
'examples/**/mockServiceWorker.js',
1921
'examples/sveltekit/.svelte-kit',
2022
],

packages/coverage-v8/src/provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,18 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
323323
}
324324
}
325325

326+
const sources = [url]
327+
if (map.sources && map.sources[0] && !url.endsWith(map.sources[0]))
328+
sources[0] = new URL(map.sources[0], url).href
329+
326330
return {
327331
originalSource: sourcesContent,
328332
source: code || sourcesContent,
329333
sourceMap: {
330334
sourcemap: excludeGeneratedCode(code, {
331335
...map,
332336
version: 3,
333-
sources: [url],
337+
sources,
334338
sourcesContent: [sourcesContent],
335339
}),
336340
},

test/coverage-test/coverage-report-tests/__snapshots__/custom.report.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ exports[`custom json report 1`] = `
2929
"<process-cwd>/src/index.mts",
3030
"<process-cwd>/src/multi-environment.ts",
3131
"<process-cwd>/src/multi-suite.ts",
32+
"<process-cwd>/src/transpiled.js",
3233
"<process-cwd>/src/utils.ts",
3334
],
3435
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy