1// Reference: https://github.com/nodejs/node/pull/7624 2'use strict'; 3require('../common'); 4const assert = require('assert'); 5const repl = require('repl'); 6const stream = require('stream'); 7 8const r = initRepl(); 9 10r.input.emit('data', 'function a() { return 42; } (1)\n'); 11r.input.emit('data', 'a\n'); 12r.input.emit('data', '.exit'); 13 14const expected = '1\n[Function: a]\n'; 15const got = r.output.accumulator.join(''); 16assert.strictEqual(got, expected); 17 18function initRepl() { 19 const input = new stream(); 20 input.write = input.pause = input.resume = () => {}; 21 input.readable = true; 22 23 const output = new stream(); 24 output.writable = true; 25 output.accumulator = []; 26 27 output.write = (data) => output.accumulator.push(data); 28 29 return repl.start({ 30 input, 31 output, 32 useColors: false, 33 terminal: false, 34 prompt: '' 35 }); 36} 37