Skip to content

Commit ce2ed58

Browse files
committed
test: improve tty.getColorDepth coverage
PR-URL: #19446 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
1 parent 2e6dd93 commit ce2ed58

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

test/pseudo-tty/test-tty-get-color-depth.js

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,55 @@ const writeStream = new WriteStream(fd);
1010

1111
{
1212
const depth = writeStream.getColorDepth();
13-
1413
assert.equal(typeof depth, 'number');
1514
assert(depth >= 1 && depth <= 24);
16-
17-
if (depth === 1) {
18-
// Terminal does not support colors, compare to a value that would.
19-
assert.notEqual(writeStream.getColorDepth({ COLORTERM: '1' }), depth);
20-
} else {
21-
// Terminal supports colors, compare to a value that would not.
22-
assert.notEqual(writeStream.getColorDepth({ TERM: 'dumb' }), depth);
23-
}
2415
}
2516

26-
// Deactivate colors
27-
{
28-
const tmp = process.env.NODE_DISABLE_COLORS;
29-
process.env.NODE_DISABLE_COLORS = 1;
30-
31-
const depth = writeStream.getColorDepth();
17+
// Check different environment variables.
18+
[
19+
[{ COLORTERM: '1' }, 4],
20+
[{ TMUX: '1' }, 8],
21+
[{ CI: '1' }, 1],
22+
[{ CI: '1', TRAVIS: '1' }, 8],
23+
[{ CI: '1', CIRCLECI: '1' }, 8],
24+
[{ CI: '1', APPVEYOR: '1' }, 8],
25+
[{ CI: '1', GITLAB_CI: '1' }, 8],
26+
[{ CI: '1', CI_NAME: 'codeship' }, 8],
27+
[{ TEAMCITY_VERSION: '1.0.0' }, 1],
28+
[{ TEAMCITY_VERSION: '9.11.0' }, 4],
29+
[{ TERM_PROGRAM: 'iTerm.app' }, 8],
30+
[{ TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '3.0' }, 24],
31+
[{ TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '2.0' }, 8],
32+
[{ TERM_PROGRAM: 'HyperTerm' }, 24],
33+
[{ TERM_PROGRAM: 'Hyper' }, 24],
34+
[{ TERM_PROGRAM: 'MacTerm' }, 24],
35+
[{ TERM_PROGRAM: 'Apple_Terminal' }, 8],
36+
[{ TERM: 'xterm-256' }, 8],
37+
[{ TERM: 'ansi' }, 4],
38+
[{ TERM: 'ANSI' }, 4],
39+
[{ TERM: 'color' }, 4],
40+
[{ TERM: 'linux' }, 4],
41+
[{ TERM: 'fail' }, 1],
42+
[{ NODE_DISABLE_COLORS: '1' }, 1],
43+
[{ TERM: 'dumb' }, 1],
44+
[{ TERM: 'dumb', COLORTERM: '1' }, 4],
45+
].forEach(([env, depth], i) => {
46+
const actual = writeStream.getColorDepth(env);
47+
assert.equal(
48+
actual,
49+
depth,
50+
`i: ${i}, expected: ${depth}, actual: ${actual}, env: ${env}`
51+
);
52+
});
3253

33-
assert.equal(depth, 1);
54+
// OS settings
55+
{
56+
const platform = Object.getOwnPropertyDescriptor(process, 'platform');
57+
const [ value, depth1, depth2 ] = process.platform !== 'win32' ?
58+
['win32', 1, 4] : ['linux', 4, 1];
3459

35-
process.env.NODE_DISABLE_COLORS = tmp;
60+
assert.equal(writeStream.getColorDepth({}), depth1);
61+
Object.defineProperty(process, 'platform', { value });
62+
assert.equal(writeStream.getColorDepth({}), depth2);
63+
Object.defineProperty(process, 'platform', platform);
3664
}

0 commit comments

Comments
 (0)