Skip to content

Commit 45d199c

Browse files
authored
fix(coverage): prevent duplicate metrics caused by source map end column differences (#12040)
1 parent c8b7d15 commit 45d199c

7 files changed

Lines changed: 117 additions & 46 deletions

File tree

‎packages/coverage-istanbul/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
},
5050
"dependencies": {
5151
"@vitest/istanbul-lib-coverage": "catalog:",
52-
"@vitest/istanbul-lib-instrument": "^2.1.0",
52+
"@vitest/istanbul-lib-instrument": "^2.1.1",
5353
"@vitest/istanbul-lib-report": "catalog:",
54-
"@vitest/istanbul-lib-source-maps": "^2.1.0",
54+
"@vitest/istanbul-lib-source-maps": "^2.1.1",
5555
"magicast": "catalog:",
5656
"obug": "catalog:",
5757
"tinyrainbow": "catalog:"

‎pnpm-lock.yaml‎

Lines changed: 32 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ catalog:
6565
'@types/yauzl': ^3.4.0
6666
'@unocss/reset': ^66.12.0
6767
'@vitejs/plugin-vue': ^6.0.10
68-
'@vitest/istanbul-lib-coverage': ^2.1.0
69-
'@vitest/istanbul-lib-report': ^2.1.0
68+
'@vitest/istanbul-lib-coverage': ^2.1.1
69+
'@vitest/istanbul-lib-report': ^2.1.1
7070
'@vueuse/core': ^14.4.0
7171
acorn-walk: ^8.3.5
7272
ansivision: ^0.4.0
@@ -138,10 +138,10 @@ minimumReleaseAgeExclude:
138138
- '@rolldown/binding-openharmony-arm64@1.2.14'
139139
- '@rolldown/binding-win32-arm64-msvc@1.2.14'
140140
- '@rolldown/binding-win32-x64-msvc@1.2.14'
141-
- '@vitest/istanbul-lib-coverage@2.1.0'
142-
- '@vitest/istanbul-lib-instrument@2.1.0'
143-
- '@vitest/istanbul-lib-report@2.1.0'
144-
- '@vitest/istanbul-lib-source-maps@2.1.0'
141+
- '@vitest/istanbul-lib-coverage@2.1.1'
142+
- '@vitest/istanbul-lib-instrument@2.1.1'
143+
- '@vitest/istanbul-lib-report@2.1.1'
144+
- '@vitest/istanbul-lib-source-maps@2.1.1'
145145
- jsdom@30.1.3
146146
- playwright-core@1.64.1
147147
- playwright@1.64.1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function useThing() {
2+
return { label: 'world' }
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useThing } from './end-mapping-dependency'
2+
3+
export function greet() {
4+
const { label } = useThing()
5+
return `Hello ${label}`
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, test } from 'vitest'
2+
import { greet } from '../src/end-mapping'
3+
4+
test('greet', () => {
5+
expect(greet()).toBe('Hello world')
6+
})

‎test/coverage-test/test/source-maps.test.ts‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { playwright } from '@vitest/browser-playwright'
12
import { expect } from 'vitest'
2-
import { runVitest, test } from '../utils'
3+
import { isBrowser, isNativeRunner, isV8Provider, readCoverageMap, runVitest, test } from '../utils'
34

45
test('errors point to correct location', async () => {
56
const { stderr } = await runVitest(
@@ -21,3 +22,63 @@ test('errors point to correct location', async () => {
2122
`.trim(),
2223
)
2324
})
25+
26+
test('statements are merged when environments produce different end mappings (#9366, #11921)', async ({
27+
skip,
28+
}) => {
29+
skip(isBrowser(), 'test defines its own browser project')
30+
skip(isNativeRunner(), 'v8 provider already covered')
31+
32+
await runVitest({
33+
coverage: {
34+
reporter: 'json',
35+
include: ['fixtures/src/end-mapping.ts'],
36+
},
37+
projects: [
38+
{
39+
test: {
40+
name: 'jsdom',
41+
environment: 'jsdom',
42+
include: ['fixtures/test/end-mapping-fixture.test.ts'],
43+
},
44+
},
45+
{
46+
test: {
47+
name: 'browser',
48+
include: ['fixtures/test/end-mapping-fixture.test.ts'],
49+
browser: {
50+
enabled: true,
51+
headless: true,
52+
provider: playwright(),
53+
instances: [{ browser: 'chromium' }],
54+
},
55+
},
56+
},
57+
],
58+
})
59+
60+
const coverageMap = await readCoverageMap()
61+
const fileCoverage = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/end-mapping.ts')
62+
63+
const statements = Object.entries(fileCoverage.statementMap).map(
64+
([id, { start, end }]) =>
65+
`${start.line}:${start.column} - ${end.line}:${end.column} = ${fileCoverage.s[id]}`,
66+
)
67+
68+
// Each statement should be reported once, with hits from both projects.
69+
if (isV8Provider()) {
70+
expect(statements).toMatchInlineSnapshot(`
71+
[
72+
"4:20 - 4:29 = 2",
73+
"5:2 - 5:null = 2",
74+
]
75+
`)
76+
} else {
77+
expect(statements).toMatchInlineSnapshot(`
78+
[
79+
"4:20 - 4:null = 2",
80+
"5:2 - 5:null = 2",
81+
]
82+
`)
83+
}
84+
})

0 commit comments

Comments
 (0)