node/test/parallel/test-repl-envvars.js
Ruben Bridgewater becc3ec372
test: remove common.globalCheck
This flag is partially used in tests where it was not necessary and
it is always possible to replace this flag with
`common.allowGlobals`. This makes sure all globals are truly tested
for.

PR-URL: https://github.com/nodejs/node/pull/20717
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-05-19 17:55:57 +02:00

59 lines
1.4 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 = Object.assign({}, process.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) {
assert.ifError(err);
assert.strictEqual(expected.terminal, repl.terminal,
`Expected ${inspect(expected)} with ${inspect(env)}`);
assert.strictEqual(expected.useColors, repl.useColors,
`Expected ${inspect(expected)} with ${inspect(env)}`);
repl.close();
});
}
tests.forEach(run);