node/test/parallel/test-repl-uncaught-exception-evalcallback.js
Anna Henningsen 9f5977a74d
repl: display prompt once after error callback
Do not call `.displayPrompt()` twice after the `eval` callback
resulted in an error.

(This does not affect the default eval because it doesn’t use
the callback if an error occurs.)

PR-URL: https://github.com/nodejs/node/pull/38314
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2021-04-22 16:39:41 +02:00

24 lines
625 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
const { PassThrough } = require('stream');
const input = new PassThrough();
const output = new PassThrough();
const r = repl.start({
input, output,
eval: common.mustCall((code, context, filename, cb) => {
r.setPrompt('prompt! ');
cb(new Error('err'));
})
});
input.end('foo\n');
// The output includes exactly one post-error prompt.
const out = output.read().toString();
assert.match(out, /prompt!/);
assert.doesNotMatch(out, /prompt![\S\s]*prompt!/);
output.on('data', common.mustNotCall());