Skip to content

Commit 821126f

Browse files
authored
feat!: add @vitest/coverage-v8 package (#3339)
1 parent 19ecc6c commit 821126f

File tree

29 files changed

+4076
-105
lines changed

29 files changed

+4076
-105
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ A blazing fast unit test framework powered by Vite.
3535
- [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
3636
- [Chai](https://www.chaijs.com/) built-in for assertions, with [Jest expect](https://jestjs.io/docs/expect) compatible APIs.
3737
- [Smart & instant watch mode](https://vitest.dev/guide/features.html#watch-mode), like HMR for tests!
38-
- [Native code coverage](https://vitest.dev/guide/features.html#coverage) via [c8](https://github.com/bcoe/c8) or [`istanbul`](https://istanbul.js.org/).
38+
- [Native code coverage](https://vitest.dev/guide/features.html#coverage) via [`v8`](https://v8.dev/blog/javascript-code-coverage) or [`istanbul`](https://istanbul.js.org/).
3939
- [Tinyspy](https://github.com/tinylibs/tinyspy) built-in for mocking, stubbing, and spies.
4040
- [JSDOM](https://github.com/jsdom/jsdom) and [happy-dom](https://github.com/capricorn86/happy-dom) for DOM and browser API mocking
4141
- Components testing ([Vue](./examples/vue), [React](./examples/react), [Svelte](./examples/svelte), [Lit](./examples/lit), [Vitesse](./examples/vitesse))

docs/.vitepress/components/FeaturesList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<ListItem><a target="_blank" href="https://www.chaijs.com/" rel="noopener noreferrer">Chai</a> built-in for assertions + <a target="_blank" href="https://jestjs.io/docs/expect" rel="noopener noreferrer">Jest expect</a> compatible APIs</ListItem>
2323
<ListItem><a target="_blank" href="https://github.com/tinylibs/tinyspy" rel="noopener noreferrer">Tinyspy</a> built-in for mocking</ListItem>
2424
<ListItem><a target="_blank" href="https://github.com/capricorn86/happy-dom" rel="noopener noreferrer">happy-dom</a> or <a target="_blank" href="https://github.com/jsdom/jsdom" rel="noopener noreferrer">jsdom</a> for DOM mocking</ListItem>
25-
<ListItem>Code coverage via <a target="_blank" href="https://github.com/bcoe/c8" rel="noopener noreferrer">c8</a> or <a target="_blank" href="https://istanbul.js.org/" rel="noopener noreferrer">istanbul</a></ListItem>
25+
<ListItem>Code coverage via <a target="_blank" href="https://v8.dev/blog/javascript-code-coverage" rel="noopener noreferrer">v8</a> or <a target="_blank" href="https://istanbul.js.org/" rel="noopener noreferrer">istanbul</a></ListItem>
2626
<ListItem>Rust-like <a href="/guide/in-source">in-source testing</a></ListItem>
2727
<ListItem>Type Testing via <a target="_blank" href="https://github.com/mmkal/expect-type" rel="noopener noreferrer">expect-type</a></ListItem>
2828
</ul>

docs/advanced/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ await vitest?.close()
1919
`startVitest` function returns `Vitest` instance if tests can be started. It returns `undefined`, if one of the following occurs:
2020
2121
- Vitest didn't find "vite" package (usually installed with Vitest)
22-
- If coverage is enabled and run mode is "test", but the coverage package is not installed (`@vitest/coverage-c8` or `@vitest/coverage-istanbul`)
22+
- If coverage is enabled and run mode is "test", but the coverage package is not installed (`@vitest/coverage-v8` or `@vitest/coverage-istanbul`)
2323
- If the environment package is not installed (`jsdom`/`happy-dom`/`@edge-runtime/vm`)
2424
2525
If `undefined` is returned or tests failed during the run, Vitest sets `process.exitCode` to `1`.

docs/config/index.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,11 @@ Isolate environment for each test file. Does not work if you disable [`--threads
665665

666666
### coverage<NonProjectOption />
667667

668-
You can use [`c8`](https://github.com/bcoe/c8), [`istanbul`](https://istanbul.js.org/) or [a custom coverage solution](/guide/coverage#custom-coverage-provider) for coverage collection.
668+
You can use [`v8`](https://v8.dev/blog/javascript-code-coverage), [`istanbul`](https://istanbul.js.org/) or [a custom coverage solution](/guide/coverage#custom-coverage-provider) for coverage collection.
669+
670+
::: info
671+
The `c8` provider is being replaced by the `v8` provider. It will be deprecated in the next major version.
672+
:::
669673

670674
You can provide coverage options to CLI with dot notation:
671675

@@ -679,8 +683,8 @@ If you are using coverage options with dot notation, don't forget to specify `--
679683

680684
#### coverage.provider
681685

682-
- **Type:** `'c8' | 'istanbul' | 'custom'`
683-
- **Default:** `'c8'`
686+
- **Type:** `'c8' | 'v8' | 'istanbul' | 'custom'`
687+
- **Default:** `'v8'`
684688
- **CLI:** `--coverage.provider=<provider>`
685689

686690
Use `provider` to select the tool for coverage collection.
@@ -689,7 +693,7 @@ Use `provider` to select the tool for coverage collection.
689693

690694
- **Type:** `boolean`
691695
- **Default:** `false`
692-
- **Available for providers:** `'c8' | 'istanbul'`
696+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
693697
- **CLI:** `--coverage.enabled`, `--coverage.enabled=false`
694698

695699
Enables coverage collection. Can be overridden using `--coverage` CLI option.
@@ -698,7 +702,7 @@ Enables coverage collection. Can be overridden using `--coverage` CLI option.
698702

699703
- **Type:** `string[]`
700704
- **Default:** `['**']`
701-
- **Available for providers:** `'c8' | 'istanbul'`
705+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
702706
- **CLI:** `--coverage.include=<path>`, `--coverage.include=<path1> --coverage.include=<path2>`
703707

704708
List of files included in coverage as glob patterns
@@ -707,7 +711,7 @@ List of files included in coverage as glob patterns
707711

708712
- **Type:** `string | string[]`
709713
- **Default:** `['.js', '.cjs', '.mjs', '.ts', '.mts', '.cts', '.tsx', '.jsx', '.vue', '.svelte']`
710-
- **Available for providers:** `'c8' | 'istanbul'`
714+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
711715
- **CLI:** `--coverage.extension=<extension>`, `--coverage.extension=<extension1> --coverage.extension=<extension2>`
712716

713717
#### coverage.exclude
@@ -729,7 +733,7 @@ List of files included in coverage as glob patterns
729733
'**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}',
730734
]
731735
```
732-
- **Available for providers:** `'c8' | 'istanbul'`
736+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
733737
- **CLI:** `--coverage.exclude=<path>`, `--coverage.exclude=<path1> --coverage.exclude=<path2>`
734738

735739
List of files excluded from coverage as glob patterns.
@@ -738,7 +742,7 @@ List of files excluded from coverage as glob patterns.
738742

739743
- **Type:** `boolean`
740744
- **Default:** `false`
741-
- **Available for providers:** `'c8' | 'istanbul'`
745+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
742746
- **CLI:** `--coverage.all`, `--coverage.all=false`
743747

744748
Whether to include all files, including the untested ones into report.
@@ -747,7 +751,7 @@ Whether to include all files, including the untested ones into report.
747751

748752
- **Type:** `boolean`
749753
- **Default:** `true`
750-
- **Available for providers:** `'c8' | 'istanbul'`
754+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
751755
- **CLI:** `--coverage.clean`, `--coverage.clean=false`
752756

753757
Clean coverage results before running tests
@@ -756,7 +760,7 @@ Clean coverage results before running tests
756760

757761
- **Type:** `boolean`
758762
- **Default:** `true`
759-
- **Available for providers:** `'c8' | 'istanbul'`
763+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
760764
- **CLI:** `--coverage.cleanOnRerun`, `--coverage.cleanOnRerun=false`
761765

762766
Clean coverage report on watch rerun
@@ -765,7 +769,7 @@ Clean coverage report on watch rerun
765769

766770
- **Type:** `string`
767771
- **Default:** `'./coverage'`
768-
- **Available for providers:** `'c8' | 'istanbul'`
772+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
769773
- **CLI:** `--coverage.reportsDirectory=<path>`
770774

771775
Directory to write coverage report to.
@@ -774,7 +778,7 @@ Directory to write coverage report to.
774778

775779
- **Type:** `string | string[] | [string, {}][]`
776780
- **Default:** `['text', 'html', 'clover', 'json']`
777-
- **Available for providers:** `'c8' | 'istanbul'`
781+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
778782
- **CLI:** `--coverage.reporter=<reporter>`, `--coverage.reporter=<reporter1> --coverage.reporter=<reporter2>`
779783

780784
Coverage reporters to use. See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters. See [`@types/istanbul-reporter`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/276d95e4304b3670eaf6e8e5a7ea9e265a14e338/types/istanbul-reports/index.d.ts) for details about reporter specific options.
@@ -801,7 +805,7 @@ Since Vitest 0.31.0, you can check your coverage report in Vitest UI: check [Vit
801805

802806
- **Type:** `boolean`
803807
- **Default:** `true`
804-
- **Available for providers:** `'c8' | 'istanbul'`
808+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
805809
- **CLI:** `--coverage.reportOnFailure`, `--coverage.reportOnFailure=false`
806810
- **Version:** Since Vitest 0.31.2
807811

@@ -811,7 +815,7 @@ Generate coverage report even when tests fail.
811815

812816
- **Type:** `boolean`
813817
- **Default:** `false`
814-
- **Available for providers:** `'c8' | 'istanbul'`
818+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
815819
- **CLI:** `--coverage.skipFull`, `--coverage.skipFull=false`
816820

817821
Do not show files with 100% statement, branch, and function coverage.
@@ -820,7 +824,7 @@ Do not show files with 100% statement, branch, and function coverage.
820824

821825
- **Type:** `boolean`
822826
- **Default:** `false`
823-
- **Available for providers:** `'c8' | 'istanbul'`
827+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
824828
- **CLI:** `--coverage.perFile`, `--coverage.perFile=false`
825829

826830
Check thresholds per file.
@@ -830,7 +834,7 @@ See `lines`, `functions`, `branches` and `statements` for the actual thresholds.
830834

831835
- **Type:** `boolean`
832836
- **Default:** `false`
833-
- **Available for providers:** `'c8' | 'istanbul'`
837+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
834838
- **CLI:** `--coverage.thresholdAutoUpdate=<boolean>`
835839

836840
Update threshold values `lines`, `functions`, `branches` and `statements` to configuration file when current coverage is above the configured thresholds.
@@ -839,7 +843,7 @@ This option helps to maintain thresholds when coverage is improved.
839843
#### coverage.lines
840844

841845
- **Type:** `number`
842-
- **Available for providers:** `'c8' | 'istanbul'`
846+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
843847
- **CLI:** `--coverage.lines=<number>`
844848

845849
Threshold for lines.
@@ -848,7 +852,7 @@ See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-threshol
848852
#### coverage.functions
849853

850854
- **Type:** `number`
851-
- **Available for providers:** `'c8' | 'istanbul'`
855+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
852856
- **CLI:** `--coverage.functions=<number>`
853857

854858
Threshold for functions.
@@ -857,7 +861,7 @@ See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-threshol
857861
#### coverage.branches
858862

859863
- **Type:** `number`
860-
- **Available for providers:** `'c8' | 'istanbul'`
864+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
861865
- **CLI:** `--coverage.branches=<number>`
862866

863867
Threshold for branches.
@@ -866,7 +870,7 @@ See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-threshol
866870
#### coverage.statements
867871

868872
- **Type:** `number`
869-
- **Available for providers:** `'c8' | 'istanbul'`
873+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
870874
- **CLI:** `--coverage.statements=<number>`
871875

872876
Threshold for statements.
@@ -903,7 +907,7 @@ Specifies the directories that are used when `--all` is enabled.
903907

904908
- **Type:** `boolean`
905909
- **Default:** `false`
906-
- **Available for providers:** `'c8'`
910+
- **Available for providers:** `'c8' | 'v8'`
907911
- **CLI:** `--coverage.100`, `--coverage.100=false`
908912

909913
Shortcut for `--check-coverage --lines 100 --functions 100 --branches 100 --statements 100`.
@@ -942,7 +946,7 @@ See [istanbul documentation](https://github.com/istanbuljs/nyc#ignoring-methods)
942946
}
943947
```
944948

945-
- **Available for providers:** `'c8' | 'istanbul'`
949+
- **Available for providers:** `'c8' | 'v8' | 'istanbul'`
946950

947951
Watermarks for statements, lines, branches and functions. See [istanbul documentation](https://github.com/istanbuljs/nyc#high-and-low-watermarks) for more information.
948952

docs/guide/coverage.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ title: Coverage | Guide
44

55
# Coverage
66

7-
Vitest supports Native code coverage via [`c8`](https://github.com/bcoe/c8) and instrumented code coverage via [`istanbul`](https://istanbul.js.org/).
7+
Vitest supports Native code coverage via [`v8`](https://v8.dev/blog/javascript-code-coverage) and instrumented code coverage via [`istanbul`](https://istanbul.js.org/).
8+
9+
:::info
10+
The `c8` provider is being replaced by the [`v8`](https://v8.dev/blog/javascript-code-coverage) provider. It will be deprecated in the next major version.
11+
:::
812

913
## Coverage Providers
1014

1115
:::tip
1216
Since Vitest v0.22.0
1317
:::
1418

15-
Both `c8` and `istanbul` support are optional. By default, `c8` will be used.
19+
Both `v8` and `istanbul` support are optional. By default, `v8` will be used.
1620

17-
You can select the coverage tool by setting `test.coverage.provider` to either `c8` or `istanbul`:
21+
You can select the coverage tool by setting `test.coverage.provider` to `v8` or `istanbul`:
1822

1923
```ts
2024
// vite.config.ts
@@ -23,7 +27,7 @@ import { defineConfig } from 'vitest/config'
2327
export default defineConfig({
2428
test: {
2529
coverage: {
26-
provider: 'istanbul' // or 'c8'
30+
provider: 'istanbul' // or 'v8'
2731
},
2832
},
2933
})
@@ -34,8 +38,8 @@ When you start the Vitest process, it will prompt you to install the correspondi
3438
Or if you prefer to install them manually:
3539

3640
```bash
37-
# For c8
38-
npm i -D @vitest/coverage-c8
41+
# For v8
42+
npm i -D @vitest/coverage-v8
3943

4044
# For istanbul
4145
npm i -D @vitest/coverage-istanbul
@@ -138,7 +142,7 @@ export default defineConfig({
138142

139143
Both coverage providers have their own ways how to ignore code from coverage reports:
140144

141-
- [`c8`](https://github.com/bcoe/c8#ignoring-uncovered-lines-functions-and-blocks)
145+
- [`v8`](https://github.com/istanbuljs/v8-to-istanbul#ignoring-uncovered-lines)
142146
- [`ìstanbul`](https://github.com/istanbuljs/nyc#parsing-hints-ignoring-lines)
143147

144148
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)).
@@ -153,7 +157,7 @@ Beware that these ignore hints may now be included in final production build as
153157
if (condition) {
154158
```
155159

156-
For `c8` this does not cause any issues. You can use `c8 ignore` comments with Typescript as usual:
160+
For `v8` this does not cause any issues. You can use `c8 ignore` comments with Typescript as usual:
157161

158162
<!-- eslint-skip -->
159163
```ts

docs/guide/features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Learn more at [Mocking](/guide/mocking).
143143

144144
## Coverage
145145

146-
Vitest supports Native code coverage via [`c8`](https://github.com/bcoe/c8) and instrumented code coverage via [`istanbul`](https://istanbul.js.org/).
146+
Vitest supports Native code coverage via [`v8`](https://v8.dev/blog/javascript-code-coverage) and instrumented code coverage via [`istanbul`](https://istanbul.js.org/).
147147

148148
```json
149149
{

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@vitest/browser": "workspace:*",
4747
"@vitest/coverage-c8": "workspace:*",
4848
"@vitest/coverage-istanbul": "workspace:*",
49+
"@vitest/coverage-v8": "workspace:*",
4950
"@vitest/ui": "workspace:*",
5051
"bumpp": "^9.1.0",
5152
"esbuild": "^0.17.18",

packages/coverage-c8/src/provider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ export class C8CoverageProvider extends BaseCoverageProvider implements Coverage
5454
branches: config['100'] ? 100 : config.branches,
5555
statements: config['100'] ? 100 : config.statements,
5656
}
57+
58+
const banner = ' DEPRECATION '
59+
this.ctx.logger.log(
60+
c.bgYellow(c.black((banner))),
61+
c.yellow('@vitest/coverage-c8 is being replaced by @vitest/coverage-v8.'),
62+
c.yellow(`\n${' '.repeat(banner.length)} See`),
63+
c.blue(c.underline('https://github.com/vitest-dev/vitest/pull/3339')),
64+
c.yellow('for more information.'),
65+
)
5766
}
5867

5968
resolveOptions() {

packages/coverage-istanbul/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"prepublishOnly": "pnpm build"
4343
},
4444
"peerDependencies": {
45-
"vitest": ">=0.30.0 <1"
45+
"vitest": ">=0.32.0 <1"
4646
},
4747
"dependencies": {
4848
"istanbul-lib-coverage": "^3.2.0",

0 commit comments

Comments
 (0)