Skip to content

Commit 176133e

Browse files
authored
feat!(coverage): v8 to support only AST based remapping (#8064)
1 parent 41a111c commit 176133e

34 files changed

+346
-1168
lines changed

docs/config/index.md

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,51 +1628,11 @@ Sets thresholds to 100 for files matching the glob pattern.
16281628
}
16291629
```
16301630

1631-
#### coverage.ignoreEmptyLines
1632-
1633-
- **Type:** `boolean`
1634-
- **Default:** `true` (`false` in v1)
1635-
- **Available for providers:** `'v8'`
1636-
- **CLI:** `--coverage.ignoreEmptyLines=<boolean>`
1637-
1638-
Ignore empty lines, comments and other non-runtime code, e.g. Typescript types. Requires `experimentalAstAwareRemapping: false`.
1639-
1640-
This option works only if the used compiler removes comments and other non-runtime code from the transpiled code.
1641-
By default Vite uses ESBuild which removes comments and Typescript types from `.ts`, `.tsx` and `.jsx` files.
1642-
1643-
If you want to apply ESBuild to other files as well, define them in [`esbuild` options](https://vitejs.dev/config/shared-options.html#esbuild):
1644-
1645-
```ts
1646-
import { defineConfig } from 'vitest/config'
1647-
1648-
export default defineConfig({
1649-
esbuild: {
1650-
// Transpile all files with ESBuild to remove comments from code coverage.
1651-
// Required for `test.coverage.ignoreEmptyLines` to work:
1652-
include: ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.ts', '**/*.tsx'],
1653-
},
1654-
test: {
1655-
coverage: {
1656-
provider: 'v8',
1657-
ignoreEmptyLines: true,
1658-
},
1659-
},
1660-
})
1661-
```
1662-
#### coverage.experimentalAstAwareRemapping
1663-
1664-
- **Type:** `boolean`
1665-
- **Default:** `false`
1666-
- **Available for providers:** `'v8'`
1667-
- **CLI:** `--coverage.experimentalAstAwareRemapping=<boolean>`
1668-
1669-
Remap coverage with experimental AST based analysis. Provides more accurate results compared to default mode.
1670-
16711631
#### coverage.ignoreClassMethods
16721632

16731633
- **Type:** `string[]`
16741634
- **Default:** `[]`
1675-
- **Available for providers:** `'istanbul'`
1635+
- **Available for providers:** `'v8' | 'istanbul'`
16761636
- **CLI:** `--coverage.ignoreClassMethods=<method>`
16771637

16781638
Set to array of class method names to ignore for coverage.

docs/guide/coverage.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,8 @@ Please refer to the type definition for more details.
336336

337337
Both coverage providers have their own ways how to ignore code from coverage reports:
338338

339-
- [`v8`](https://github.com/istanbuljs/v8-to-istanbul#ignoring-uncovered-lines)
339+
- [`v8`](https://github.com/AriPerkkio/ast-v8-to-istanbul?tab=readme-ov-file#ignoring-code)
340340
- [`istanbul`](https://github.com/istanbuljs/nyc#parsing-hints-ignoring-lines)
341-
- `v8` with [`experimentalAstAwareRemapping: true`](https://vitest.dev/config/#coverage-experimentalAstAwareRemapping) see [ast-v8-to-istanbul | Ignoring code](https://github.com/AriPerkkio/ast-v8-to-istanbul?tab=readme-ov-file#ignoring-code)
342341

343342
When using TypeScript the source codes are transpiled using `esbuild`, which strips all comments from the source codes ([esbuild#516](https://github.com/evanw/esbuild/issues/516)).
344343
Comments which are considered as [legal comments](https://esbuild.github.io/api/#legal-comments) are preserved.

docs/guide/migration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ export default defineConfig({
2121
})
2222
```
2323

24+
### V8 Code Coverage Major Changes
25+
26+
Vitest's V8 code coverage provider is now using more accurate coverage result remapping logic.
27+
It is expected for users to see changes in their coverage reports when updating from Vitest v3.
28+
29+
In the past Vitest used [`v8-to-istanbul`](https://github.com/istanbuljs/v8-to-istanbul) for remapping V8 coverage results into your source files.
30+
This method wasn't very accurate and provided plenty of false positives in the coverage reports.
31+
We've now developed a new package that utilizes AST based analysis for the V8 coverage.
32+
This allows V8 reports to be as accurate as `@vitest/coverage-istanbul` reports.
33+
34+
- Coverage ignore hints have updated. See [Coverage | Ignoring Code](/guide/coverage.html#ignoring-code).
35+
- `coverage.ignoreEmptyLines` is removed. Lines without runtime code are no longer included in reports.
36+
- `coverage.experimentalAstAwareRemapping` is removed. This option is now enabled by default, and is the only supported remapping method.
37+
- `coverage.ignoreClassMethods` is now supported by V8 provider too.
38+
2439
### Removed options `coverage.all` and `coverage.extensions`
2540

2641
In previous versions Vitest included all uncovered files in coverage report by default.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"@sinonjs/fake-timers@14.0.0": "patches/@sinonjs__fake-timers@14.0.0.patch",
8787
"cac@6.7.14": "patches/cac@6.7.14.patch",
8888
"@types/sinonjs__fake-timers@8.1.5": "patches/@types__sinonjs__fake-timers@8.1.5.patch",
89-
"v8-to-istanbul@9.3.0": "patches/v8-to-istanbul@9.3.0.patch",
9089
"acorn@8.11.3": "patches/acorn@8.11.3.patch"
9190
},
9291
"onlyBuiltDependencies": [

packages/coverage-v8/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
"@types/istanbul-reports": "catalog:",
7676
"@vitest/browser": "workspace:*",
7777
"pathe": "catalog:",
78-
"v8-to-istanbul": "^9.3.0",
7978
"vite-node": "workspace:*",
8079
"vitest": "workspace:*"
8180
}

0 commit comments

Comments
 (0)