forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-repl-uncaught-exception.js
More file actions
60 lines (52 loc) · 1.36 KB
/
test-repl-uncaught-exception.js
File metadata and controls
60 lines (52 loc) · 1.36 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
'use strict';
require('../common');
const ArrayStream = require('../common/arraystream');
const assert = require('assert');
const repl = require('repl');
let count = 0;
function run({ command, expected }) {
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
});
r.write(`${command}\n`);
if (typeof expected === 'string') {
assert.strictEqual(accum, expected);
} else {
assert(expected.test(accum), accum);
}
r.close();
count++;
}
const tests = [
{
command: 'x',
expected: 'Thrown:\n' +
'ReferenceError: x is not defined\n'
},
{
command: 'process.on("uncaughtException", () => console.log("Foobar"));\n',
expected: /^Thrown:\nTypeError \[ERR_INVALID_REPL_INPUT]: Unhandled exception/
},
{
command: 'x;\n',
expected: 'Thrown:\n' +
'ReferenceError: x is not defined\n'
},
{
command: 'process.on("uncaughtException", () => console.log("Foobar"));' +
'console.log("Baz");\n',
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
expected: /^Baz(.|\n)*ERR_INVALID_REPL_INPUT/
}
];
process.on('exit', () => {
assert.strictEqual(count, tests.length);
});
tests.forEach(run);