@@ -73,6 +73,7 @@ const VITE_EXPORTS_LINE_PATTERN
7373const DECORATOR_METADATA_PATTERN
7474 = / _ t s _ m e t a d a t a \( " d e s i g n : p a r a m t y p e s " , \[ [ ^ \] ] * \] \) , * / g
7575const DEFAULT_PROJECT : unique symbol = Symbol . for ( 'default-project' )
76+ const FILE_PROTOCOL = 'file://'
7677
7778const debug = createDebug ( 'vitest:coverage' )
7879let uniqueId = 0
@@ -441,7 +442,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
441442
442443 if ( ! transformResult ) {
443444 isExecuted = false
444- transformResult = await onTransform ( url . replace ( 'file://' , '' ) ) . catch ( ( ) => undefined )
445+ transformResult = await onTransform ( removeRoot ( url , FILE_PROTOCOL ) ) . catch ( ( ) => undefined )
445446 }
446447
447448 const map = transformResult ?. map as EncodedSourceMap | undefined
@@ -499,7 +500,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
499500
500501 async function onTransform ( filepath : string ) {
501502 if ( transformMode === 'browser' && project . browser ) {
502- const result = await project . browser . vite . transformRequest ( filepath . replace ( project . config . root , '' ) )
503+ const result = await project . browser . vite . transformRequest ( removeRoot ( filepath , project . config . root ) )
503504
504505 if ( result ) {
505506 return { ...result , code : `${ result . code } // <inline-source-map>` }
@@ -512,11 +513,11 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
512513
513514 for ( const result of coverage . result ) {
514515 if ( transformMode === 'browser' ) {
515- if ( result . url . includes ( ' @fs/ ') ) {
516- result . url = `file:// ${ result . url . replace ( '@fs/' , '' ) } `
516+ if ( result . url . startsWith ( '/ @fs') ) {
517+ result . url = `${ FILE_PROTOCOL } ${ removeRoot ( result . url , '/@fs ' ) } `
517518 }
518519 else {
519- result . url = `file:// ${ project . config . root } ${ result . url } `
520+ result . url = `${ FILE_PROTOCOL } ${ project . config . root } ${ result . url } `
520521 }
521522 }
522523
@@ -635,3 +636,11 @@ function normalizeTransformResults(
635636
636637 return normalized
637638}
639+
640+ function removeRoot ( filepath : string , root : string ) {
641+ if ( filepath . startsWith ( root ) ) {
642+ return filepath . slice ( root . length )
643+ }
644+
645+ return filepath
646+ }
0 commit comments