summaryrefslogtreecommitdiff
path: root/test/parallel/test-repl-colors.js
blob: f484f57945a16b1f7129590adbd8764f72452589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* eslint-disable quotes */
'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 });

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);
});