nodejs/test/parallel/test-repl-uncaught-exception-async.js
Dario Piotrowicz 39ab68b2c1
readline: add stricter validation for functions called after closed
PR-URL: https://github.com/nodejs/node/pull/58283
Fixes: https://github.com/nodejs/node/issues/57678
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-05-18 19:46:38 +00:00

45 lines
1.1 KiB
JavaScript

'use strict';
// This verifies that adding an `uncaughtException` listener in an REPL instance
// does not suppress errors in the whole application. Adding such listener
// should throw.
require('../common');
const ArrayStream = require('../common/arraystream');
const repl = require('repl');
const assert = require('assert');
let accum = '';
const output = new ArrayStream();
output.write = (data) => accum += data.replace('\r', '');
const r = repl.start({
prompt: '',
input: new ArrayStream(),
output,
terminal: false,
useColors: false,
global: false
});
r.write(
'process.nextTick(() => {\n' +
' process.on("uncaughtException", () => console.log("Foo"));\n' +
' throw new TypeError("foobar");\n' +
'});\n'
);
r.write(
'setTimeout(() => {\n' +
' throw new RangeError("abc");\n' +
'}, 1);console.log()\n'
);
setTimeout(() => {
r.close();
const len = process.listenerCount('uncaughtException');
process.removeAllListeners('uncaughtException');
assert.strictEqual(len, 0);
assert.match(accum, /ERR_INVALID_REPL_INPUT.*(?!Type)RangeError: abc/s);
}, 2);