Skip to content

Commit

Permalink
test: add multiline repl input regression test
Browse files Browse the repository at this point in the history
This commit adds a regression test for
de848ac, which broke
multiline input in the REPL.

PR-URL: #18718
Refs: #17828
Refs: #18715
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Feb 21, 2018
1 parent 18c4933 commit d6786d2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/parallel/test-repl-multiline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
const inputStream = new common.ArrayStream();
const outputStream = new common.ArrayStream();
const input = ['var foo = {', '};', 'foo;'];
let output = '';

outputStream.write = (data) => { output += data.replace('\r', ''); };

const r = repl.start({
prompt: '',
input: inputStream,
output: outputStream,
terminal: true,
useColors: false
});

r.on('exit', common.mustCall(() => {
const actual = output.split('\n');

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

inputStream.run(input);
r.close();

0 comments on commit d6786d2

Please sign in to comment.