Skip to content

Commit cd871dd

Browse files
committed
feat(coverage): support ignore start/end ignore hints
1 parent 300648f commit cd871dd

5 files changed

Lines changed: 48 additions & 21 deletions

File tree

packages/coverage-v8/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"dependencies": {
5757
"@bcoe/v8-coverage": "^1.0.2",
5858
"@vitest/utils": "workspace:*",
59-
"ast-v8-to-istanbul": "^0.3.8",
59+
"ast-v8-to-istanbul": "https://pkg.pr.new/AriPerkkio/ast-v8-to-istanbul@109",
6060
"istanbul-lib-coverage": "catalog:",
6161
"istanbul-lib-report": "catalog:",
6262
"istanbul-lib-source-maps": "catalog:",

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ overrides:
2828
'@vitest/browser-webdriverio': 'workspace:*'
2929
'@vitest/ui': 'workspace:*'
3030
acorn: 8.11.3
31+
istanbul-lib-source-maps: 'file:../istanbuljs/packages/istanbul-lib-source-maps'
3132
mlly: ^1.8.0
3233
rollup: $rollup
3334
vite: $vite

test/coverage-test/fixtures/src/ignore-hints.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ export function second() {
88
return "Second"
99
}
1010

11+
/* istanbul ignore start */
12+
export function third() {
13+
return "Third"
14+
}
15+
16+
export function fourth() {
17+
return "fourh"
18+
}
19+
/* istanbul ignore end */
20+
1121
// Covered line
1222
second()
1323

@@ -16,3 +26,5 @@ second()
1626

1727
/* istanbul ignore next -- @preserve, Uncovered line istanbul */
1828
second()
29+
30+
fourth()

test/coverage-test/test/ignore-hints.test.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,30 @@ test('ignore hints work', async () => {
1616
const fileCoverage = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/ignore-hints.ts')
1717
const lines = fileCoverage.getLineCoverage()
1818

19+
// Covered
1920
expect(lines[8]).toBeGreaterThanOrEqual(1)
20-
expect(lines[12]).toBeGreaterThanOrEqual(1)
21+
expect(lines[22]).toBeGreaterThanOrEqual(1)
22+
expect(lines[30]).toBeGreaterThanOrEqual(1)
2123

24+
// Ignored start+end lines
25+
expect(lines[11]).toBeUndefined()
26+
expect(lines[12]).toBeUndefined()
27+
expect(lines[13]).toBeUndefined()
28+
expect(lines[14]).toBeUndefined()
29+
expect(lines[15]).toBeUndefined()
30+
expect(lines[16]).toBeUndefined()
31+
expect(lines[17]).toBeUndefined()
32+
expect(lines[18]).toBeUndefined()
33+
expect(lines[19]).toBeUndefined()
34+
35+
// Ignore istanbul
36+
expect(lines[28]).toBeUndefined()
37+
38+
// Line 25 = Ignore v8
2239
if (isV8Provider()) {
23-
expect(lines[15]).toBeUndefined()
24-
expect(lines[18]).toBeUndefined()
40+
expect(lines[25]).toBeUndefined()
2541
}
2642
else {
27-
expect(lines[15]).toBeGreaterThanOrEqual(1)
28-
expect(lines[18]).toBeUndefined()
43+
expect(lines[25]).toBeGreaterThanOrEqual(1)
2944
}
3045
})

0 commit comments

Comments
 (0)