@@ -457,39 +457,41 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
457457
458458 const map = transformResult ?. map as EncodedSourceMap | undefined
459459 const code = transformResult ?. code
460- const sourcesContent
461- = map ?. sourcesContent ?. [ 0 ]
462- || ( await fs . readFile ( filePath , 'utf-8' ) . catch ( ( ) => {
460+ const sourcesContent = map ?. sourcesContent || [ ]
461+
462+ if ( ! sourcesContent [ 0 ] ) {
463+ sourcesContent [ 0 ] = await fs . readFile ( filePath , 'utf-8' ) . catch ( ( ) => {
463464 // If file does not exist construct a dummy source for it.
464465 // These can be files that were generated dynamically during the test run and were removed after it.
465466 const length = findLongestFunctionLength ( functions )
466467 return '.' . repeat ( length )
467- } ) )
468+ } )
469+ }
468470
469471 // These can be uncovered files included by "all: true" or files that are loaded outside vite-node
470472 if ( ! map ) {
471473 return {
472474 isExecuted,
473- source : code || sourcesContent ,
474- originalSource : sourcesContent ,
475+ source : code || sourcesContent [ 0 ] ,
476+ originalSource : sourcesContent [ 0 ] ,
475477 }
476478 }
477479
478- const sources = [ url ]
480+ const sources = map . sources || [ url ]
479481 if ( map . sources && map . sources [ 0 ] && ! url . endsWith ( map . sources [ 0 ] ) ) {
480482 sources [ 0 ] = new URL ( map . sources [ 0 ] , url ) . href
481483 }
482484
483485 return {
484486 isExecuted,
485- originalSource : sourcesContent ,
486- source : code || sourcesContent ,
487+ originalSource : sourcesContent [ 0 ] ,
488+ source : code || sourcesContent [ 0 ] ,
487489 sourceMap : {
488490 sourcemap : excludeGeneratedCode ( code , {
489491 ...map ,
490492 version : 3 ,
491493 sources,
492- sourcesContent : [ sourcesContent ] ,
494+ sourcesContent,
493495 } ) ,
494496 } ,
495497 }
0 commit comments