mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
This adds input previews by using the inspectors eager evaluation functionality. It is implemented as additional line that is not counted towards the actual input. In case no colors are supported, it will be visible as comment. Otherwise it's grey. It will be triggered on any line change. It is heavily tested against edge cases and adheres to "dumb" terminals (previews are deactived in that case). PR-URL: https://github.com/nodejs/node/pull/30811 Fixes: https://github.com/nodejs/node/issues/20977 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const ArrayStream = require('../common/arraystream');
|
|
const assert = require('assert');
|
|
const repl = require('repl');
|
|
const input = ['const foo = {', '};', 'foo'];
|
|
|
|
function run({ useColors }) {
|
|
const inputStream = new ArrayStream();
|
|
const outputStream = new ArrayStream();
|
|
let output = '';
|
|
|
|
outputStream.write = (data) => { output += data.replace('\r', ''); };
|
|
|
|
const r = repl.start({
|
|
prompt: '',
|
|
input: inputStream,
|
|
output: outputStream,
|
|
terminal: true,
|
|
useColors
|
|
});
|
|
|
|
r.on('exit', common.mustCall(() => {
|
|
const actual = output.split('\n');
|
|
|
|
// Validate the output, which contains terminal escape codes.
|
|
assert.strictEqual(actual.length, 6 + process.features.inspector);
|
|
assert.ok(actual[0].endsWith(input[0]));
|
|
assert.ok(actual[1].includes('... '));
|
|
assert.ok(actual[1].endsWith(input[1]));
|
|
assert.ok(actual[2].includes('undefined'));
|
|
assert.ok(actual[3].endsWith(input[2]));
|
|
if (process.features.inspector) {
|
|
assert.ok(actual[4].includes(actual[5]));
|
|
assert.strictEqual(actual[4].includes('//'), !useColors);
|
|
}
|
|
assert.strictEqual(actual[4 + process.features.inspector], '{}');
|
|
// Ignore the last line, which is nothing but escape codes.
|
|
}));
|
|
|
|
inputStream.run(input);
|
|
r.close();
|
|
}
|
|
|
|
run({ useColors: true });
|
|
run({ useColors: false });
|