summaryrefslogtreecommitdiff
path: root/test/parallel/test-repl-programmatic-history.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-12-29 13:09:45 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2020-01-10 09:11:50 +0100
commitb52bf605187d65be272a0ab8fb7f5623d8934f18 (patch)
tree9e4c38e36255f31dbaad7968bf8b55b73283d6e7 /test/parallel/test-repl-programmatic-history.js
parentd449c505f3413843b60caf46d5bc3ef17d711830 (diff)
downloadnode-new-b52bf605187d65be272a0ab8fb7f5623d8934f18.tar.gz
readline,repl: improve history up/previous
Reaching the history end caused the last entry to be persistent. That way there's no actualy feedback to the user that the history end is reached. Instead, visualize the original input line and keep the history index at the history end in case the user wants to go back again. PR-URL: https://github.com/nodejs/node/pull/31112 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-repl-programmatic-history.js')
-rw-r--r--test/parallel/test-repl-programmatic-history.js37
1 files changed, 31 insertions, 6 deletions
diff --git a/test/parallel/test-repl-programmatic-history.js b/test/parallel/test-repl-programmatic-history.js
index 7eda401a7c..5307ae0556 100644
--- a/test/parallel/test-repl-programmatic-history.js
+++ b/test/parallel/test-repl-programmatic-history.js
@@ -8,6 +8,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');
const os = require('os');
+const util = require('util');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
@@ -49,6 +50,7 @@ ActionStream.prototype.readable = true;
// Mock keys
const UP = { name: 'up' };
+const DOWN = { name: 'down' };
const ENTER = { name: 'enter' };
const CLEAR = { ctrl: true, name: 'u' };
@@ -88,20 +90,40 @@ const tests = [
},
{
env: {},
- test: [UP, '\'42\'', ENTER],
- expected: [prompt, '\'', '4', '2', '\'', '\'42\'\n', prompt, prompt],
+ test: [UP, '21', ENTER, "'42'", ENTER],
+ expected: [
+ prompt,
+ // TODO(BridgeAR): The line is refreshed too many times. The double prompt
+ // is redundant and can be optimized away.
+ '2', '1', '21\n', prompt, prompt,
+ "'", '4', '2', "'", "'42'\n", prompt, prompt
+ ],
clean: false
},
{ // Requires the above test case
env: {},
- test: [UP, UP, ENTER],
- expected: [prompt, `${prompt}'42'`, '\'42\'\n', prompt]
+ test: [UP, UP, UP, DOWN, ENTER],
+ expected: [
+ prompt,
+ `${prompt}'42'`,
+ `${prompt}21`,
+ prompt,
+ `${prompt}21`,
+ '21\n',
+ prompt
+ ]
},
{
env: { NODE_REPL_HISTORY: historyPath,
NODE_REPL_HISTORY_SIZE: 1 },
- test: [UP, UP, CLEAR],
- expected: [prompt, `${prompt}'you look fabulous today'`, prompt]
+ test: [UP, UP, DOWN, CLEAR],
+ expected: [
+ prompt,
+ `${prompt}'you look fabulous today'`,
+ prompt,
+ `${prompt}'you look fabulous today'`,
+ prompt
+ ]
},
{
env: { NODE_REPL_HISTORY: historyPathFail,
@@ -167,6 +189,8 @@ function runTest(assertCleaned) {
const opts = tests.shift();
if (!opts) return; // All done
+ console.log('NEW');
+
if (assertCleaned) {
try {
assert.strictEqual(fs.readFileSync(defaultHistoryPath, 'utf8'), '');
@@ -192,6 +216,7 @@ function runTest(assertCleaned) {
output: new stream.Writable({
write(chunk, _, next) {
const output = chunk.toString();
+ console.log('INPUT', util.inspect(output));
// Ignore escapes and blank lines
if (output.charCodeAt(0) === 27 || /^[\r\n]+$/.test(output))