Skip to content

Commit

Permalink
test_runner: display dot report as wide as the terminal width
Browse files Browse the repository at this point in the history
PR-URL: #48038
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
rluvaton authored May 23, 2023
1 parent c55aa01 commit 7e0c12f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/internal/test_runner/reporter/dot.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
'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 '.';
}
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);
}
18 changes: 18 additions & 0 deletions test/fixtures/test-runner/output/dot_output_custom_columns.js
Original file line number Diff line number Diff line change
@@ -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;
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
..............................
.........................................
.............................
1 change: 1 addition & 0 deletions test/parallel/test-runner-output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 7e0c12f

Please sign in to comment.