Skip to content

Commit

Permalink
test_runner: avoid coverage report partial file names
Browse files Browse the repository at this point in the history
Co-author: Medhansh404 <[email protected]>
  • Loading branch information
pmarchini committed Aug 25, 2024
1 parent 43f699d commit 20e0807
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -454,7 +451,6 @@ function getCoverageReport(pad, summary, symbol, color, table) {
}
}


function getCell(string, width, pad, truncate, coverage) {
if (!table) return string;

Expand All @@ -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}` +
Expand All @@ -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`;
}
Expand Down

0 comments on commit 20e0807

Please sign in to comment.