diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-05 14:41:49 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-10 00:23:23 +0100 |
commit | 6bdf8d106009e4ed0f3c323d0f0874a51acc8e08 (patch) | |
tree | 57153227fef5cac26ae147e44bf571eee646feef /test/parallel/test-repl-multiline.js | |
parent | 02a0c74861c3107e6a9a1752e91540f8d4c49a76 (diff) | |
download | node-new-6bdf8d106009e4ed0f3c323d0f0874a51acc8e08.tar.gz |
repl: support previews by eager evaluating input
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>
Diffstat (limited to 'test/parallel/test-repl-multiline.js')
-rw-r--r-- | test/parallel/test-repl-multiline.js | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/test/parallel/test-repl-multiline.js b/test/parallel/test-repl-multiline.js index 454d5b1019..6498923b62 100644 --- a/test/parallel/test-repl-multiline.js +++ b/test/parallel/test-repl-multiline.js @@ -3,34 +3,44 @@ const common = require('../common'); const ArrayStream = require('../common/arraystream'); const assert = require('assert'); const repl = require('repl'); -const inputStream = new ArrayStream(); -const outputStream = new ArrayStream(); -const input = ['const foo = {', '};', 'foo;']; -let output = ''; +const input = ['const foo = {', '};', 'foo']; -outputStream.write = (data) => { output += data.replace('\r', ''); }; +function run({ useColors }) { + const inputStream = new ArrayStream(); + const outputStream = new ArrayStream(); + let output = ''; -const r = repl.start({ - prompt: '', - input: inputStream, - output: outputStream, - terminal: true, - useColors: false -}); + outputStream.write = (data) => { output += data.replace('\r', ''); }; -r.on('exit', common.mustCall(() => { - const actual = output.split('\n'); + const r = repl.start({ + prompt: '', + input: inputStream, + output: outputStream, + terminal: true, + useColors + }); - // Validate the output, which contains terminal escape codes. - assert.strictEqual(actual.length, 6); - assert.ok(actual[0].endsWith(input[0])); - assert.ok(actual[1].includes('... ')); - assert.ok(actual[1].endsWith(input[1])); - assert.strictEqual(actual[2], 'undefined'); - assert.ok(actual[3].endsWith(input[2])); - assert.strictEqual(actual[4], '{}'); - // Ignore the last line, which is nothing but escape codes. -})); + r.on('exit', common.mustCall(() => { + const actual = output.split('\n'); -inputStream.run(input); -r.close(); + // 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 }); |