@@ -72,25 +72,27 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
7272
7373 const coverageMap = this . createCoverageMap ( )
7474
75- const mergedScripts = new Map < ScriptCoverageWithOffset [ 'url' ] , ScriptCoverageWithOffset > ( )
75+ const mergedScripts = new Map < string , ScriptCoverageWithOffset > ( )
7676 const autoAttachSubprocess = this . options . autoAttachSubprocess
7777
7878 await this . readCoverageFiles < RawCoverage > ( {
7979 onFileRead ( coverage ) {
8080 for ( const script of coverage . result ) {
81- const previous = mergedScripts . get ( script . url )
82- const merged : typeof script = mergeScriptCovs ( previous ? [ previous , script ] : [ script ] )
81+ const isExtendedContext = autoAttachSubprocess && script . isExtendedContext
82+
83+ // Same file can run in both module runner and child process, but with different source code
84+ const key = isExtendedContext ? `extended-context:${ script . url } ` : script . url
8385
84- const startOffset = previous ?. startOffset || script . startOffset || 0
85- const isExtendedContext = previous ?. isExtendedContext || script . isExtendedContext
86+ const previous = mergedScripts . get ( key )
87+ const merged : typeof script = mergeScriptCovs ( previous ? [ previous , script ] : [ script ] )
8688
87- merged . startOffset ||= startOffset
89+ merged . startOffset ||= previous ?. startOffset || script . startOffset || 0
8890
89- if ( autoAttachSubprocess && isExtendedContext ) {
91+ if ( isExtendedContext ) {
9092 merged . isExtendedContext = true
9193 }
9294
93- mergedScripts . set ( merged . url , merged )
95+ mergedScripts . set ( key , merged )
9496 }
9597 } ,
9698 onFinished : async ( project , environment ) => {
0 commit comments