• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Flags: --expose-internals
4
5require('../common');
6const stream = require('stream');
7const REPL = require('internal/repl');
8const assert = require('assert');
9const inspect = require('util').inspect;
10
11const tests = [
12  {
13    env: {},
14    expected: { terminal: true, useColors: true }
15  },
16  {
17    env: { NODE_DISABLE_COLORS: '1' },
18    expected: { terminal: true, useColors: false }
19  },
20  {
21    env: { NODE_NO_READLINE: '1' },
22    expected: { terminal: false, useColors: false }
23  },
24  {
25    env: { TERM: 'dumb' },
26    expected: { terminal: true, useColors: false }
27  },
28  {
29    env: { NODE_NO_READLINE: '1', NODE_DISABLE_COLORS: '1' },
30    expected: { terminal: false, useColors: false }
31  },
32  {
33    env: { NODE_NO_READLINE: '0' },
34    expected: { terminal: true, useColors: true }
35  },
36];
37
38function run(test) {
39  const env = test.env;
40  const expected = test.expected;
41
42  const opts = {
43    terminal: true,
44    input: new stream.Readable({ read() {} }),
45    output: new stream.Writable({ write() {} })
46  };
47
48  Object.assign(process.env, env);
49
50  REPL.createInternalRepl(process.env, opts, function(err, repl) {
51    assert.ifError(err);
52
53    assert.strictEqual(repl.terminal, expected.terminal,
54                       `Expected ${inspect(expected)} with ${inspect(env)}`);
55    assert.strictEqual(repl.useColors, expected.useColors,
56                       `Expected ${inspect(expected)} with ${inspect(env)}`);
57    for (const key of Object.keys(env)) {
58      delete process.env[key];
59    }
60    repl.close();
61  });
62}
63
64tests.forEach(run);
65