@@ -310,10 +310,17 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
310
310
source : string
311
311
originalSource : string
312
312
sourceMap ?: { sourcemap : EncodedSourceMap }
313
+ isExecuted : boolean
313
314
} > {
314
315
const filePath = normalize ( fileURLToPath ( url ) )
315
316
316
- const transformResult = transformResults . get ( filePath ) || await this . ctx . vitenode . transformRequest ( filePath ) . catch ( ( ) => { } )
317
+ let isExecuted = true
318
+ let transformResult : FetchResult | Awaited < ReturnType < typeof this . ctx . vitenode . transformRequest > > = transformResults . get ( filePath )
319
+
320
+ if ( ! transformResult ) {
321
+ isExecuted = false
322
+ transformResult = await this . ctx . vitenode . transformRequest ( filePath ) . catch ( ( ) => null )
323
+ }
317
324
318
325
const map = transformResult ?. map as ( EncodedSourceMap | undefined )
319
326
const code = transformResult ?. code
@@ -327,6 +334,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
327
334
// These can be uncovered files included by "all: true" or files that are loaded outside vite-node
328
335
if ( ! map ) {
329
336
return {
337
+ isExecuted,
330
338
source : code || sourcesContent ,
331
339
originalSource : sourcesContent ,
332
340
}
@@ -337,6 +345,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
337
345
sources [ 0 ] = new URL ( map . sources [ 0 ] , url ) . href
338
346
339
347
return {
348
+ isExecuted,
340
349
originalSource : sourcesContent ,
341
350
source : code || sourcesContent ,
342
351
sourceMap : {
@@ -368,8 +377,8 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
368
377
await Promise . all ( chunk . map ( async ( { url, functions } ) => {
369
378
const sources = await this . getSources ( url , transformResults , functions )
370
379
371
- // If no source map was found from vite-node we can assume this file was not run in the wrapper
372
- const wrapperLength = sources . sourceMap ? WRAPPER_LENGTH : 0
380
+ // If file was executed by vite-node we'll need to add its wrapper
381
+ const wrapperLength = sources . isExecuted ? WRAPPER_LENGTH : 0
373
382
374
383
const converter = v8ToIstanbul ( url , wrapperLength , sources , undefined , this . options . ignoreEmptyLines )
375
384
await converter . load ( )
0 commit comments