forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-repl-envvars.js
More file actions
62 lines (53 loc) · 1.38 KB
/
test-repl-envvars.js
File metadata and controls
62 lines (53 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
// Flags: --expose-internals
require('../common');
const stream = require('stream');
const REPL = require('internal/repl');
const assert = require('assert');
const debug = require('util').debuglog('test');
const tests = [
{
env: { TERM: 'xterm-256' },
expected: { terminal: true, useColors: true }
},
{
env: { NODE_DISABLE_COLORS: '1' },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: '1' },
expected: { terminal: false, useColors: false }
},
{
env: { TERM: 'dumb' },
expected: { terminal: true, useColors: false }
},
{
env: { NODE_NO_READLINE: '1', NODE_DISABLE_COLORS: '1' },
expected: { terminal: false, useColors: false }
},
{
env: { NODE_NO_READLINE: '0', TERM: 'xterm-256' },
expected: { terminal: true, useColors: true }
}
];
const originalEnv = process.env;
function run(test) {
const env = test.env;
const expected = test.expected;
process.env = { ...originalEnv, ...env };
const opts = {
terminal: true,
input: new stream.Readable({ read() {} }),
output: new stream.Writable({ write() {} })
};
REPL.createInternalRepl(opts, (repl) => {
debug(env);
const { terminal, useColors } = repl;
assert.deepStrictEqual({ terminal, useColors }, expected);
repl.close();
if (tests.length)
run(tests.shift());
});
}
run(tests.shift());