Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
util: change inspect compact and breakLength default
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.
  • Loading branch information
BridgeAR committed Apr 5, 2019
commit 3b0b59b997c12f38debd42c859faa72b891096d2
4 changes: 2 additions & 2 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const inspectDefaultOptions = Object.seal({
customInspect: true,
showProxy: false,
maxArrayLength: 100,
breakLength: 60,
compact: true,
breakLength: 80,
compact: 3,
sorted: false,
getters: false
});
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-console-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ function teardown() {
const expectedOut = 'not indented\n' +
' indented\n' +
' also indented\n' +
" { also: 'a',\n" +
' {\n' +
" also: 'a',\n" +
" multiline: 'object',\n" +
" should: 'be',\n" +
" indented: 'properly',\n" +
" kthx: 'bai' }\n";
" kthx: 'bai'\n" +
' }\n';
const expectedErr = '';

c.log('not indented');
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ for (const expected of expectedStrings) {
}

assert.strictEqual(strings.shift(),
"{ foo: 'bar',\n [Symbol(nodejs.util.inspect.custom)]: " +
'[Function: [nodejs.util.inspect.custom]] }\n');
"{\n foo: 'bar',\n [Symbol(nodejs.util.inspect.custom)]:" +
' [Function: [nodejs.util.inspect.custom]]\n}\n');
assert.strictEqual(strings.shift(),
"{ foo: 'bar',\n [Symbol(nodejs.util.inspect.custom)]: " +
'[Function: [nodejs.util.inspect.custom]] }\n');
"{\n foo: 'bar',\n [Symbol(nodejs.util.inspect.custom)]:" +
' [Function: [nodejs.util.inspect.custom]]\n}\n');
assert.ok(strings.shift().includes('foo: [Object]'));
assert.strictEqual(strings.shift().includes('baz'), false);
assert.strictEqual(strings.shift(), 'inspect inspect\n');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-stream-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
assert.strictEqual(stream.aborted, false);
const insp = util.inspect(stream);
assert.ok(/Http2Stream { id/.test(insp));
assert.ok(/Http2Stream {/.test(insp));
assert.ok(/ state:/.test(insp));
assert.ok(/ readableState:/.test(insp));
assert.ok(/ writableState:/.test(insp));
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-repl-pretty-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function run({ command, expected, ...extraREPLOptions }) {

const tests = [
{
// test .load for a file that throws
// Test .load for a file that throws.
command: `.load ${fixtures.path('repl-pretty-stack.js')}`,
expected: 'Thrown:\nError: Whoops!\n at repl:9:24\n' +
' at d (repl:12:3)\n at c (repl:9:3)\n' +
Expand All @@ -48,20 +48,20 @@ const tests = [
{
command: '(() => { const err = Error(\'Whoops!\'); ' +
'err.foo = \'bar\'; throw err; })()',
expected: 'Thrown:\n{ Error: Whoops!\n at repl:1:22\n foo: \'bar\' }\n',
expected: "Thrown:\nError: Whoops!\n at repl:1:22 {\n foo: 'bar'\n}\n",
},
{
command: '(() => { const err = Error(\'Whoops!\'); ' +
'err.foo = \'bar\'; throw err; })()',
expected: 'Thrown:\n{ Error: Whoops!\n at repl:1:22\n foo: ' +
"\u001b[32m'bar'\u001b[39m }\n",
expected: 'Thrown:\nError: Whoops!\n at repl:1:22 {\n foo: ' +
"\u001b[32m'bar'\u001b[39m\n}\n",
useColors: true
},
{
command: 'foo = bar;',
expected: 'Thrown:\nReferenceError: bar is not defined\n'
},
// test anonymous IIFE
// Test anonymous IIFE.
{
command: '(function() { throw new Error(\'Whoops!\'); })()',
expected: 'Thrown:\nError: Whoops!\n at repl:1:21\n'
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-repl-underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ function testError() {

// The sync error, with individual property echoes
'Thrown:',
/^{ Error: ENOENT: no such file or directory, scandir '.*nonexistent.*'/,
/^Error: ENOENT: no such file or directory, scandir '.*nonexistent\?'/,
/Object\.readdirSync/,
/^ errno: -(2|4058),$/,
" syscall: 'scandir',",
" code: 'ENOENT',",
" path: '/nonexistent?' }",
" path: '/nonexistent?'",
'}',
"'ENOENT'",
"'scandir'",

Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,16 @@ const errorTests = [
send: 'require("internal/repl")',
expect: [
'Thrown:',
/^{ Error: Cannot find module 'internal\/repl'/,
/^Error: Cannot find module 'internal\/repl'/,
/^Require stack:/,
/^- <repl>/,
/^ at .*/,
/^ at .*/,
/^ at .*/,
/^ at .*/,
" code: 'MODULE_NOT_FOUND',",
" requireStack: [ '<repl>' ] }"
" requireStack: [ '<repl>' ]",
'}'
]
},
// REPL should handle quotes within regexp literal in multiline mode
Expand Down
95 changes: 55 additions & 40 deletions test/parallel/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,59 +165,74 @@ assert.strictEqual(util.format('%o', 42), '42');
assert.strictEqual(util.format('%o', 'foo'), '\'foo\'');
assert.strictEqual(
util.format('%o', obj),
'{ foo: \'bar\',\n' +
'{\n' +
' foo: \'bar\',\n' +
' foobar: 1,\n' +
' func:\n' +
' { [Function: func]\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] } } }');
' func: [Function: func] {\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] }\n' +
' }\n' +
'}');
assert.strictEqual(
util.format('%o', nestedObj2),
'{ foo: \'bar\',\n' +
'{\n' +
' foo: \'bar\',\n' +
' foobar: 1,\n' +
' func:\n' +
' [ { a:\n' +
' { [Function: a]\n' +
' [length]: 0,\n' +
' [name]: \'a\',\n' +
' [prototype]: a { [constructor]: [Circular] } } },\n' +
' [length]: 1 ] }');
' func: [\n' +
' {\n' +
' a: [Function: a] {\n' +
' [length]: 0,\n' +
' [name]: \'a\',\n' +
' [prototype]: a { [constructor]: [Circular] }\n' +
' }\n' +
' },\n' +
' [length]: 1\n' +
' ]\n' +
'}');
assert.strictEqual(
util.format('%o', nestedObj),
'{ foo: \'bar\',\n' +
' foobar:\n' +
' { foo: \'bar\',\n' +
' func:\n' +
' { [Function: func]\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] } } } }');
'{\n' +
' foo: \'bar\',\n' +
' foobar: {\n' +
' foo: \'bar\',\n' +
' func: [Function: func] {\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] }\n' +
' }\n' +
' }\n' +
'}');
assert.strictEqual(
util.format('%o %o', obj, obj),
'{ foo: \'bar\',\n' +
'{\n' +
' foo: \'bar\',\n' +
' foobar: 1,\n' +
' func:\n' +
' { [Function: func]\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] } } }' +
' { foo: \'bar\',\n' +
' func: [Function: func] {\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] }\n' +
' }\n' +
'} {\n' +
' foo: \'bar\',\n' +
' foobar: 1,\n' +
' func:\n' +
' { [Function: func]\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] } } }');
' func: [Function: func] {\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] }\n' +
' }\n' +
'}');
assert.strictEqual(
util.format('%o %o', obj),
'{ foo: \'bar\',\n' +
'{\n' +
' foo: \'bar\',\n' +
' foobar: 1,\n' +
' func:\n' +
' { [Function: func]\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] } } } %o');
' func: [Function: func] {\n' +
' [length]: 0,\n' +
' [name]: \'func\',\n' +
' [prototype]: func { [constructor]: [Circular] }\n' +
' }\n' +
'} %o');

assert.strictEqual(util.format('%O'), '%O');
assert.strictEqual(util.format('%O', 42), '42');
Expand Down
17 changes: 12 additions & 5 deletions test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ assert.strictEqual(
util.inspect(proxyObj, opts),
'Proxy [\n' +
' [ 1, 2, 3 ],\n' +
' { getPrototypeOf: [Function: getPrototypeOf],\n' +
' {\n' +
' getPrototypeOf: [Function: getPrototypeOf],\n' +
' setPrototypeOf: [Function: setPrototypeOf],\n' +
' isExtensible: [Function: isExtensible],\n' +
' preventExtensions: [Function: preventExtensions],\n' +
Expand All @@ -63,7 +64,9 @@ assert.strictEqual(
' deleteProperty: [Function: deleteProperty],\n' +
' ownKeys: [Function: ownKeys],\n' +
' apply: [Function: apply],\n' +
' construct: [Function: construct] } ]'
' construct: [Function: construct]\n' +
' }\n' +
']'
);

// Using getProxyDetails with non-proxy returns undefined
Expand All @@ -89,14 +92,18 @@ const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]';
const expected5 = 'Proxy [\n ' +
'Proxy [ Proxy [ Proxy [Array], {} ], Proxy [ {}, {} ] ],\n' +
' Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [Array], {} ] ] ]';
' Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [Array], {} ] ]' +
'\n]';
const expected6 = 'Proxy [\n' +
' Proxy [\n' +
' Proxy [ Proxy [Array], Proxy [Array] ],\n' +
' Proxy [ Proxy [Array], Proxy [Array] ] ],\n' +
' Proxy [ Proxy [Array], Proxy [Array] ]\n' +
' ],\n' +
' Proxy [\n' +
' Proxy [ Proxy [Array], Proxy [Array] ],\n' +
' Proxy [ Proxy [Array], Proxy [Array] ] ] ]';
' Proxy [ Proxy [Array], Proxy [Array] ]\n' +
' ]\n' +
']';
assert.strictEqual(
util.inspect(proxy1, { showProxy: true, depth: null }),
expected1);
Expand Down
Loading