Skip to content

Commit 785417a

Browse files
Trottcodebytere
authored andcommitted
util: add coverage for util.inspect.colors alias setter
Add test to confirm that the setter for aliases in `util.inspect.colors` keeps the alias reference-equal to the target value. Refs: https://coverage.nodejs.org/coverage-5b0308cd823a5110/lib/internal/util/inspect.js.html#L357 Refs: https://codecov.io/gh/nodejs/node/src/5b0308cd823a511098dadf9ddd5a35e3a9dbb424/lib/internal/util/inspect.js#L357 PR-URL: #31743 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 7597100 commit 785417a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/parallel/test-util-inspect.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,3 +2702,28 @@ assert.strictEqual(
27022702
'\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }'
27032703
);
27042704
}
2705+
2706+
// Test changing util.inspect.colors colors and aliases.
2707+
{
2708+
const colors = util.inspect.colors;
2709+
2710+
const originalValue = colors.gray;
2711+
2712+
// "grey" is reference-equal alias of "gray".
2713+
assert.strictEqual(colors.grey, colors.gray);
2714+
2715+
// Assigninging one should assign the other. This tests that the alias setter
2716+
// function keeps things reference-equal.
2717+
colors.gray = [0, 0];
2718+
assert.deepStrictEqual(colors.gray, [0, 0]);
2719+
assert.strictEqual(colors.grey, colors.gray);
2720+
2721+
colors.grey = [1, 1];
2722+
assert.deepStrictEqual(colors.grey, [1, 1]);
2723+
assert.strictEqual(colors.grey, colors.gray);
2724+
2725+
// Restore original value to avoid side effects in other tests.
2726+
colors.gray = originalValue;
2727+
assert.deepStrictEqual(colors.gray, originalValue);
2728+
assert.strictEqual(colors.grey, colors.gray);
2729+
}

0 commit comments

Comments
 (0)