Skip to content

Commit 7b9d6d0

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 1dec9d1 commit 7b9d6d0

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
@@ -2724,3 +2724,28 @@ assert.strictEqual(
27242724
'\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }'
27252725
);
27262726
}
2727+
2728+
// Test changing util.inspect.colors colors and aliases.
2729+
{
2730+
const colors = util.inspect.colors;
2731+
2732+
const originalValue = colors.gray;
2733+
2734+
// "grey" is reference-equal alias of "gray".
2735+
assert.strictEqual(colors.grey, colors.gray);
2736+
2737+
// Assigninging one should assign the other. This tests that the alias setter
2738+
// function keeps things reference-equal.
2739+
colors.gray = [0, 0];
2740+
assert.deepStrictEqual(colors.gray, [0, 0]);
2741+
assert.strictEqual(colors.grey, colors.gray);
2742+
2743+
colors.grey = [1, 1];
2744+
assert.deepStrictEqual(colors.grey, [1, 1]);
2745+
assert.strictEqual(colors.grey, colors.gray);
2746+
2747+
// Restore original value to avoid side effects in other tests.
2748+
colors.gray = originalValue;
2749+
assert.deepStrictEqual(colors.gray, originalValue);
2750+
assert.strictEqual(colors.grey, colors.gray);
2751+
}

0 commit comments

Comments
 (0)