1'use strict'; 2 3require('../common'); 4const ArrayStream = require('../common/arraystream'); 5const assert = require('assert'); 6const repl = require('repl'); 7 8let evalCount = 0; 9let recovered = false; 10let rendered = false; 11 12function customEval(code, context, file, cb) { 13 evalCount++; 14 15 return cb(evalCount === 1 ? new repl.Recoverable() : null, true); 16} 17 18const putIn = new ArrayStream(); 19 20putIn.write = function(msg) { 21 if (msg === '... ') { 22 recovered = true; 23 } 24 25 if (msg === 'true\n') { 26 rendered = true; 27 } 28}; 29 30repl.start('', putIn, customEval); 31 32// https://github.com/nodejs/node/issues/2939 33// Expose recoverable errors to the consumer. 34putIn.emit('data', '1\n'); 35putIn.emit('data', '2\n'); 36 37process.on('exit', function() { 38 assert(recovered, 'REPL never recovered'); 39 assert(rendered, 'REPL never rendered the result'); 40 assert.strictEqual(evalCount, 2); 41}); 42