Skip to content
Open
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 lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,10 @@ function reduceToSingleString(
// Consolidate all entries of the local most inner depth up to
// `ctx.compact`, as long as the properties are smaller than
// `ctx.breakLength`.
if (ctx.currentDepth - recurseTimes < ctx.compact &&
if (((ctx.breakLength === Infinity &&
(ctx.depth === Infinity || ctx.depth === null) &&
ctx.compact === 3) ||
ctx.currentDepth - recurseTimes < ctx.compact) &&
entries === output.length) {
// Line up all entries on a single line in case the entries do not
// exceed `breakLength`. Add 10 as constant to start next to all other
Expand Down
36 changes: 36 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,36 @@ if (typeof Symbol !== 'undefined') {
assert.strictEqual(twoLines, "{\n foo: 'abc',\n bar: 'xyz'\n}");
}

{
const obj = {
a: {
b: {
c: {
d: 1,
},
},
},
};

assert.strictEqual(
util.inspect(obj, { breakLength: Infinity, depth: Infinity }),
'{ a: { b: { c: { d: 1 } } } }',
);
assert.strictEqual(
util.inspect(obj, { breakLength: Infinity, depth: null }),
'{ a: { b: { c: { d: 1 } } } }',
);
assert.strictEqual(
util.inspect(obj, { breakLength: Infinity, depth: Infinity, compact: 3 }),
'{ a: { b: { c: { d: 1 } } } }',
);

assert.strictEqual(
util.inspect(obj, { breakLength: Infinity, depth: Infinity, compact: 1 }),
'{\n a: {\n b: {\n c: { d: 1 }\n }\n }\n}',
);
}

// util.inspect.defaultOptions tests.
{
const arr = new Array(101).fill();
Expand All @@ -1631,6 +1661,12 @@ if (typeof Symbol !== 'undefined') {
assert.doesNotMatch(util.inspect(obj), /Object/);
util.inspect.defaultOptions.depth = oldOptions.depth;
assert.match(util.inspect(obj), /Object/);
util.inspect.defaultOptions.compact = 1;
assert.strictEqual(
util.inspect(obj, { breakLength: Infinity, depth: Infinity }),
'{\n a: {\n a: {\n a: { a: 1 }\n }\n }\n}',
);
util.inspect.defaultOptions.compact = oldOptions.compact;
assert.strictEqual(
JSON.stringify(util.inspect.defaultOptions),
JSON.stringify(oldOptions)
Expand Down
Loading