From 697228d48f554dcd83c5b0186bf7e20d642b6e55 Mon Sep 17 00:00:00 2001 From: islandryu Date: Sat, 12 Apr 2025 22:09:18 +0900 Subject: [PATCH] test_runner: match minimum file column to 'all files' --- lib/internal/test_runner/utils.js | 2 +- .../output/coverage-short-filename.mjs | 9 +++++++ .../output/coverage-short-filename.snapshot | 25 +++++++++++++++++++ test/parallel/test-runner-output.mjs | 9 +++++-- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/test-runner/output/coverage-short-filename.mjs create mode 100644 test/fixtures/test-runner/output/coverage-short-filename.snapshot diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index 6cfe0fa8d9e88e..949503d9dbc1d6 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -468,7 +468,7 @@ function getCoverageReport(pad, summary, symbol, color, table) { if (color) { filePadLength += 2; } - filePadLength = MathMax(filePadLength, 'file'.length); + filePadLength = MathMax(filePadLength, 'all files'.length); if (filePadLength > (process.stdout.columns / 2)) { filePadLength = MathFloor(process.stdout.columns / 2); } diff --git a/test/fixtures/test-runner/output/coverage-short-filename.mjs b/test/fixtures/test-runner/output/coverage-short-filename.mjs new file mode 100644 index 00000000000000..b053c15ea5ec00 --- /dev/null +++ b/test/fixtures/test-runner/output/coverage-short-filename.mjs @@ -0,0 +1,9 @@ +// Flags: --experimental-test-coverage +// here we can't import common module as the coverage will be different based on the system +// Unused imports are here in order to populate the coverage report +// eslint-disable-next-line no-unused-vars +import * as a from '../coverage-snap/a.js'; + +import { test } from 'node:test'; + +test(`Coverage Print Short Filename`); diff --git a/test/fixtures/test-runner/output/coverage-short-filename.snapshot b/test/fixtures/test-runner/output/coverage-short-filename.snapshot new file mode 100644 index 00000000000000..22fc1aea5e8d68 --- /dev/null +++ b/test/fixtures/test-runner/output/coverage-short-filename.snapshot @@ -0,0 +1,25 @@ +TAP version 13 +# Subtest: Coverage Print Short Filename +ok 1 - Coverage Print Short Filename + --- + duration_ms: * + type: 'test' + ... +1..1 +# tests 1 +# suites 0 +# pass 1 +# fail 0 +# cancelled 0 +# skipped 0 +# todo 0 +# duration_ms * +# start of coverage report +# --------------------------------------------------------------------------------------- +# file | line % | branch % | funcs % | uncovered lines +# --------------------------------------------------------------------------------------- +# a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52 +# --------------------------------------------------------------------------------------- +# all files | 55.77 | 100.00 | 0.00 | +# --------------------------------------------------------------------------------------- +# end of coverage report diff --git a/test/parallel/test-runner-output.mjs b/test/parallel/test-runner-output.mjs index 4bb22fa2f39d6b..be02fa23805451 100644 --- a/test/parallel/test-runner-output.mjs +++ b/test/parallel/test-runner-output.mjs @@ -308,12 +308,17 @@ const tests = [ name: 'test-runner/output/coverage-width-infinity-uncovered-lines.mjs', flags: ['--test-reporter=tap', '--test-coverage-exclude=!test/**'], } : false, + process.features.inspector ? { + name: 'test-runner/output/coverage-short-filename.mjs', + flags: ['--test-reporter=tap', '--test-coverage-exclude=../output/**'], + cwd: fixtures.path('test-runner/coverage-snap'), + } : false, ] .filter(Boolean) -.map(({ flags, name, tty, transform }) => ({ +.map(({ flags, name, tty, transform, cwd }) => ({ name, fn: common.mustCall(async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty, flags }); + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty, flags, cwd }); }), }));