From c324ad8f7882bc50c25353041d1f4e235fd04157 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Sat, 6 May 2023 22:55:25 +0300 Subject: [PATCH 1/6] test_runner: display dot report as wide as the terminal width --- lib/internal/test_runner/reporter/dot.js | 11 ++++++++++- .../test-runner/output/dot_output_custom_columns.js | 10 ++++++++++ .../output/dot_output_custom_columns.snapshot | 4 ++++ test/parallel/test-runner-output.mjs | 1 + 4 files changed, 25 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..5924e2fd245074 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,16 @@ 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 === 0) { yield '\n'; + + // Getting again in case the terminal was resized. + columns = getLineLength(); } } 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..1a76d9c59b1b99 --- /dev/null +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.js @@ -0,0 +1,10 @@ +// Flags: --test-reporter=dot +'use strict'; +process.stdout.columns = 30; + +require('../../../common'); +const test = require('node:test'); + +for (let i = 0; i < 100; i++) { + test(i + ' example', () => {}); +} \ No newline at end of file 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..00a76aa7f54c36 --- /dev/null +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot @@ -0,0 +1,4 @@ +.............................. +.............................. +.............................. +.......... 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 () => { From b47e380287e0179c57dfb4f5641b3b360ae7ba12 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Fri, 19 May 2023 11:42:42 +0300 Subject: [PATCH 2/6] test_runner: add test and fix error --- lib/internal/test_runner/reporter/dot.js | 1 + .../test-runner/output/dot_output_custom_columns.js | 13 +++++++++++-- .../output/dot_output_custom_columns.snapshot | 5 ++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/internal/test_runner/reporter/dot.js b/lib/internal/test_runner/reporter/dot.js index 5924e2fd245074..bcaa6b08d26a74 100644 --- a/lib/internal/test_runner/reporter/dot.js +++ b/lib/internal/test_runner/reporter/dot.js @@ -16,6 +16,7 @@ module.exports = async function* dot(source) { // Getting again in case the terminal was resized. columns = getLineLength(); + count = 0; } } yield '\n'; diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.js b/test/fixtures/test-runner/output/dot_output_custom_columns.js index 1a76d9c59b1b99..e0d6438164d9d2 100644 --- a/test/fixtures/test-runner/output/dot_output_custom_columns.js +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.js @@ -4,7 +4,16 @@ process.stdout.columns = 30; require('../../../common'); const test = require('node:test'); +const {setTimeout} = require('timers/promises'); for (let i = 0; i < 100; i++) { - test(i + ' example', () => {}); -} \ No newline at end of file + 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 index 00a76aa7f54c36..1aaaf3eb243ae4 100644 --- a/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot @@ -1,4 +1,3 @@ .............................. -.............................. -.............................. -.......... +......................................... +............................. From ae1906c099bcf29e5eeae5b9572d899a65b4f8e7 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Fri, 19 May 2023 11:52:58 +0300 Subject: [PATCH 3/6] Update lib/internal/test_runner/reporter/dot.js Co-authored-by: Moshe Atlow --- lib/internal/test_runner/reporter/dot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/test_runner/reporter/dot.js b/lib/internal/test_runner/reporter/dot.js index bcaa6b08d26a74..496c819d69ea07 100644 --- a/lib/internal/test_runner/reporter/dot.js +++ b/lib/internal/test_runner/reporter/dot.js @@ -11,7 +11,7 @@ module.exports = async function* dot(source) { if (type === 'test:fail') { yield 'X'; } - if ((type === 'test:fail' || type === 'test:pass') && ++count % columns === 0) { + if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) { yield '\n'; // Getting again in case the terminal was resized. From b991fd25e049d2b247a2d33df19ae93b8c8fd5ef Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Sun, 21 May 2023 00:10:20 +0300 Subject: [PATCH 4/6] Update test/fixtures/test-runner/output/dot_output_custom_columns.js Co-authored-by: Antoine du Hamel --- test/fixtures/test-runner/output/dot_output_custom_columns.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.js b/test/fixtures/test-runner/output/dot_output_custom_columns.js index e0d6438164d9d2..da67359360386d 100644 --- a/test/fixtures/test-runner/output/dot_output_custom_columns.js +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.js @@ -2,7 +2,6 @@ 'use strict'; process.stdout.columns = 30; -require('../../../common'); const test = require('node:test'); const {setTimeout} = require('timers/promises'); From d38e661ec4aacf99d7421c83ba023989d16003d2 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Mon, 22 May 2023 07:56:11 +0300 Subject: [PATCH 5/6] Update test/fixtures/test-runner/output/dot_output_custom_columns.js Co-authored-by: cjihrig --- test/fixtures/test-runner/output/dot_output_custom_columns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.js b/test/fixtures/test-runner/output/dot_output_custom_columns.js index da67359360386d..e168bf39e24620 100644 --- a/test/fixtures/test-runner/output/dot_output_custom_columns.js +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.js @@ -3,7 +3,7 @@ process.stdout.columns = 30; const test = require('node:test'); -const {setTimeout} = require('timers/promises'); +const { setTimeout } = require('timers/promises'); for (let i = 0; i < 100; i++) { test(i + ' example', async () => { From ef8cec76e40965f336b5118271ef23d72d760b20 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Mon, 22 May 2023 07:56:19 +0300 Subject: [PATCH 6/6] Update test/fixtures/test-runner/output/dot_output_custom_columns.js Co-authored-by: cjihrig --- test/fixtures/test-runner/output/dot_output_custom_columns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.js b/test/fixtures/test-runner/output/dot_output_custom_columns.js index e168bf39e24620..875ead9efc22a5 100644 --- a/test/fixtures/test-runner/output/dot_output_custom_columns.js +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.js @@ -7,7 +7,7 @@ const { setTimeout } = require('timers/promises'); for (let i = 0; i < 100; i++) { test(i + ' example', async () => { - if(i === 0) { + if (i === 0) { // So the reporter will run before all tests has started await setTimeout(10); }