Skip to content

Commit a32539a

Browse files
committed
fix(coverage): default reporter
1 parent d0ce8d0 commit a32539a

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

packages/vitest/src/coverage.ts

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { pathToFileURL } from 'url'
44
import { resolve } from 'pathe'
55
import type { Arrayable } from 'vitest'
66
import type { Vitest } from './node'
7+
import { toArray } from './utils'
78

89
const defaultExcludes = [
910
'coverage/**',
@@ -108,6 +109,7 @@ export function resolveC8Options(options: C8Options, root: string): ResolvedC8Op
108109
...options as any,
109110
}
110111

112+
resolved.reporter = toArray(resolved.reporter)
111113
resolved.reportsDirectory = resolve(root, resolved.reportsDirectory)
112114
resolved.tempDirectory = process.env.NODE_V8_COVERAGE || resolve(resolved.reportsDirectory, 'tmp')
113115

@@ -132,38 +134,25 @@ export async function prepareCoverage(options: ResolvedC8Options) {
132134
const require = createRequire(import.meta.url)
133135

134136
export async function reportCoverage(ctx: Vitest) {
135-
// await writeC8Sourcemap(ctx)
136137
// eslint-disable-next-line @typescript-eslint/no-var-requires
137138
const createReport = require('c8/lib/report')
138139
const report = createReport(ctx.config.coverage)
139140

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+
})
153156

154157
await report.run()
155158
}
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

Comments
 (0)