1/* eslint-disable quotes */ 2'use strict'; 3require('../common'); 4const { Duplex } = require('stream'); 5const { inspect } = require('util'); 6const { strictEqual } = require('assert'); 7const { REPLServer } = require('repl'); 8 9let output = ''; 10 11const inout = new Duplex({ decodeStrings: false }); 12inout._read = function() { 13 this.push('util.inspect("string")\n'); 14 this.push(null); 15}; 16inout._write = function(s, _, cb) { 17 output += s; 18 cb(); 19}; 20 21const repl = new REPLServer({ input: inout, output: inout, useColors: true }); 22inout.isTTY = true; 23const repl2 = new REPLServer({ input: inout, output: inout }); 24 25process.on('exit', function() { 26 // https://github.com/nodejs/node/pull/16485#issuecomment-350428638 27 // The color setting of the REPL should not have leaked over into 28 // the color setting of `util.inspect.defaultOptions`. 29 strictEqual(output.includes(`"'string'"`), true); 30 strictEqual(output.includes(`'\u001b[32m\\'string\\'\u001b[39m'`), false); 31 strictEqual(inspect.defaultOptions.colors, false); 32 strictEqual(repl.writer.options.colors, true); 33 strictEqual(repl2.writer.options.colors, true); 34}); 35