/
istanbul.report.test.ts
52 lines (39 loc) · 1.55 KB
/
istanbul.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
/*
* Istanbul coverage provider specific test cases
*/
import { expect, test } from 'vitest'
import { readCoverageJson } from './utils'
test('istanbul json report', async () => {
const jsonReport = await readCoverageJson()
// If this fails, you can use "npx live-server@1.2.1 ./coverage" to see coverage report
expect(jsonReport).toMatchSnapshot()
})
test('implicit else is included in branch count', async () => {
const coverageMap = await readCoverageJson()
const filename = '<process-cwd>/src/implicitElse.ts'
const fileCoverage = coverageMap[filename]
expect(fileCoverage.b).toHaveProperty('0')
expect(fileCoverage.b['0']).toHaveLength(2)
})
test('ignored code is excluded from the report', async () => {
const functionName = 'ignoredFunction'
const filename = '<process-cwd>/src/utils.ts'
const coverageMap = await readCoverageJson()
const fileCoverage = coverageMap[filename]
// Function should not be included in report
const functionCoverage = Object.values(fileCoverage.fnMap).find(fn => fn.name === functionName)
expect(functionCoverage).toBe(undefined)
// Function should still be found from the actual sources
const utils = await import('../src/utils')
expect(utils[functionName]).toBeTypeOf('function')
})
test('tests with multiple suites are covered', async () => {
const coverageMap = await readCoverageJson()
const filename = '<process-cwd>/src/multi-suite.ts'
const fileCoverage = coverageMap[filename]
// Assert that all functions are covered
expect(fileCoverage.f).toMatchObject({
0: 1,
1: 1,
})
})