@@ -2813,6 +2813,50 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
28132813 logger . info ( "Process unit test coverage report" ) ;
28142814 return new Promise ( ( resolve , reject ) => {
28152815 let covDat , covFileNames ;
2816+ const normalizeCoveragePath = ( filePath : string ) : string => {
2817+ return path
2818+ . normalize ( filePath )
2819+ . replace ( / \\ / g, "/" )
2820+ . replace ( / ^ [ A - Z a - z ] : \/ / , "/" )
2821+ . replace ( / \/ + / g, "/" )
2822+ . toLowerCase ( ) ;
2823+ } ;
2824+ const getSourceRelativePath = (
2825+ normalizedFilePath : string ,
2826+ ) : string => {
2827+ const sourceRootIndex = normalizedFilePath . lastIndexOf ( "/src/" ) ;
2828+ if ( sourceRootIndex === - 1 ) {
2829+ return normalizedFilePath ;
2830+ }
2831+ return normalizedFilePath . slice ( sourceRootIndex + 1 ) ;
2832+ } ;
2833+ const isCoveragePathMatch = (
2834+ sourceFilePath : string ,
2835+ coverageFilePath : string ,
2836+ ) : boolean => {
2837+ const normalizedSourcePath = normalizeCoveragePath ( sourceFilePath ) ;
2838+ const normalizedCoveragePath =
2839+ normalizeCoveragePath ( coverageFilePath ) ;
2840+
2841+ if (
2842+ normalizedSourcePath === normalizedCoveragePath ||
2843+ normalizedSourcePath . endsWith ( normalizedCoveragePath ) ||
2844+ normalizedCoveragePath . endsWith ( normalizedSourcePath )
2845+ ) {
2846+ return true ;
2847+ }
2848+
2849+ const sourceRelativePath =
2850+ getSourceRelativePath ( normalizedSourcePath ) ;
2851+ const coverageRelativePath =
2852+ getSourceRelativePath ( normalizedCoveragePath ) ;
2853+
2854+ return (
2855+ sourceRelativePath === coverageRelativePath ||
2856+ sourceRelativePath . endsWith ( coverageRelativePath ) ||
2857+ coverageRelativePath . endsWith ( sourceRelativePath )
2858+ ) ;
2859+ } ;
28162860
28172861 let coverageData : CoverageData =
28182862 Configuration . mainData . coverageData ;
@@ -2865,13 +2909,7 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
28652909 out = { name : fileName , filePath : fileName } ;
28662910 } else {
28672911 const findMatch = _ . filter ( covFileNames , ( el ) => {
2868- const normalizedFilename = path
2869- . normalize ( fileName )
2870- . replace ( / \\ / g, "/" ) ;
2871- return (
2872- el . includes ( fileName ) ||
2873- normalizedFilename . includes ( el )
2874- ) ;
2912+ return isCoveragePathMatch ( el , fileName ) ;
28752913 } ) ;
28762914 if ( findMatch . length > 0 ) {
28772915 out = _ . clone ( covDat [ findMatch [ 0 ] ] ) ;
0 commit comments