Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: display dot report as wide as the terminal width #48038

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the ++count === columns be nested inside of the top level if? That way we only need to call getLineLength() once from there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The need to call again is in case of resize of the terminal

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