Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: change inspect's default depth from 2 to 4 #23062

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ stream.write('With ES6');
<!-- YAML
added: v0.3.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/23062
description: The `depth` option now defaults to `4` instead of `2`.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/22788
description: The `sorted` option is supported now.
Expand Down Expand Up @@ -401,7 +404,7 @@ changes:
* `depth` {number} Specifies the number of times to recurse while formatting
the `object`. This is useful for inspecting large complicated objects. To
make it recurse up to the maximum call stack size pass `Infinity` or `null`.
**Default:** `2`.
**Default:** `4`.
* `colors` {boolean} If `true`, the output will be styled with ANSI color
codes. Colors are customizable, see [Customizing `util.inspect` colors][].
**Default:** `false`.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);

const inspectDefaultOptions = Object.seal({
showHidden: false,
depth: 2,
depth: 4,
colors: false,
customInspect: true,
showProxy: false,
Expand Down
13 changes: 7 additions & 6 deletions test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ const expected1 = 'Proxy [ {}, {} ]';
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]';
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], {} ],' +
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ],' +
' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ]' +
', Proxy [ Proxy [Array], {} ] ] ]';
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], Proxy [Array]' +
' ],\n Proxy [ Proxy [Array], Proxy [Array] ] ],\n' +
' Proxy [ Proxy [ Proxy [Array], Proxy [Array] ],\n' +
' Proxy [ Proxy [Array], Proxy [Array] ] ] ]';
', Proxy [ Proxy [ {}, {} ], {} ] ] ]';
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ],' +
' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ], Proxy' +
' [ Proxy [ {}, {} ], {} ] ] ],\n Proxy [ Proxy [ Proxy' +
' [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ],\n Proxy' +
' [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ] ] ]';
assert.strictEqual(
util.inspect(proxy1, { showProxy: true, depth: null }),
expected1);
Expand Down
36 changes: 20 additions & 16 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ assert.strictEqual(util.inspect({ a: function*() {} }),
assert.strictEqual(util.inspect({ a: 1, b: 2 }), '{ a: 1, b: 2 }');
assert.strictEqual(util.inspect({ 'a': {} }), '{ a: {} }');
assert.strictEqual(util.inspect({ 'a': { 'b': 2 } }), '{ a: { b: 2 } }');
assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }),
'{ a: { b: { c: [Object] } } }');
assert.strictEqual(util.inspect(
{ 'a': { 'b': { 'c': { 'd': { 'e': { 'f': {} } } } } } }),
'{ a: { b: { c: { d: { e: [Object] } } } } }'
);
assert.strictEqual(
util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }, false, null),
'{ a: { b: { c: { d: 2 } } } }');
Expand Down Expand Up @@ -111,10 +113,12 @@ assert.strictEqual(util.inspect((new JSStream())._externalStream),
}

assert(/Object/.test(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true)
util.inspect({ a: { a: { a: { a: { a: { a: {} } } } } } },
undefined, undefined, true)
));
assert(!/Object/.test(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true)
util.inspect({ a: { a: { a: { a: { a: { a: {} } } } } } },
undefined, null, true)
));

for (const showHidden of [true, false]) {
Expand Down Expand Up @@ -1048,16 +1052,16 @@ if (typeof Symbol !== 'undefined') {

// Empty and circular before depth.
{
const arr = [[[[]]]];
assert.strictEqual(util.inspect(arr), '[ [ [ [] ] ] ]');
arr[0][0][0][0] = [];
assert.strictEqual(util.inspect(arr), '[ [ [ [Array] ] ] ]');
arr[0][0][0] = {};
assert.strictEqual(util.inspect(arr), '[ [ [ {} ] ] ]');
arr[0][0][0] = { a: 2 };
assert.strictEqual(util.inspect(arr), '[ [ [ [Object] ] ] ]');
arr[0][0][0] = arr;
assert.strictEqual(util.inspect(arr), '[ [ [ [Circular] ] ] ]');
const arr = [[[[[[]]]]]];
assert.strictEqual(util.inspect(arr), '[ [ [ [ [ [] ] ] ] ] ]');
arr[0][0][0][0][0][0] = [];
assert.strictEqual(util.inspect(arr), '[ [ [ [ [ [Array] ] ] ] ] ]');
arr[0][0][0][0][0] = {};
assert.strictEqual(util.inspect(arr), '[ [ [ [ [ {} ] ] ] ] ]');
arr[0][0][0][0][0] = { a: 2 };
assert.strictEqual(util.inspect(arr), '[ [ [ [ [ [Object] ] ] ] ] ]');
arr[0][0][0][0][0] = arr;
assert.strictEqual(util.inspect(arr), '[ [ [ [ [ [Circular] ] ] ] ] ]');
}

// Corner cases.
Expand Down Expand Up @@ -1145,7 +1149,7 @@ if (typeof Symbol !== 'undefined') {
// util.inspect.defaultOptions tests.
{
const arr = new Array(101).fill();
const obj = { a: { a: { a: { a: 1 } } } };
const obj = { a: { a: { a: { a: { a: { a: 1 } } } } } };

const oldOptions = Object.assign({}, util.inspect.defaultOptions);

Expand Down Expand Up @@ -1559,7 +1563,7 @@ util.inspect(process);
head = head.next = {};
assert.strictEqual(
util.inspect(list),
'{ next: { next: { next: [Object] } } }'
'{ next: { next: { next: { next: { next: [Object] } } } } }'
);
const longList = util.inspect(list, { depth: Infinity });
const match = longList.match(/next/g);
Expand Down