-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
coverage.istanbul.test.ts
87 lines (66 loc) · 2.63 KB
/
coverage.istanbul.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import fs from 'fs'
import { normalize, resolve } from 'pathe'
import { expect, test } from 'vitest'
interface CoverageFinalJson {
default: {
[filename: string]: {
path: string
b: Record<string, number[]>
// ... and more unrelated keys
}
}
}
test('istanbul html report', async () => {
const coveragePath = resolve('./coverage/src')
const files = fs.readdirSync(coveragePath)
expect(files).toContain('index.html')
expect(files).toContain('index.ts.html')
expect(files).toContain('Hello.vue.html')
})
test('istanbul lcov report', async () => {
const coveragePath = resolve('./coverage')
const files = fs.readdirSync(coveragePath)
expect(files).toContain('lcov.info')
const lcovReport = resolve('./coverage/lcov-report')
const lcovReportFiles = fs.readdirSync(lcovReport)
expect(lcovReportFiles).toContain('index.html')
})
test('istanbul json report', async () => {
// @ts-expect-error -- generated file
const { default: jsonReport } = await import('./coverage/coverage-final.json') as CoverageFinalJson
const normalizedReport: CoverageFinalJson['default'] = {}
for (const [filename, coverage] of Object.entries(jsonReport)) {
coverage.path = normalizeFilename(coverage.path)
normalizedReport[normalizeFilename(filename)] = coverage
}
expect(normalizedReport).toMatchSnapshot()
})
test('all includes untested files', () => {
const coveragePath = resolve('./coverage/src')
const files = fs.readdirSync(coveragePath)
expect(files).toContain('untested-file.ts.html')
})
test('files should not contain query parameters', () => {
const coveragePath = resolve('./coverage/src/Counter')
const files = fs.readdirSync(coveragePath)
expect(files).toContain('index.html')
expect(files).toContain('Counter.vue.html')
expect(files).toContain('Counter.component.ts.html')
expect(files).not.toContain('Counter.component.ts?vue&type=script&src=true&lang.ts.html')
})
test('implicit else is included in branch count', async () => {
// @ts-expect-error -- generated file
const { default: coverageMap } = await import('./coverage/coverage-final.json') as CoverageFinalJson
const filename = normalize(resolve('./src/implicitElse.ts'))
const fileCoverage = coverageMap[filename]
expect(fileCoverage.b).toHaveProperty('0')
expect(fileCoverage.b['0']).toHaveLength(2)
})
test('file using import.meta.env is included in report', async () => {
const coveragePath = resolve('./coverage/src')
const files = fs.readdirSync(coveragePath)
expect(files).toContain('importEnv.ts.html')
})
function normalizeFilename(filename: string) {
return normalize(filename.replace(process.cwd(), '<root>'))
}