node/test/parallel/test-repl-colors.js
Node.js GitHub Bot 45c2e2514f
tools: update eslint to 9.5.0
PR-URL: https://github.com/nodejs/node/pull/53515
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-06-22 12:54:57 +00:00

34 lines
1.1 KiB
JavaScript

'use strict';
require('../common');
const { Duplex } = require('stream');
const { inspect } = require('util');
const { strictEqual } = require('assert');
const { REPLServer } = require('repl');
let output = '';
const inout = new Duplex({ decodeStrings: false });
inout._read = function() {
this.push('util.inspect("string")\n');
this.push(null);
};
inout._write = function(s, _, cb) {
output += s;
cb();
};
const repl = new REPLServer({ input: inout, output: inout, useColors: true });
inout.isTTY = true;
const repl2 = new REPLServer({ input: inout, output: inout });
process.on('exit', function() {
// https://github.com/nodejs/node/pull/16485#issuecomment-350428638
// The color setting of the REPL should not have leaked over into
// the color setting of `util.inspect.defaultOptions`.
strictEqual(output.includes(`"'string'"`), true);
strictEqual(output.includes(`'\u001b[32m\\'string\\'\u001b[39m'`), false);
strictEqual(inspect.defaultOptions.colors, false);
strictEqual(repl.writer.options.colors, true);
strictEqual(repl2.writer.options.colors, true);
});