Skip to content

Commit 7514eb3

Browse files
committed
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: #17615 PR-URL: #18800 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 92bf249 commit 7514eb3

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

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

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert').strict;
5+
/* eslint-disable no-restricted-properties */
6+
const { WriteStream } = require('tty');
7+
8+
const fd = common.getTTYfd();
9+
const writeStream = new WriteStream(fd);
10+
11+
{
12+
const depth = writeStream.getColorDepth();
13+
14+
assert.equal(typeof depth, 'number');
15+
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+
}
24+
}
25+
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();
32+
33+
assert.equal(depth, 1);
34+
35+
process.env.NODE_DISABLE_COLORS = tmp;
36+
}

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

Whitespace-only changes.

0 commit comments

Comments
 (0)