mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 17:32:22 +00:00

This makes sure that the described default behavior for the `terminal` option is actually always used and not only when running the REPL as standalone program. The options code is now logically combined instead of being spread out in the big REPL constructor. PR-URL: https://github.com/nodejs/node/pull/26518 Reviewed-By: Lance Ball <lball@redhat.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// Flags: --expose-internals
|
|
|
|
require('../common');
|
|
const stream = require('stream');
|
|
const REPL = require('internal/repl');
|
|
const assert = require('assert');
|
|
const inspect = require('util').inspect;
|
|
|
|
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 }
|
|
}
|
|
];
|
|
|
|
function run(test) {
|
|
const env = test.env;
|
|
const expected = test.expected;
|
|
|
|
const opts = {
|
|
terminal: true,
|
|
input: new stream.Readable({ read() {} }),
|
|
output: new stream.Writable({ write() {} })
|
|
};
|
|
|
|
Object.assign(process.env, env);
|
|
|
|
REPL.createInternalRepl(process.env, opts, function(err, repl) {
|
|
assert.ifError(err);
|
|
|
|
assert.strictEqual(repl.terminal, expected.terminal,
|
|
`Expected ${inspect(expected)} with ${inspect(env)}`);
|
|
assert.strictEqual(repl.useColors, expected.useColors,
|
|
`Expected ${inspect(expected)} with ${inspect(env)}`);
|
|
for (const key of Object.keys(env)) {
|
|
delete process.env[key];
|
|
}
|
|
repl.close();
|
|
});
|
|
}
|
|
|
|
tests.forEach(run);
|