@@ -4,6 +4,7 @@ import { pathToFileURL } from 'url'
4
4
import { resolve } from 'pathe'
5
5
import type { Arrayable } from 'vitest'
6
6
import type { Vitest } from './node'
7
+ import { toArray } from './utils'
7
8
8
9
const defaultExcludes = [
9
10
'coverage/**' ,
@@ -108,6 +109,7 @@ export function resolveC8Options(options: C8Options, root: string): ResolvedC8Op
108
109
...options as any ,
109
110
}
110
111
112
+ resolved . reporter = toArray ( resolved . reporter )
111
113
resolved . reportsDirectory = resolve ( root , resolved . reportsDirectory )
112
114
resolved . tempDirectory = process . env . NODE_V8_COVERAGE || resolve ( resolved . reportsDirectory , 'tmp' )
113
115
@@ -132,38 +134,25 @@ export async function prepareCoverage(options: ResolvedC8Options) {
132
134
const require = createRequire ( import . meta. url )
133
135
134
136
export async function reportCoverage ( ctx : Vitest ) {
135
- // await writeC8Sourcemap(ctx)
136
137
// eslint-disable-next-line @typescript-eslint/no-var-requires
137
138
const createReport = require ( 'c8/lib/report' )
138
139
const report = createReport ( ctx . config . coverage )
139
140
140
- const files = Array . from ( ctx . visitedFilesMap . entries ( ) ) . filter ( i => ! i [ 0 ] . includes ( '/node_modules/' ) )
141
-
142
- files . forEach ( ( [ file , map ] ) => {
143
- if ( ! existsSync ( file ) )
144
- return
145
- const url = pathToFileURL ( file ) . href
146
- report . sourceMapCache [ url ] = {
147
- data : {
148
- ...map ,
149
- sources : map . sources . map ( i => pathToFileURL ( i ) . href ) || [ url ] ,
150
- } ,
151
- }
152
- } )
141
+ // add source maps
142
+ Array
143
+ . from ( ctx . visitedFilesMap . entries ( ) )
144
+ . filter ( i => ! i [ 0 ] . includes ( '/node_modules/' ) )
145
+ . forEach ( ( [ file , map ] ) => {
146
+ if ( ! existsSync ( file ) )
147
+ return
148
+ const url = pathToFileURL ( file ) . href
149
+ report . sourceMapCache [ url ] = {
150
+ data : {
151
+ ...map ,
152
+ sources : map . sources . map ( i => pathToFileURL ( i ) . href ) || [ url ] ,
153
+ } ,
154
+ }
155
+ } )
153
156
154
157
await report . run ( )
155
158
}
156
-
157
- // export async function writeC8Sourcemap(ctx: Vitest) {
158
- // const cache: Record<string, any> = {}
159
-
160
- // // write a fake coverage report with source map for c8 to consume
161
- // await fs.writeFile(
162
- // join(ctx.config.coverage.tempDirectory, 'vitest-source-map.json'),
163
- // JSON.stringify({
164
- // 'result': [],
165
- // 'timestamp': performance.now(),
166
- // 'source-map-cache': cache,
167
- // }), 'utf-8',
168
- // )
169
- // }
0 commit comments