Skip to content

Commit ac5f5a4

Browse files
committed
test_runner: avoid coverage report partial file names
Co-author: Medhansh404 <21ucs126@lnmiit.ac.in>
1 parent 53c5322 commit ac5f5a4

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

lib/internal/test_runner/utils.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,6 @@ function addTableLine(prefix, width) {
342342
}
343343

344344
const kHorizontalEllipsis = '\u2026';
345-
function truncateStart(string, width) {
346-
return string.length > width ? `${kHorizontalEllipsis}${StringPrototypeSlice(string, string.length - width + 1)}` : string;
347-
}
348345

349346
function truncateEnd(string, width) {
350347
return string.length > width ? `${StringPrototypeSlice(string, 0, width - 1)}${kHorizontalEllipsis}` : string;
@@ -419,7 +416,6 @@ function getCoverageReport(pad, summary, symbol, color, table) {
419416
}
420417
}
421418

422-
423419
function getCell(string, width, pad, truncate, coverage) {
424420
if (!table) return string;
425421

@@ -434,6 +430,46 @@ function getCoverageReport(pad, summary, symbol, color, table) {
434430
return result;
435431
}
436432

433+
function getfilePathMultiline(string, width, pad, coverage) {
434+
if (!table) return string;
435+
436+
const lines = [];
437+
let currentLine = '';
438+
439+
for (const word of StringPrototypeSplit(string, '\\')) {
440+
if (currentLine.length + word.length + 1 <= width) {
441+
// If adding the next word fits in the current line, append it
442+
currentLine += (currentLine.length > 0 ? '\\' : '') + word;
443+
} else {
444+
// If adding the next word exceeds the width, start a new line
445+
ArrayPrototypePush(lines, currentLine);
446+
currentLine = word;
447+
}
448+
}
449+
450+
// Add the last line if any
451+
if (currentLine.length > 0) {
452+
ArrayPrototypePush(lines, currentLine);
453+
}
454+
455+
const truncatedLines = ArrayPrototypeMap(lines, (line) => StringPrototypeSlice(line, 0, width));
456+
457+
// Delete empty lines if any
458+
for (let i = 0; i < truncatedLines.length; ++i) {
459+
if (truncatedLines[i].length === 0) {
460+
truncatedLines.splice(i, 1);
461+
}
462+
}
463+
464+
return getCell(
465+
ArrayPrototypeJoin(truncatedLines, '\n'),
466+
width,
467+
pad,
468+
false,
469+
coverage,
470+
);
471+
}
472+
437473
// Head
438474
if (table) report += addTableLine(prefix, tableWidth);
439475
report += `${prefix}${getCell('file', filePadLength, StringPrototypePadEnd, truncateEnd)}${kSeparator}` +
@@ -454,7 +490,7 @@ function getCoverageReport(pad, summary, symbol, color, table) {
454490
});
455491
fileCoverage /= kColumnsKeys.length;
456492

457-
report += `${prefix}${getCell(relativePath, filePadLength, StringPrototypePadEnd, truncateStart, fileCoverage)}${kSeparator}` +
493+
report += `${prefix}${getfilePathMultiline(relativePath, filePadLength, StringPrototypePadEnd, fileCoverage)}${kSeparator}` +
458494
`${ArrayPrototypeJoin(ArrayPrototypeMap(coverages, (coverage, j) => getCell(NumberPrototypeToFixed(coverage, 2), columnPadLengths[j], StringPrototypePadStart, false, coverage)), kSeparator)}${kSeparator}` +
459495
`${getCell(formatUncoveredLines(getUncoveredLines(file.lines), table), uncoveredLinesPadLength, false, truncateEnd)}\n`;
460496
}

0 commit comments

Comments
 (0)