diff options
author | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2018-02-16 12:12:14 -0500 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2018-02-20 12:31:26 -0500 |
commit | 7514eb3cff9f333882db0a3173247df06c0257e5 (patch) | |
tree | ec1bf7692b0cb4ee682c19e813538072ee8ade97 | |
parent | 92bf2492cd6b78b1ab26765660d912ee34bb90c6 (diff) | |
download | android-node-v8-7514eb3cff9f333882db0a3173247df06c0257e5.tar.gz android-node-v8-7514eb3cff9f333882db0a3173247df06c0257e5.tar.bz2 android-node-v8-7514eb3cff9f333882db0a3173247df06c0257e5.zip |
test: actually test tty `getColorDepth()`
TTY tests should almost never be placed in `/parallel/`. Skipping TTY
tests there due to missing tty fds just means they will never be run,
ever, on any system.
This moves the tty-get-color-depth test to `/pseudo-tty/` where the test
runner will actually make a pty fd.
Refs: https://github.com/nodejs/node/pull/17615
PR-URL: https://github.com/nodejs/node/pull/18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
-rw-r--r-- | test/parallel/test-tty-get-color-depth.js | 35 | ||||
-rw-r--r-- | test/pseudo-tty/test-tty-get-color-depth.js | 36 | ||||
-rw-r--r-- | test/pseudo-tty/test-tty-get-color-depth.out | 0 |
3 files changed, 36 insertions, 35 deletions
diff --git a/test/parallel/test-tty-get-color-depth.js b/test/parallel/test-tty-get-color-depth.js deleted file mode 100644 index e688460171..0000000000 --- a/test/parallel/test-tty-get-color-depth.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -const common = require('../common'); -const assert = require('assert').strict; -/* eslint-disable no-restricted-properties */ -const { WriteStream } = require('tty'); - -const fd = common.getTTYfd(); - -// Give up if we did not find a tty -if (fd === -1) - common.skip(); - -const writeStream = new WriteStream(fd); - -let depth = writeStream.getColorDepth(); - -assert.equal(typeof depth, 'number'); -assert(depth >= 1 && depth <= 24); - -// If the terminal does not support colors, skip the rest -if (depth === 1) - common.skip(); - -assert.notEqual(writeStream.getColorDepth({ TERM: 'dumb' }), depth); - -// Deactivate colors -const tmp = process.env.NODE_DISABLE_COLORS; -process.env.NODE_DISABLE_COLORS = 1; - -depth = writeStream.getColorDepth(); - -assert.equal(depth, 1); - -process.env.NODE_DISABLE_COLORS = tmp; diff --git a/test/pseudo-tty/test-tty-get-color-depth.js b/test/pseudo-tty/test-tty-get-color-depth.js new file mode 100644 index 0000000000..7641290c05 --- /dev/null +++ b/test/pseudo-tty/test-tty-get-color-depth.js @@ -0,0 +1,36 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert').strict; +/* eslint-disable no-restricted-properties */ +const { WriteStream } = require('tty'); + +const fd = common.getTTYfd(); +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(); + + assert.equal(depth, 1); + + process.env.NODE_DISABLE_COLORS = tmp; +} diff --git a/test/pseudo-tty/test-tty-get-color-depth.out b/test/pseudo-tty/test-tty-get-color-depth.out new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/pseudo-tty/test-tty-get-color-depth.out |