0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-repl-recoverable.js
Evan Lucas 76007079ec Revert "repl,util: insert carriage returns in output"
This reverts commit fce4b981ea.

This was a breaking change and should have been marked semver-major.
The change that was made altered the output of util.format() and
util.inspect(). With how much those are used in the wild, this type of
change deserves more justification.

Fixes: https://github.com/nodejs/node/issues/8138
PR-URL: https://github.com/nodejs/node/pull/8143
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-19 11:48:52 -05:00

41 lines
847 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
let evalCount = 0;
let recovered = false;
let rendered = false;
function customEval(code, context, file, cb) {
evalCount++;
return cb(evalCount === 1 ? new repl.Recoverable() : null, true);
}
const putIn = new common.ArrayStream();
putIn.write = function(msg) {
if (msg === '... ') {
recovered = true;
}
if (msg === 'true\n') {
rendered = true;
}
};
repl.start('', putIn, customEval);
// https://github.com/nodejs/node/issues/2939
// Expose recoverable errors to the consumer.
putIn.emit('data', '1\n');
putIn.emit('data', '2\n');
process.on('exit', function() {
assert(recovered, 'REPL never recovered');
assert(rendered, 'REPL never rendered the result');
assert.strictEqual(evalCount, 2);
});