diff --git a/lib/util.js b/lib/util.js index d9306643a9c216..16a31eade17077 100644 --- a/lib/util.js +++ b/lib/util.js @@ -717,14 +717,14 @@ function formatValue(ctx, value, recurseTimes) { if (ctx.showHidden) { formatter = formatWeakSet; } else { - extra = '[items unknown]'; + extra = ctx.stylize('[items unknown]', 'special'); } } else if (isWeakMap(value)) { braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`; if (ctx.showHidden) { formatter = formatWeakMap; } else { - extra = '[items unknown]'; + extra = ctx.stylize('[items unknown]', 'special'); } } else if (types.isModuleNamespaceObject(value)) { braces[0] = `[${tag}] {`; @@ -1162,14 +1162,18 @@ function formatPromise(ctx, value, recurseTimes, keys) { let output; const [state, result] = getPromiseDetails(value); if (state === kPending) { - output = ['']; + output = [ctx.stylize('', 'special')]; } else { // Using `formatValue` is correct here without the need to fix the // indentation level. ctx.indentationLvl += 2; const str = formatValue(ctx, result, recurseTimes); ctx.indentationLvl -= 2; - output = [state === kRejected ? ` ${str}` : str]; + output = [ + state === kRejected ? + `${ctx.stylize('', 'special')} ${str}` : + str + ]; } for (var n = 0; n < keys.length; n++) { output.push(formatProperty(ctx, value, recurseTimes, keys[n], 0)); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index e948b9861ba908..78a632a0d55d21 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1688,3 +1688,30 @@ assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]'); '{ [Non\\nenumerable\\tkey]: true }' ); } + +// Check for special colors. +{ + const special = inspect.colors[inspect.styles.special]; + const string = inspect.colors[inspect.styles.string]; + + assert.strictEqual( + inspect(new WeakSet(), { colors: true }), + `WeakSet { \u001b[${special[0]}m[items unknown]\u001b[${special[1]}m }` + ); + assert.strictEqual( + inspect(new WeakMap(), { colors: true }), + `WeakMap { \u001b[${special[0]}m[items unknown]\u001b[${special[1]}m }` + ); + assert.strictEqual( + inspect(new Promise(() => {}), { colors: true }), + `Promise { \u001b[${special[0]}m\u001b[${special[1]}m }` + ); + + const rejection = Promise.reject('Oh no!'); + assert.strictEqual( + inspect(rejection, { colors: true }), + `Promise { \u001b[${special[0]}m\u001b[${special[1]}m ` + + `\u001b[${string[0]}m'Oh no!'\u001b[${string[1]}m }` + ); + rejection.catch(() => {}); +}