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 <21ucs126@lnmiit.ac.in>
  • Loading branch information
pmarchini committed Aug 14, 2024
1 parent 53c5322 commit ac5f5a4
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 @@ -342,9 +342,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 @@ -419,7 +416,6 @@ function getCoverageReport(pad, summary, symbol, color, table) {
}
}


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

Expand All @@ -434,6 +430,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 @@ -454,7 +490,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 ac5f5a4

Please sign in to comment.