0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-repl-load-multiline.js
Ruben Bridgewater 1fc373bdf6
Revert "repl: refactor tests to not rely on timing"
This reverts commit de848ac1e0.

The commit broke multiline repl.

PR-URL: https://github.com/nodejs/node/pull/18715
Refs: https://github.com/nodejs/node/pull/17828
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-02-12 15:42:06 +01:00

41 lines
1005 B
JavaScript

'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const repl = require('repl');
common.crashOnUnhandledRejection();
const command = `.load ${fixtures.path('repl-load-multiline.js')}`;
const terminalCode = '\u001b[1G\u001b[0J \u001b[1G';
const terminalCodeRegex = new RegExp(terminalCode.replace(/\[/g, '\\['), 'g');
const expected = `${command}
const getLunch = () =>
placeOrder('tacos')
.then(eat);
const placeOrder = (order) => Promise.resolve(order);
const eat = (food) => '<nom nom nom>';
undefined
`;
let accum = '';
const inputStream = new common.ArrayStream();
const outputStream = new common.ArrayStream();
outputStream.write = (data) => accum += data.replace('\r', '');
const r = repl.start({
prompt: '',
input: inputStream,
output: outputStream,
terminal: true,
useColors: false
});
r.write(`${command}\n`);
assert.strictEqual(accum.replace(terminalCodeRegex, ''), expected);
r.close();