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

The createInternalRepl() module accepts an options object as an argument. However, if one is provided, it overrides all of the default options. This commit applies the options object to the defaults, only changing the values that are explicitly set. PR-URL: https://github.com/nodejs/node/pull/7826 Reviewed-By: James M Snell <jasnell@gmail.com>
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// Flags: --expose-internals
|
|
|
|
const common = 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() {} })
|
|
};
|
|
|
|
REPL.createInternalRepl(env, opts, function(err, repl) {
|
|
if (err) throw err;
|
|
|
|
// The REPL registers 'module' and 'require' globals
|
|
common.allowGlobals(repl.context.module, repl.context.require);
|
|
|
|
assert.equal(expected.terminal, repl.terminal,
|
|
'Expected ' + inspect(expected) + ' with ' + inspect(env));
|
|
assert.equal(expected.useColors, repl.useColors,
|
|
'Expected ' + inspect(expected) + ' with ' + inspect(env));
|
|
repl.close();
|
|
});
|
|
}
|
|
|
|
tests.forEach(run);
|