Skip to content

Commit

Permalink
util: add coverage for util.inspect.colors alias setter
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Trott authored and codebytere committed Mar 30, 2020
1 parent 7597100 commit 785417a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2702,3 +2702,28 @@ assert.strictEqual(
'\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }'
);
}

// Test changing util.inspect.colors colors and aliases.
{
const colors = util.inspect.colors;

const originalValue = colors.gray;

// "grey" is reference-equal alias of "gray".
assert.strictEqual(colors.grey, colors.gray);

// Assigninging one should assign the other. This tests that the alias setter
// function keeps things reference-equal.
colors.gray = [0, 0];
assert.deepStrictEqual(colors.gray, [0, 0]);
assert.strictEqual(colors.grey, colors.gray);

colors.grey = [1, 1];
assert.deepStrictEqual(colors.grey, [1, 1]);
assert.strictEqual(colors.grey, colors.gray);

// Restore original value to avoid side effects in other tests.
colors.gray = originalValue;
assert.deepStrictEqual(colors.gray, originalValue);
assert.strictEqual(colors.grey, colors.gray);
}

0 comments on commit 785417a

Please sign in to comment.