2015-09-05 18:03:46 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Flags: --expose-internals
|
|
|
|
|
2018-05-14 16:16:33 +02:00
|
|
|
require('../common');
|
2015-09-05 18:03:46 +03:00
|
|
|
const stream = require('stream');
|
|
|
|
const REPL = require('internal/repl');
|
|
|
|
const assert = require('assert');
|
|
|
|
const inspect = require('util').inspect;
|
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const tests = [
|
|
|
|
{
|
|
|
|
env: {},
|
|
|
|
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' },
|
|
|
|
expected: { terminal: true, useColors: true }
|
|
|
|
}
|
|
|
|
];
|
2015-09-05 18:03:46 +03:00
|
|
|
|
|
|
|
function run(test) {
|
2017-08-15 19:14:54 +01:00
|
|
|
const env = Object.assign({}, process.env, test.env);
|
2015-09-05 18:03:46 +03:00
|
|
|
const expected = test.expected;
|
|
|
|
const opts = {
|
|
|
|
terminal: true,
|
|
|
|
input: new stream.Readable({ read() {} }),
|
|
|
|
output: new stream.Writable({ write() {} })
|
|
|
|
};
|
|
|
|
|
|
|
|
REPL.createInternalRepl(env, opts, function(err, repl) {
|
2016-12-30 10:54:01 -05:00
|
|
|
assert.ifError(err);
|
2016-07-21 13:17:07 -04:00
|
|
|
|
2018-11-24 16:36:59 +09:00
|
|
|
assert.strictEqual(repl.terminal, expected.terminal,
|
2017-04-28 04:06:42 +03:00
|
|
|
`Expected ${inspect(expected)} with ${inspect(env)}`);
|
2018-11-24 16:36:59 +09:00
|
|
|
assert.strictEqual(repl.useColors, expected.useColors,
|
2017-04-28 04:06:42 +03:00
|
|
|
`Expected ${inspect(expected)} with ${inspect(env)}`);
|
2015-09-05 18:03:46 +03:00
|
|
|
repl.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
tests.forEach(run);
|