diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 7f78bddf4bef40..ced521d9f6614f 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -377,9 +377,6 @@ function addTableLine(prefix, width) { } const kHorizontalEllipsis = '\u2026'; -function truncateStart(string, width) { - return string.length > width ? `${kHorizontalEllipsis}${StringPrototypeSlice(string, string.length - width + 1)}` : string; -} function truncateEnd(string, width) { return string.length > width ? `${StringPrototypeSlice(string, 0, width - 1)}${kHorizontalEllipsis}` : string; @@ -454,7 +451,6 @@ function getCoverageReport(pad, summary, symbol, color, table) { } } - function getCell(string, width, pad, truncate, coverage) { if (!table) return string; @@ -469,6 +465,46 @@ function getCoverageReport(pad, summary, symbol, color, table) { return result; } + function getfilePathMultiline(string, width, pad, coverage) { + if (!table) return string; + + const lines = []; + let currentLine = ''; + + for (const word of StringPrototypeSplit(string, '\\')) { + if (currentLine.length + word.length + 1 <= width) { + // If adding the next word fits in the current line, append it + currentLine += (currentLine.length > 0 ? '\\' : '') + word; + } else { + // If adding the next word exceeds the width, start a new line + ArrayPrototypePush(lines, currentLine); + currentLine = word; + } + } + + // Add the last line if any + if (currentLine.length > 0) { + ArrayPrototypePush(lines, currentLine); + } + + const truncatedLines = ArrayPrototypeMap(lines, (line) => StringPrototypeSlice(line, 0, width)); + + // Delete empty lines if any + for (let i = 0; i < truncatedLines.length; ++i) { + if (truncatedLines[i].length === 0) { + truncatedLines.splice(i, 1); + } + } + + return getCell( + ArrayPrototypeJoin(truncatedLines, '\n'), + width, + pad, + false, + coverage, + ); + } + // Head if (table) report += addTableLine(prefix, tableWidth); report += `${prefix}${getCell('file', filePadLength, StringPrototypePadEnd, truncateEnd)}${kSeparator}` + @@ -489,7 +525,7 @@ function getCoverageReport(pad, summary, symbol, color, table) { }); fileCoverage /= kColumnsKeys.length; - report += `${prefix}${getCell(relativePath, filePadLength, StringPrototypePadEnd, truncateStart, fileCoverage)}${kSeparator}` + + report += `${prefix}${getfilePathMultiline(relativePath, filePadLength, StringPrototypePadEnd, fileCoverage)}${kSeparator}` + `${ArrayPrototypeJoin(ArrayPrototypeMap(coverages, (coverage, j) => getCell(NumberPrototypeToFixed(coverage, 2), columnPadLengths[j], StringPrototypePadStart, false, coverage)), kSeparator)}${kSeparator}` + `${getCell(formatUncoveredLines(getUncoveredLines(file.lines), table), uncoveredLinesPadLength, false, truncateEnd)}\n`; }