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 () => {