Skip to content

Commit

Permalink
test_runner: remove unnecessary padding
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarchini committed Aug 30, 2024
1 parent 6968743 commit a561951
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 98 deletions.
7 changes: 5 additions & 2 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ function buildFileTree(summary) {
let longestFile = 0;

ArrayPrototypeForEach(summary.files, (file) => {
let longestPart = 0;
const parts = relative(summary.workingDirectory, file.path).split('/');
let current = tree;
ArrayPrototypeForEach(parts, (part, index) => {
Expand All @@ -424,9 +425,11 @@ function buildFileTree(summary) {
current.file = file;
current.finalPath = parts;
}
// Keep track of the longest part for padding
longestPart = MathMax(longestPart, part.length);
});
treeDepth = MathMax(treeDepth, parts.length);
longestFile = MathMax(longestFile, ...parts.map((part) => part.length));
longestFile = longestPart;
});

return { __proto__: null, tree, treeDepth, longestFile };
Expand All @@ -448,7 +451,7 @@ function getCoverageReport(pad, summary, symbol, color, table) {
// Calculate expected column sizes based on the tree
// Every level of the tree adds 2 to the column size + the longest file name
filePadLength = table && longestFile;
filePadLength += 2 * treeDepth;
filePadLength += 1 * treeDepth;
// Get the maximum length of the file path or 'file'
filePadLength = MathMax(filePadLength, 'file'.length);
const fileWidth = filePadLength + 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ ok 1 - Coverage Print Fixed Width 100
# duration_ms *
# start of coverage report
# --------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# file | line % | branch % | funcs % | uncovered lines
# --------------------------------------------------------------------------------------------------
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 …
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# many-uncovered-lines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 …
# output | | | |
# coverage-width-100-uncovered-lines.mjs | 100.00 | 100.00 | 100.00 |
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# many-uncovered-lines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19
# output | | | |
# coverage-width-100-uncovered-lines.mjs | 100.00 | 100.00 | 100.00 |
# --------------------------------------------------------------------------------------------------
# all files | 52.80 | 60.00 | 1.61 |
# all files | 52.80 | 60.00 | 1.61 |
# --------------------------------------------------------------------------------------------------
# end of coverage report
20 changes: 10 additions & 10 deletions test/fixtures/test-runner/output/coverage-width-100.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ ok 1 - Coverage Print Fixed Width 100
# duration_ms *
# start of coverage report
# --------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# file | line % | branch % | funcs % | uncovered lines
# --------------------------------------------------------------------------------------------------
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-4
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# output | | | |
# coverage-width-100.mjs | 100.00 | 100.00 | 100.00 |
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# output | | | |
# coverage-width-100.mjs | 100.00 | 100.00 | 100.00 |
# --------------------------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# all files | 60.81 | 100.00 | 0.00 |
# --------------------------------------------------------------------------------------------------
# end of coverage report
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ ok 1 - Coverage Print Fixed Width 150
# duration_ms *
# start of coverage report
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# file | line % | branch % | funcs % | uncovered lines
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# many-uncovered-lines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52 55-57 59-61 63-65 67…
# output | | | |
# coverage-width-150-uncovered-lines.mjs | 100.00 | 100.00 | 100.00 |
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# many-uncovered-lines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52 55-57 59-61 63-65 67-69 9
# output | | | |
# coverage-width-150-uncovered-lines.mjs | 100.00 | 100.00 | 100.00 |
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# all files | 52.80 | 60.00 | 1.61 |
# all files | 52.80 | 60.00 | 1.61 |
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# end of coverage report
28 changes: 14 additions & 14 deletions test/fixtures/test-runner/output/coverage-width-150.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ ok 1 - Coverage Print Fixed Width 150
# todo 0
# duration_ms *
# start of coverage report
# --------------------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# --------------------------------------------------------------------------------------------------------------
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# output | | | |
# coverage-width-150.mjs | 100.00 | 100.00 | 100.00 |
# --------------------------------------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# --------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# ---------------------------------------------------------------------------------------------------------
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# output | | | |
# coverage-width-150.mjs | 100.00 | 100.00 | 100.00 |
# ---------------------------------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# ---------------------------------------------------------------------------------------------------------
# end of coverage report
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ ok 1 - Coverage Print Fixed Width 100
# duration_ms *
# start of coverage report
# --------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# file | line % | branch % | funcs % | uncovered lines
# --------------------------------------------------------------------------------------------------
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 1
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# many-uncovered-lines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 1
# output | | | |
# coverage-width-80-uncovered-lines.mjs | 100.00 | 100.00 | 100.00 |
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# many-uncovered-lines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19
# output | | | |
# coverage-width-80-uncovered-lines.mjs | 100.00 | 100.00 | 100.00 |
# --------------------------------------------------------------------------------------------------
# all files | 52.80 | 60.00 | 1.61 |
# all files | 52.80 | 60.00 | 1.61 |
# --------------------------------------------------------------------------------------------------
# end of coverage report
20 changes: 10 additions & 10 deletions test/fixtures/test-runner/output/coverage-width-80.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ ok 1 - Coverage Print Fixed Width 80
# duration_ms *
# start of coverage report
# ------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered li…
# file | line % | branch % | funcs % | uncovered lines
# ------------------------------------------------------------------------------
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-…
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# output | | | |
# coverage-width-80.mjs | 100.00 | 100.00 | 100.00 |
# test | | | |
# fixtures | | | |
# test-runner | | | |
# coverage-snap | | | |
# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17
# b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# output | | | |
# coverage-width-80.mjs | 100.00 | 100.00 | 100.00 |
# ------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# all files | 60.81 | 100.00 | 0.00 |
# ------------------------------------------------------------------------------
# end of coverage report
Loading

0 comments on commit a561951

Please sign in to comment.