Skip to content

Commit 83017fc

Browse files
committed
feat(coverage): switch to @vitest/istanbuljs packages
1 parent c3ba16b commit 83017fc

26 files changed

Lines changed: 218 additions & 597 deletions

docs/api/advanced/reporters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ export default new MyReporter()
187187
function onCoverage(coverage: unknown): Awaitable<void>
188188
```
189189

190-
This hook is called after coverage results have been processed. Coverage provider's reporters are called after this hook. The typings of `coverage` depends on the `coverage.provider`. For Vitest's default built-in providers you can import the types from `istanbul-lib-coverage` package:
190+
This hook is called after coverage results have been processed. Coverage provider's reporters are called after this hook. The typings of `coverage` depends on the `coverage.provider`. For Vitest's default built-in providers you can import the types from `@vitest/istanbul-lib-coverage` package:
191191

192192
```ts
193-
import type { CoverageMap } from 'istanbul-lib-coverage'
193+
import type { CoverageMap } from '@vitest/istanbul-lib-coverage'
194194
195195
declare function onCoverage(coverage: CoverageMap): Awaitable<void>
196196
```

docs/config/coverage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Directory to write coverage report to.
9898
- **Available for providers:** `'v8' | 'istanbul'`
9999
- **CLI:** `--coverage.reporter=<reporter>`, `--coverage.reporter=<reporter1> --coverage.reporter=<reporter2>`
100100

101-
Coverage reporters to use. See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters. See [`@types/istanbul-reports`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/276d95e4304b3670eaf6e8e5a7ea9e265a14e338/types/istanbul-reports/index.d.ts) for details about reporter specific options.
101+
Coverage reporters to use. See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters. See [`@vitest/istanbul-reports`](https://github.com/vitest-dev/istanbuljs/tree/main/packages/istanbul-lib-report/src/reports) for details about reporter specific options.
102102

103103
The reporter has three different types:
104104

docs/guide/coverage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export default defineConfig({
260260
Custom reporters are loaded by Istanbul and must match its reporter interface. See [built-in reporters' implementation](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib) for reference.
261261

262262
```js [custom-reporter.cjs]
263+
// TODO Rewrite this part
263264
const { ReportBase } = require('istanbul-lib-report')
264265

265266
module.exports = class CustomReporter extends ReportBase {

packages/coverage-istanbul/package.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,18 @@
4848
"vitest": "workspace:*"
4949
},
5050
"dependencies": {
51-
"@babel/core": "^7.29.7",
5251
"@istanbuljs/schema": "^0.1.6",
5352
"@jridgewell/gen-mapping": "^0.3.13",
5453
"@jridgewell/trace-mapping": "catalog:",
55-
"istanbul-lib-coverage": "catalog:",
56-
"istanbul-lib-report": "catalog:",
57-
"istanbul-reports": "catalog:",
54+
"@vitest/istanbul-lib-coverage": "catalog:",
55+
"@vitest/istanbul-lib-instrument": "^0.0.3",
56+
"@vitest/istanbul-lib-report": "catalog:",
57+
"@vitest/istanbul-lib-source-maps": "^0.0.3",
5858
"magicast": "catalog:",
5959
"obug": "catalog:",
6060
"tinyrainbow": "catalog:"
6161
},
6262
"devDependencies": {
63-
"@types/istanbul-lib-coverage": "catalog:",
64-
"@types/istanbul-lib-instrument": "^1.7.8",
65-
"@types/istanbul-lib-report": "catalog:",
66-
"@types/istanbul-lib-source-maps": "catalog:",
67-
"@types/istanbul-reports": "catalog:",
68-
"istanbul-lib-instrument": "^6.0.3",
69-
"istanbul-lib-source-maps": "catalog:",
7063
"pathe": "catalog:",
7164
"vitest": "workspace:*"
7265
}

packages/coverage-istanbul/rollup.config.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { builtinModules, createRequire } from 'node:module'
2-
import commonjs from '@rollup/plugin-commonjs'
32
import json from '@rollup/plugin-json'
43
import nodeResolve from '@rollup/plugin-node-resolve'
54
import { join } from 'pathe'
@@ -21,9 +20,6 @@ const external = [
2120
...Object.keys(pkg.dependencies || {}),
2221
...Object.keys(pkg.peerDependencies || {}),
2322
/^@?vitest(\/|$)/,
24-
25-
// We bundle istanbul-lib-instrument but don't want to bundle its babel dependency
26-
'@babel/core',
2723
]
2824

2925
const dtsUtils = createDtsUtils()
@@ -32,11 +28,6 @@ const plugins = [
3228
...dtsUtils.isolatedDecl(),
3329
nodeResolve(),
3430
json(),
35-
commonjs({
36-
// "istanbul-lib-source-maps > @jridgewell/trace-mapping" is not CJS
37-
// "istanbul-lib-instrument > @jridgewell/trace-mapping" is not CJS
38-
esmExternals: ['@jridgewell/trace-mapping'],
39-
}),
4031
oxc({
4132
transform: { target: 'node20' },
4233
}),
@@ -62,16 +53,5 @@ export default defineConfig(() => [
6253
watch: false,
6354
external,
6455
plugins: dtsUtils.dts(),
65-
onLog(level, log, handler) {
66-
// we don't control the source of "istanbul-lib-coverage"
67-
if (
68-
level === 'warn'
69-
&& log.exporter === 'istanbul-lib-coverage'
70-
&& log.message.includes('"Range" is imported')
71-
) {
72-
return
73-
}
74-
handler(level, log)
75-
},
7656
},
7757
])

packages/coverage-istanbul/src/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CoverageMapData } from 'istanbul-lib-coverage'
1+
import type { CoverageMapData } from '@vitest/istanbul-lib-coverage'
22
import type { IstanbulCoverageProvider } from './provider'
33
import { COVERAGE_STORE_KEY } from './constants'
44

packages/coverage-istanbul/src/provider.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import type { CoverageMap } from 'istanbul-lib-coverage'
2-
import type { Instrumenter } from 'istanbul-lib-instrument'
1+
import type { CoverageMap } from '@vitest/istanbul-lib-coverage'
2+
import type { Instrumenter } from '@vitest/istanbul-lib-instrument'
33
import type { ProxifiedModule } from 'magicast'
44
import type { CoverageProvider, ReportContext, Vite, Vitest } from 'vitest/node'
55
import { existsSync, promises as fs } from 'node:fs'
66
// @ts-expect-error missing types
77
import { defaults as istanbulDefaults } from '@istanbuljs/schema'
88
import { addMapping, GenMapping, toEncodedMap } from '@jridgewell/gen-mapping'
99
import { eachMapping, TraceMap } from '@jridgewell/trace-mapping'
10-
import libCoverage from 'istanbul-lib-coverage'
11-
import { createInstrumenter } from 'istanbul-lib-instrument'
12-
import libReport from 'istanbul-lib-report'
13-
import libSourceMaps from 'istanbul-lib-source-maps'
14-
import reports from 'istanbul-reports'
10+
import * as libCoverage from '@vitest/istanbul-lib-coverage'
11+
import { createInstrumenter } from '@vitest/istanbul-lib-instrument'
12+
import * as libReport from '@vitest/istanbul-lib-report'
13+
import * as libSourceMaps from '@vitest/istanbul-lib-source-maps'
1514
import { parseModule } from 'magicast'
1615
import { createDebug } from 'obug'
1716
import c from 'tinyrainbow'
@@ -63,7 +62,6 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
6362
['importAttributes', { deprecatedAssertSyntax: true }],
6463
],
6564
generatorOpts: {
66-
// @ts-expect-error missing type
6765
importAttributesKeyword: 'with',
6866
},
6967

@@ -206,8 +204,8 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
206204

207205
for (const reporter of this.options.reporter) {
208206
// Type assertion required for custom reporters
209-
reports
210-
.create(reporter[0] as Parameters<typeof reports.create>[0], {
207+
libReport
208+
.create(reporter[0] as Parameters<typeof libReport.create>[0], {
211209
skipFull: this.options.skipFull,
212210
projectRoot: this.ctx.config.root,
213211
...reporter[1],

packages/coverage-v8/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,15 @@
5555
},
5656
"dependencies": {
5757
"@bcoe/v8-coverage": "^1.0.2",
58+
"@vitest/istanbul-lib-coverage": "catalog:",
59+
"@vitest/istanbul-lib-report": "catalog:",
5860
"ast-v8-to-istanbul": "^1.0.5",
59-
"istanbul-lib-coverage": "catalog:",
60-
"istanbul-lib-report": "catalog:",
61-
"istanbul-reports": "catalog:",
6261
"magicast": "catalog:",
6362
"obug": "catalog:",
6463
"std-env": "catalog:",
6564
"tinyrainbow": "catalog:"
6665
},
6766
"devDependencies": {
68-
"@types/istanbul-lib-coverage": "catalog:",
69-
"@types/istanbul-lib-report": "catalog:",
70-
"@types/istanbul-reports": "catalog:",
7167
"@vitest/browser": "workspace:*",
7268
"@vitest/browser-playwright": "workspace:*",
7369
"pathe": "catalog:",

packages/coverage-v8/src/provider.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import type { CoverageMap } from 'istanbul-lib-coverage'
1+
import type { CoverageMap } from '@vitest/istanbul-lib-coverage'
22
import type { ProxifiedModule } from 'magicast'
33
import type { Profiler } from 'node:inspector'
44
import type { CoverageProvider, ReportContext, TestProject, Vite, Vitest } from 'vitest/node'
55
import { existsSync, promises as fs } from 'node:fs'
66
import { fileURLToPath } from 'node:url'
77
// @ts-expect-error -- untyped
88
import { mergeScriptCovs } from '@bcoe/v8-coverage'
9+
import * as libCoverage from '@vitest/istanbul-lib-coverage'
10+
import * as libReport from '@vitest/istanbul-lib-report'
911
import astV8ToIstanbul from 'ast-v8-to-istanbul'
10-
import libCoverage from 'istanbul-lib-coverage'
11-
import libReport from 'istanbul-lib-report'
12-
import reports from 'istanbul-reports'
1312
import { parseModule } from 'magicast'
1413
import { createDebug } from 'obug'
1514
import { normalize } from 'pathe'
@@ -156,8 +155,8 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
156155

157156
for (const reporter of this.options.reporter) {
158157
// Type assertion required for custom reporters
159-
reports
160-
.create(reporter[0] as Parameters<typeof reports.create>[0], {
158+
libReport
159+
.create(reporter[0] as Parameters<typeof libReport.create>[0], {
161160
skipFull: this.options.skipFull,
162161
projectRoot: this.ctx.config.root,
163162
...reporter[1],

packages/vitest/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@
187187
"@jridgewell/trace-mapping": "catalog:",
188188
"@opentelemetry/api": "^1.9.1",
189189
"@sinonjs/fake-timers": "15.4.0",
190-
"@types/istanbul-lib-coverage": "catalog:",
191-
"@types/istanbul-reports": "catalog:",
192190
"@types/jsdom": "^28.0.3",
193191
"@types/node": "^24.13.3",
194192
"@types/picomatch": "^4.0.3",
195193
"@types/prompts": "^2.4.9",
196194
"@vitest/expect": "workspace:*",
195+
"@vitest/istanbul-lib-coverage": "catalog:",
196+
"@vitest/istanbul-lib-report": "catalog:",
197197
"@vitest/pretty-format": "workspace:*",
198198
"@vitest/snapshot": "workspace:*",
199199
"@vitest/spy": "workspace:*",

0 commit comments

Comments
 (0)