forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-repl-uncaught-exception-error.js
More file actions
61 lines (46 loc) · 1.34 KB
/
test-repl-uncaught-exception-error.js
File metadata and controls
61 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
require('../common');
// Adding an `uncaughtException` listener in an REPL instance suppresses errors
// in the whole application.
// Closing the instance won't remove those listeners either.
if (process.argv[2] === 'child') {
const ArrayStream = require('../common/arraystream');
const repl = require('repl');
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(
'setTimeout(() => {\n' +
' process.on("uncaughtException", () => console.log("Foo"));\n' +
'}, 1);\n'
);
// Event listeners added to the global `process` won't be removed after
// closing the REPL instance! Those should be removed again, especially since
// the REPL's `global` option is set to `false`.
r.close();
setTimeout(() => {
// This should definitely not be silenced!
throw new Error('HU');
}, 2);
setTimeout(() => {
console.error('FAILED');
process.exit(1);
}, 10);
return;
}
const cp = require('child_process');
const assert = require('assert');
const res = cp.spawnSync(
process.execPath,
[__filename, 'child'],
{ encoding: 'utf8' }
);
assert.notStrictEqual(res.stderr, 'FAILED\n');