GeezerVison is showing github.com — test_runner: display dot report as wide as the terminal width · nodejs/node@23d310b
File tree
Expand file treeCollapse file tree
Open diff view settings
lib/internal/test_runner/reporter fixtures/test-runner/output
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | 'use strict'; |
| 2 | +const { MathMax } = primordials; |
2 | 3 |
|
3 | 4 | module.exports = async function* dot(source) { |
4 | 5 | let count = 0; |
| 6 | + let columns = getLineLength(); |
5 | 7 | for await (const { type } of source) { |
6 | 8 | if (type === 'test:pass') { |
7 | 9 | yield '.'; |
8 | 10 | } |
9 | 11 | if (type === 'test:fail') { |
10 | 12 | yield 'X'; |
11 | 13 | } |
12 | | - if ((type === 'test:fail' || type === 'test:pass') && ++count % 20 === 0) { |
| 14 | + if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) { |
13 | 15 | yield '\n'; |
| 16 | + |
| 17 | + // Getting again in case the terminal was resized. |
| 18 | + columns = getLineLength(); |
| 19 | + count = 0; |
14 | 20 | } |
15 | 21 | } |
16 | 22 | yield '\n'; |
17 | 23 | }; |
| 24 | + |
| 25 | +function getLineLength() { |
| 26 | + return MathMax(process.stdout.columns ?? 20, 20); |
| 27 | +} |
Collapse file
Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |
Collapse file
Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +.............................. |
| 2 | +......................................... |
| 3 | +............................. |
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-runner-output.mjs +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,6 +46,7 @@ const tests = [ |
46 | 46 | { name: 'test-runner/output/unresolved_promise.js' }, |
47 | 47 | { name: 'test-runner/output/default_output.js', transform: specTransform, tty: true }, |
48 | 48 | { name: 'test-runner/output/arbitrary-output.js' }, |
| 49 | + { name: 'test-runner/output/dot_output_custom_columns.js', transform: specTransform, tty: true }, |
49 | 50 | ].map(({ name, tty, transform }) => ({ |
50 | 51 | name, |
51 | 52 | fn: common.mustCall(async () => { |
|