mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 18:44:40 +00:00

This changes the `compact` default from `true` to `3`. That mode changes arrays to be grouped together, it alignes multiple small entries on a single line in similar to `compact` true but only for the most inner three depth levels and the closing brackets are always on the same indentation as the openeing of the object instead of at the same line as another property. Big strings will be naturally broken into multiple lines instead of having one huge line that is not well readable. The output size mainly stays the same that way while it will be smaller in case of big arrays. Increasing the `breakLength` to 80 adjusts for most terminals that support at least 80 characters in a single line and improves the general output that way. A lot of calculations use the `breakLength` to determine the concrete behavior. PR-URL: https://github.com/nodejs/node/pull/27109 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
156 lines
3.8 KiB
JavaScript
156 lines
3.8 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const {
|
|
hijackStdout,
|
|
hijackStderr,
|
|
restoreStdout,
|
|
restoreStderr
|
|
} = require('../common/hijackstdio');
|
|
|
|
const assert = require('assert');
|
|
const Console = require('console').Console;
|
|
|
|
let c, stdout, stderr;
|
|
|
|
function setup() {
|
|
stdout = '';
|
|
hijackStdout(function(data) {
|
|
stdout += data;
|
|
});
|
|
|
|
stderr = '';
|
|
hijackStderr(function(data) {
|
|
stderr += data;
|
|
});
|
|
|
|
c = new Console(process.stdout, process.stderr);
|
|
}
|
|
|
|
function teardown() {
|
|
restoreStdout();
|
|
restoreStderr();
|
|
}
|
|
|
|
// Basic group() functionality
|
|
{
|
|
setup();
|
|
const expectedOut = 'This is the outer level\n' +
|
|
' Level 2\n' +
|
|
' Level 3\n' +
|
|
' Back to level 2\n' +
|
|
'Back to the outer level\n' +
|
|
'Still at the outer level\n';
|
|
|
|
|
|
const expectedErr = ' More of level 3\n';
|
|
|
|
c.log('This is the outer level');
|
|
c.group();
|
|
c.log('Level 2');
|
|
c.group();
|
|
c.log('Level 3');
|
|
c.warn('More of level 3');
|
|
c.groupEnd();
|
|
c.log('Back to level 2');
|
|
c.groupEnd();
|
|
c.log('Back to the outer level');
|
|
c.groupEnd();
|
|
c.log('Still at the outer level');
|
|
|
|
assert.strictEqual(stdout, expectedOut);
|
|
assert.strictEqual(stderr, expectedErr);
|
|
teardown();
|
|
}
|
|
|
|
// Group indentation is tracked per Console instance.
|
|
{
|
|
setup();
|
|
const expectedOut = 'No indentation\n' +
|
|
'None here either\n' +
|
|
' Now the first console is indenting\n' +
|
|
'But the second one does not\n';
|
|
const expectedErr = '';
|
|
|
|
const c2 = new Console(process.stdout, process.stderr);
|
|
c.log('No indentation');
|
|
c2.log('None here either');
|
|
c.group();
|
|
c.log('Now the first console is indenting');
|
|
c2.log('But the second one does not');
|
|
|
|
assert.strictEqual(stdout, expectedOut);
|
|
assert.strictEqual(stderr, expectedErr);
|
|
teardown();
|
|
}
|
|
|
|
// Make sure labels work.
|
|
{
|
|
setup();
|
|
const expectedOut = 'This is a label\n' +
|
|
' And this is the data for that label\n';
|
|
const expectedErr = '';
|
|
|
|
c.group('This is a label');
|
|
c.log('And this is the data for that label');
|
|
|
|
assert.strictEqual(stdout, expectedOut);
|
|
assert.strictEqual(stderr, expectedErr);
|
|
teardown();
|
|
}
|
|
|
|
// Check that console.groupCollapsed() is an alias of console.group()
|
|
{
|
|
setup();
|
|
const expectedOut = 'Label\n' +
|
|
' Level 2\n' +
|
|
' Level 3\n';
|
|
const expectedErr = '';
|
|
|
|
c.groupCollapsed('Label');
|
|
c.log('Level 2');
|
|
c.groupCollapsed();
|
|
c.log('Level 3');
|
|
|
|
assert.strictEqual(stdout, expectedOut);
|
|
assert.strictEqual(stderr, expectedErr);
|
|
teardown();
|
|
}
|
|
|
|
// Check that multiline strings and object output are indented properly.
|
|
{
|
|
setup();
|
|
const expectedOut = 'not indented\n' +
|
|
' indented\n' +
|
|
' also indented\n' +
|
|
' {\n' +
|
|
" also: 'a',\n" +
|
|
" multiline: 'object',\n" +
|
|
" should: 'be',\n" +
|
|
" indented: 'properly',\n" +
|
|
" kthx: 'bai'\n" +
|
|
' }\n';
|
|
const expectedErr = '';
|
|
|
|
c.log('not indented');
|
|
c.group();
|
|
c.log('indented\nalso indented');
|
|
c.log({ also: 'a',
|
|
multiline: 'object',
|
|
should: 'be',
|
|
indented: 'properly',
|
|
kthx: 'bai' });
|
|
|
|
assert.strictEqual(stdout, expectedOut);
|
|
assert.strictEqual(stderr, expectedErr);
|
|
teardown();
|
|
}
|
|
|
|
// Check that the kGroupIndent symbol property is not enumerable
|
|
{
|
|
const keys = Reflect.ownKeys(console)
|
|
.filter((val) => console.propertyIsEnumerable(val))
|
|
.map((val) => val.toString());
|
|
assert(!keys.includes('Symbol(groupIndent)'),
|
|
'groupIndent should not be enumerable');
|
|
}
|