@@ -2,7 +2,7 @@ import { existsSync, promises as fs } from 'fs'
2
2
import _url from 'url'
3
3
import type { Profiler } from 'inspector'
4
4
import { takeCoverage } from 'v8'
5
- import { resolve } from 'pathe'
5
+ import { extname , resolve } from 'pathe'
6
6
import type { RawSourceMap } from 'vite-node'
7
7
import { configDefaults } from 'vitest/config'
8
8
// eslint-disable-next-line no-restricted-imports
@@ -53,6 +53,7 @@ export class C8CoverageProvider implements CoverageProvider {
53
53
54
54
// add source maps
55
55
const sourceMapMeta : Record < SourceMapMeta [ 'url' ] , MapAndSource > = { }
56
+ const extensions = Array . isArray ( this . options . extension ) ? this . options . extension : [ this . options . extension ]
56
57
57
58
const entries = Array
58
59
. from ( this . ctx . vitenode . fetchCache . entries ( ) )
@@ -62,10 +63,13 @@ export class C8CoverageProvider implements CoverageProvider {
62
63
return null
63
64
64
65
const filepath = file . split ( '?' ) [ 0 ]
66
+ const url = _url . pathToFileURL ( filepath ) . href
67
+ const extension = extname ( file ) || extname ( url )
65
68
66
69
return {
67
70
filepath,
68
- url : _url . pathToFileURL ( filepath ) . href ,
71
+ url,
72
+ extension,
69
73
map : result . map ,
70
74
source : result . code ,
71
75
}
@@ -74,6 +78,9 @@ export class C8CoverageProvider implements CoverageProvider {
74
78
if ( ! entry )
75
79
return false
76
80
81
+ if ( ! extensions . includes ( entry . extension ) )
82
+ return false
83
+
77
84
// Mappings and sourcesContent are needed for C8 to work
78
85
return (
79
86
entry . map . mappings . length > 0
@@ -84,6 +91,9 @@ export class C8CoverageProvider implements CoverageProvider {
84
91
} ) as SourceMapMeta [ ]
85
92
86
93
await Promise . all ( entries . map ( async ( { url, source, map, filepath } ) => {
94
+ if ( url in sourceMapMeta )
95
+ return
96
+
87
97
let code : string | undefined
88
98
try {
89
99
code = ( await fs . readFile ( filepath ) ) . toString ( )
0 commit comments