Skip to content

Commit 7af4903

Browse files
rluvatonCeres6
authored andcommitted
test_runner: display dot report as wide as the terminal width
PR-URL: nodejs#48038 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent a1bd794 commit 7af4903

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed
+11-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
'use strict';
2+
const { MathMax } = primordials;
23

34
module.exports = async function* dot(source) {
45
let count = 0;
6+
let columns = getLineLength();
57
for await (const { type } of source) {
68
if (type === 'test:pass') {
79
yield '.';
810
}
911
if (type === 'test:fail') {
1012
yield 'X';
1113
}
12-
if ((type === 'test:fail' || type === 'test:pass') && ++count % 20 === 0) {
14+
if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) {
1315
yield '\n';
16+
17+
// Getting again in case the terminal was resized.
18+
columns = getLineLength();
19+
count = 0;
1420
}
1521
}
1622
yield '\n';
1723
};
24+
25+
function getLineLength() {
26+
return MathMax(process.stdout.columns ?? 20, 20);
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Flags: --test-reporter=dot
2+
'use strict';
3+
process.stdout.columns = 30;
4+
5+
const test = require('node:test');
6+
const { setTimeout } = require('timers/promises');
7+
8+
for (let i = 0; i < 100; i++) {
9+
test(i + ' example', async () => {
10+
if (i === 0) {
11+
// So the reporter will run before all tests has started
12+
await setTimeout(10);
13+
}
14+
// resize
15+
if (i === 28)
16+
process.stdout.columns = 41;
17+
});
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
..............................
2+
.........................................
3+
.............................

test/parallel/test-runner-output.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const tests = [
4646
{ name: 'test-runner/output/unresolved_promise.js' },
4747
{ name: 'test-runner/output/default_output.js', transform: specTransform, tty: true },
4848
{ name: 'test-runner/output/arbitrary-output.js' },
49+
{ name: 'test-runner/output/dot_output_custom_columns.js', transform: specTransform, tty: true },
4950
].map(({ name, tty, transform }) => ({
5051
name,
5152
fn: common.mustCall(async () => {

0 commit comments

Comments
 (0)