@@ -2,6 +2,16 @@ import fs from 'fs'
2
2
import { normalize , resolve } from 'pathe'
3
3
import { expect , test } from 'vitest'
4
4
5
+ interface CoverageFinalJson {
6
+ default : {
7
+ [ filename : string ] : {
8
+ path : string
9
+ b : Record < string , number [ ] >
10
+ // ... and more unrelated keys
11
+ }
12
+ }
13
+ }
14
+
5
15
test ( 'istanbul html report' , async ( ) => {
6
16
const coveragePath = resolve ( './coverage/src' )
7
17
const files = fs . readdirSync ( coveragePath )
@@ -23,6 +33,20 @@ test('istanbul lcov report', async () => {
23
33
expect ( lcovReportFiles ) . toContain ( 'index.html' )
24
34
} )
25
35
36
+ test ( 'istanbul json report' , async ( ) => {
37
+ // @ts -expect-error -- generated file
38
+ const { default : jsonReport } = await import ( './coverage/coverage-final.json' ) as CoverageFinalJson
39
+
40
+ const normalizedReport : CoverageFinalJson [ 'default' ] = { }
41
+
42
+ for ( const [ filename , coverage ] of Object . entries ( jsonReport ) ) {
43
+ coverage . path = normalizeFilename ( coverage . path )
44
+ normalizedReport [ normalizeFilename ( filename ) ] = coverage
45
+ }
46
+
47
+ expect ( normalizedReport ) . toMatchSnapshot ( )
48
+ } )
49
+
26
50
test ( 'all includes untested files' , ( ) => {
27
51
const coveragePath = resolve ( './coverage/src' )
28
52
const files = fs . readdirSync ( coveragePath )
@@ -42,7 +66,7 @@ test('files should not contain query parameters', () => {
42
66
43
67
test ( 'implicit else is included in branch count' , async ( ) => {
44
68
// @ts -expect-error -- generated file
45
- const { default : coverageMap } = await import ( './coverage/coverage-final.json' )
69
+ const { default : coverageMap } = await import ( './coverage/coverage-final.json' ) as CoverageFinalJson
46
70
47
71
const filename = normalize ( resolve ( './src/implicitElse.ts' ) )
48
72
const fileCoverage = coverageMap [ filename ]
@@ -57,3 +81,7 @@ test('file using import.meta.env is included in report', async () => {
57
81
58
82
expect ( files ) . toContain ( 'importEnv.ts.html' )
59
83
} )
84
+
85
+ function normalizeFilename ( filename : string ) {
86
+ return filename . replace ( normalize ( process . cwd ( ) ) , '<root>' )
87
+ }
0 commit comments