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
21 changes: 14 additions & 7 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,20 @@ const meta = [
];

function getUserOptions(ctx) {
const obj = { stylize: ctx.stylize };
for (const key of ObjectKeys(inspectDefaultOptions)) {
obj[key] = ctx[key];
}
if (ctx.userOptions === undefined)
return obj;
return { ...obj, ...ctx.userOptions };
return {
stylize: ctx.stylize,
showHidden: ctx.showHidden,
depth: ctx.depth,
colors: ctx.colors,
customInspect: ctx.customInspect,
showProxy: ctx.showProxy,
maxArrayLength: ctx.maxArrayLength,
breakLength: ctx.breakLength,
compact: ctx.compact,
sorted: ctx.sorted,
getters: ctx.getters,
...ctx.userOptions
};
}

/**
Expand Down
9 changes: 7 additions & 2 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,10 @@ util.inspect({ hasOwnProperty: null });
assert.strictEqual(opts.budget, undefined);
assert.strictEqual(opts.indentationLvl, undefined);
assert.strictEqual(opts.showHidden, false);
assert.deepStrictEqual(
new Set(Object.keys(util.inspect.defaultOptions).concat(['stylize'])),
new Set(Object.keys(opts))
);
opts.showHidden = true;
return { [util.inspect.custom]: common.mustCall((depth, opts2) => {
assert.deepStrictEqual(clone, opts2);
Expand All @@ -881,10 +885,11 @@ util.inspect({ hasOwnProperty: null });
}

{
const subject = { [util.inspect.custom]: common.mustCall((depth) => {
const subject = { [util.inspect.custom]: common.mustCall((depth, opts) => {
assert.strictEqual(depth, null);
assert.strictEqual(opts.compact, true);
}) };
util.inspect(subject, { depth: null });
util.inspect(subject, { depth: null, compact: true });
}

{
Expand Down