mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
36 lines
1009 B
TypeScript
36 lines
1009 B
TypeScript
import { readFileSync } from 'fs'
|
|
import { normalize } from 'pathe'
|
|
|
|
interface CoverageFinalJson {
|
|
default: {
|
|
[filename: string]: {
|
|
path: string
|
|
b: Record<string, number[]>
|
|
f: Record<string, number>
|
|
fnMap: Record<string, { name: string }>
|
|
// ... and more unrelated keys
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Read JSON coverage report from file system.
|
|
* Normalizes paths to keep contents consistent between OS's
|
|
*/
|
|
export async function readCoverageJson() {
|
|
const jsonReport = JSON.parse(readFileSync('./coverage/custom-json-report-name.json', 'utf8')) as CoverageFinalJson
|
|
|
|
const normalizedReport: CoverageFinalJson['default'] = {}
|
|
|
|
for (const [filename, coverage] of Object.entries(jsonReport)) {
|
|
coverage.path = normalizeFilename(coverage.path)
|
|
normalizedReport[normalizeFilename(filename)] = coverage
|
|
}
|
|
|
|
return normalizedReport
|
|
}
|
|
|
|
export function normalizeFilename(filename: string) {
|
|
return normalize(filename).replace(normalize(process.cwd()), '<process-cwd>')
|
|
}
|