/
utils.ts
35 lines (29 loc) · 1009 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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>')
}