• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const ArrayStream = require('../common/arraystream');
4const fixtures = require('../common/fixtures');
5const assert = require('assert');
6const repl = require('repl');
7
8common.skipIfDumbTerminal();
9
10const command = `.load ${fixtures.path('repl-load-multiline.js')}`;
11const terminalCode = '\u001b[1G\u001b[0J \u001b[1G';
12const terminalCodeRegex = new RegExp(terminalCode.replace(/\[/g, '\\['), 'g');
13
14const expected = `${command}
15const getLunch = () =>
16  placeOrder('tacos')
17    .then(eat);
18
19const placeOrder = (order) => Promise.resolve(order);
20const eat = (food) => '<nom nom nom>';
21
22undefined
23`;
24
25let accum = '';
26
27const inputStream = new ArrayStream();
28const outputStream = new ArrayStream();
29
30outputStream.write = (data) => accum += data.replace('\r', '');
31
32const r = repl.start({
33  prompt: '',
34  input: inputStream,
35  output: outputStream,
36  terminal: true,
37  useColors: false
38});
39
40r.write(`${command}\n`);
41assert.strictEqual(accum.replace(terminalCodeRegex, ''), expected);
42r.close();
43