-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
generic.report.test.ts
82 lines (61 loc) · 2.63 KB
/
generic.report.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
/*
* Test cases shared by both coverage providers
*/
import fs from 'node:fs'
import { resolve } from 'pathe'
import { expect, test } from 'vitest'
test('html report', async () => {
const coveragePath = resolve('./coverage/src')
const files = fs.readdirSync(coveragePath)
expect(files).toContain('index.html')
expect(files).toContain('index.mts.html')
expect(files).toContain('Hello.vue.html')
})
test('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('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('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')
})
test('files should not contain a setup file', () => {
const coveragePath = resolve('./coverage')
const files = fs.readdirSync(coveragePath)
expect(files).not.toContain('coverage-test')
expect(files).not.toContain('setup.ts.html')
const coverageSrcPath = resolve('./coverage/src')
const srcFiles = fs.readdirSync(coverageSrcPath)
expect(srcFiles).not.toContain('another-setup.ts.html')
})
test('thresholdAutoUpdate updates thresholds', async () => {
const configFilename = resolve('./vitest.config.ts')
const configContents = fs.readFileSync(configFilename, 'utf-8')
for (const threshold of ['functions', 'branches', 'lines', 'statements']) {
const match = configContents.match(new RegExp(`${threshold}: (?<coverage>[\\d|\\.]+)`))
const coverage = match?.groups?.coverage || '0'
// Configuration has fixed value of 1.01 set for each threshold
expect(parseInt(coverage)).toBeGreaterThan(1.01)
}
// Update thresholds back to fixed values
const updatedConfig = configContents.replace(/(branches|functions|lines|statements): ([\d|\.])+/g, '$1: 1.01')
fs.writeFileSync(configFilename, updatedConfig)
})