@@ -377,9 +377,6 @@ function addTableLine(prefix, width) {
377377}
378378
379379const kHorizontalEllipsis = '\u2026' ;
380- function truncateStart ( string , width ) {
381- return string . length > width ? `${ kHorizontalEllipsis } ${ StringPrototypeSlice ( string , string . length - width + 1 ) } ` : string ;
382- }
383380
384381function truncateEnd ( string , width ) {
385382 return string . length > width ? `${ StringPrototypeSlice ( string , 0 , width - 1 ) } ${ kHorizontalEllipsis } ` : string ;
@@ -454,7 +451,6 @@ function getCoverageReport(pad, summary, symbol, color, table) {
454451 }
455452 }
456453
457-
458454 function getCell ( string , width , pad , truncate , coverage ) {
459455 if ( ! table ) return string ;
460456
@@ -469,6 +465,46 @@ function getCoverageReport(pad, summary, symbol, color, table) {
469465 return result ;
470466 }
471467
468+ function getfilePathMultiline ( string , width , pad , coverage ) {
469+ if ( ! table ) return string ;
470+
471+ const lines = [ ] ;
472+ let currentLine = '' ;
473+
474+ for ( const word of StringPrototypeSplit ( string , '\\' ) ) {
475+ if ( currentLine . length + word . length + 1 <= width ) {
476+ // If adding the next word fits in the current line, append it
477+ currentLine += ( currentLine . length > 0 ? '\\' : '' ) + word ;
478+ } else {
479+ // If adding the next word exceeds the width, start a new line
480+ ArrayPrototypePush ( lines , currentLine ) ;
481+ currentLine = word ;
482+ }
483+ }
484+
485+ // Add the last line if any
486+ if ( currentLine . length > 0 ) {
487+ ArrayPrototypePush ( lines , currentLine ) ;
488+ }
489+
490+ const truncatedLines = ArrayPrototypeMap ( lines , ( line ) => StringPrototypeSlice ( line , 0 , width ) ) ;
491+
492+ // Delete empty lines if any
493+ for ( let i = 0 ; i < truncatedLines . length ; ++ i ) {
494+ if ( truncatedLines [ i ] . length === 0 ) {
495+ truncatedLines . splice ( i , 1 ) ;
496+ }
497+ }
498+
499+ return getCell (
500+ ArrayPrototypeJoin ( truncatedLines , '\n' ) ,
501+ width ,
502+ pad ,
503+ false ,
504+ coverage ,
505+ ) ;
506+ }
507+
472508 // Head
473509 if ( table ) report += addTableLine ( prefix , tableWidth ) ;
474510 report += `${ prefix } ${ getCell ( 'file' , filePadLength , StringPrototypePadEnd , truncateEnd ) } ${ kSeparator } ` +
@@ -489,7 +525,7 @@ function getCoverageReport(pad, summary, symbol, color, table) {
489525 } ) ;
490526 fileCoverage /= kColumnsKeys . length ;
491527
492- report += `${ prefix } ${ getCell ( relativePath , filePadLength , StringPrototypePadEnd , truncateStart , fileCoverage ) } ${ kSeparator } ` +
528+ report += `${ prefix } ${ getfilePathMultiline ( relativePath , filePadLength , StringPrototypePadEnd , fileCoverage ) } ${ kSeparator } ` +
493529 `${ ArrayPrototypeJoin ( ArrayPrototypeMap ( coverages , ( coverage , j ) => getCell ( NumberPrototypeToFixed ( coverage , 2 ) , columnPadLengths [ j ] , StringPrototypePadStart , false , coverage ) ) , kSeparator ) } ${ kSeparator } ` +
494530 `${ getCell ( formatUncoveredLines ( getUncoveredLines ( file . lines ) , table ) , uncoveredLinesPadLength , false , truncateEnd ) } \n` ;
495531 }
0 commit comments