diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-13 01:54:23 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-27 01:24:57 +0100 |
commit | ce2ed584c826f22c94f89ceb2eb60a1facbb7c95 (patch) | |
tree | 0bc95fc39a4c7c2e47f34eab005470421a96cbb9 /test/pseudo-tty | |
parent | 2e6dd93aaa40e9f205a2e84920213effab81bea1 (diff) | |
download | android-node-v8-ce2ed584c826f22c94f89ceb2eb60a1facbb7c95.tar.gz android-node-v8-ce2ed584c826f22c94f89ceb2eb60a1facbb7c95.tar.bz2 android-node-v8-ce2ed584c826f22c94f89ceb2eb60a1facbb7c95.zip |
test: improve tty.getColorDepth coverage
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test/pseudo-tty')
-rw-r--r-- | test/pseudo-tty/test-tty-get-color-depth.js | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/test/pseudo-tty/test-tty-get-color-depth.js b/test/pseudo-tty/test-tty-get-color-depth.js index 7641290c05..d802add118 100644 --- a/test/pseudo-tty/test-tty-get-color-depth.js +++ b/test/pseudo-tty/test-tty-get-color-depth.js @@ -10,27 +10,55 @@ const writeStream = new WriteStream(fd); { const depth = writeStream.getColorDepth(); - assert.equal(typeof depth, 'number'); assert(depth >= 1 && depth <= 24); - - if (depth === 1) { - // Terminal does not support colors, compare to a value that would. - assert.notEqual(writeStream.getColorDepth({ COLORTERM: '1' }), depth); - } else { - // Terminal supports colors, compare to a value that would not. - assert.notEqual(writeStream.getColorDepth({ TERM: 'dumb' }), depth); - } } -// Deactivate colors -{ - const tmp = process.env.NODE_DISABLE_COLORS; - process.env.NODE_DISABLE_COLORS = 1; - - const depth = writeStream.getColorDepth(); +// Check different environment variables. +[ + [{ COLORTERM: '1' }, 4], + [{ TMUX: '1' }, 8], + [{ CI: '1' }, 1], + [{ CI: '1', TRAVIS: '1' }, 8], + [{ CI: '1', CIRCLECI: '1' }, 8], + [{ CI: '1', APPVEYOR: '1' }, 8], + [{ CI: '1', GITLAB_CI: '1' }, 8], + [{ CI: '1', CI_NAME: 'codeship' }, 8], + [{ TEAMCITY_VERSION: '1.0.0' }, 1], + [{ TEAMCITY_VERSION: '9.11.0' }, 4], + [{ TERM_PROGRAM: 'iTerm.app' }, 8], + [{ TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '3.0' }, 24], + [{ TERM_PROGRAM: 'iTerm.app', TERM_PROGRAM_VERSION: '2.0' }, 8], + [{ TERM_PROGRAM: 'HyperTerm' }, 24], + [{ TERM_PROGRAM: 'Hyper' }, 24], + [{ TERM_PROGRAM: 'MacTerm' }, 24], + [{ TERM_PROGRAM: 'Apple_Terminal' }, 8], + [{ TERM: 'xterm-256' }, 8], + [{ TERM: 'ansi' }, 4], + [{ TERM: 'ANSI' }, 4], + [{ TERM: 'color' }, 4], + [{ TERM: 'linux' }, 4], + [{ TERM: 'fail' }, 1], + [{ NODE_DISABLE_COLORS: '1' }, 1], + [{ TERM: 'dumb' }, 1], + [{ TERM: 'dumb', COLORTERM: '1' }, 4], +].forEach(([env, depth], i) => { + const actual = writeStream.getColorDepth(env); + assert.equal( + actual, + depth, + `i: ${i}, expected: ${depth}, actual: ${actual}, env: ${env}` + ); +}); - assert.equal(depth, 1); +// OS settings +{ + const platform = Object.getOwnPropertyDescriptor(process, 'platform'); + const [ value, depth1, depth2 ] = process.platform !== 'win32' ? + ['win32', 1, 4] : ['linux', 4, 1]; - process.env.NODE_DISABLE_COLORS = tmp; + assert.equal(writeStream.getColorDepth({}), depth1); + Object.defineProperty(process, 'platform', { value }); + assert.equal(writeStream.getColorDepth({}), depth2); + Object.defineProperty(process, 'platform', platform); } |