-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
check-coverage.test.ts
52 lines (47 loc) · 1.47 KB
/
check-coverage.test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { existsSync, readFileSync } from 'node:fs'
import { normalize } from 'node:path'
import { expect, test } from 'vitest'
import libCoverage from 'istanbul-lib-coverage'
import { normalize as patheNormalize, resolve } from 'pathe'
test('coverage exists', () => {
expect(existsSync('./coverage')).toBe(true)
expect(existsSync('./coverage/index.html')).toBe(true)
})
test('file coverage summary matches', () => {
const coverageJson = JSON.parse(readFileSync('./coverage/coverage-final.json', 'utf-8'))
const coverageMap = libCoverage.createCoverageMap(coverageJson)
/* eslint-disable no-console */
console.log('coverageMap', coverageMap)
console.log('node:fs normalize', normalize(resolve('./src/math.ts')))
console.log('pathe normalize', patheNormalize(resolve('./src/math.ts')))
const fileCoverage = coverageMap.fileCoverageFor(normalize(resolve('./src/math.ts')))
// There should be 1 uncovered branch and 1 uncovered function. See math.ts.
expect(fileCoverage.toSummary()).toMatchInlineSnapshot(`
{
"branches": {
"covered": 3,
"pct": 75,
"skipped": 0,
"total": 4,
},
"functions": {
"covered": 2,
"pct": 66.66,
"skipped": 0,
"total": 3,
},
"lines": {
"covered": 7,
"pct": 50,
"skipped": 0,
"total": 14,
},
"statements": {
"covered": 7,
"pct": 50,
"skipped": 0,
"total": 14,
},
}
`)
})