-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: display dot report as wide as the terminal width
PR-URL: #48038 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
4 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
test/fixtures/test-runner/output/dot_output_custom_columns.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/test-runner/output/dot_output_custom_columns.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.............................. | ||
......................................... | ||
............................. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters