From 23d310bee817581f74e485a4656d7fdf49f2864b Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Tue, 23 May 2023 07:44:38 +0300 Subject: [PATCH] test_runner: display dot report as wide as the terminal width PR-URL: https://github.com/nodejs/node/pull/48038 Reviewed-By: Moshe Atlow Reviewed-By: Colin Ihrig --- lib/internal/test_runner/reporter/dot.js | 12 +++++++++++- .../output/dot_output_custom_columns.js | 18 ++++++++++++++++++ .../output/dot_output_custom_columns.snapshot | 3 +++ test/parallel/test-runner-output.mjs | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/output/dot_output_custom_columns.js create mode 100644 test/fixtures/test-runner/output/dot_output_custom_columns.snapshot diff --git a/lib/internal/test_runner/reporter/dot.js b/lib/internal/test_runner/reporter/dot.js index 7dbba5a957894e..496c819d69ea07 100644 --- a/lib/internal/test_runner/reporter/dot.js +++ b/lib/internal/test_runner/reporter/dot.js @@ -1,7 +1,9 @@ 'use strict'; +const { MathMax } = primordials; module.exports = async function* dot(source) { let count = 0; + let columns = getLineLength(); for await (const { type } of source) { if (type === 'test:pass') { yield '.'; @@ -9,9 +11,17 @@ module.exports = async function* dot(source) { if (type === 'test:fail') { yield 'X'; } - if ((type === 'test:fail' || type === 'test:pass') && ++count % 20 === 0) { + if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) { yield '\n'; + + // Getting again in case the terminal was resized. + columns = getLineLength(); + count = 0; } } yield '\n'; }; + +function getLineLength() { + return MathMax(process.stdout.columns ?? 20, 20); +} diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.js b/test/fixtures/test-runner/output/dot_output_custom_columns.js new file mode 100644 index 00000000000000..875ead9efc22a5 --- /dev/null +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.js @@ -0,0 +1,18 @@ +// Flags: --test-reporter=dot +'use strict'; +process.stdout.columns = 30; + +const test = require('node:test'); +const { setTimeout } = require('timers/promises'); + +for (let i = 0; i < 100; i++) { + test(i + ' example', async () => { + if (i === 0) { + // So the reporter will run before all tests has started + await setTimeout(10); + } + // resize + if (i === 28) + process.stdout.columns = 41; + }); +} diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot b/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot new file mode 100644 index 00000000000000..1aaaf3eb243ae4 --- /dev/null +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot @@ -0,0 +1,3 @@ +.............................. +......................................... +............................. diff --git a/test/parallel/test-runner-output.mjs b/test/parallel/test-runner-output.mjs index d2fa06b4395095..bd8c9f1bd071ee 100644 --- a/test/parallel/test-runner-output.mjs +++ b/test/parallel/test-runner-output.mjs @@ -46,6 +46,7 @@ const tests = [ { name: 'test-runner/output/unresolved_promise.js' }, { name: 'test-runner/output/default_output.js', transform: specTransform, tty: true }, { name: 'test-runner/output/arbitrary-output.js' }, + { name: 'test-runner/output/dot_output_custom_columns.js', transform: specTransform, tty: true }, ].map(({ name, tty, transform }) => ({ name, fn: common.mustCall(async () => {