mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
test_runner: display dot report as wide as the terminal width
PR-URL: https://github.com/nodejs/node/pull/48038 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
f6725751b7
commit
23d310bee8
4 files changed
+33
-1
No files matched your search
@@ -1,7 +1,9 @@
|
||||
'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 '.';
|
||||
@@ -9,9 +11,17 @@ module.exports = async function* dot(source) {
|
||||
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);
|
||||
}
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
..............................
|
||||
.........................................
|
||||
.............................
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in new issue
Block a user