-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The internal default repl will from now on trigger `uncaughtException` handlers instead of ignoring them. The regular error output is suppressed in that case.
- Loading branch information
Showing
7 changed files
with
194 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const child = cp.spawn(process.execPath, ['-i']); | ||
let output = ''; | ||
|
||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (data) => { | ||
output += data; | ||
}); | ||
|
||
child.on('exit', common.mustCall(() => { | ||
const results = output.replace(/^> /mg, '').split('\n'); | ||
assert.deepStrictEqual( | ||
results, | ||
[ | ||
'Thrown:', | ||
'ReferenceError: x is not defined', | ||
'short', | ||
'undefined', | ||
'Foobar', | ||
'' | ||
] | ||
); | ||
})); | ||
|
||
child.stdin.write('x\n'); | ||
child.stdin.write( | ||
'process.on("uncaughtException", () => console.log("Foobar"));' + | ||
'console.log("short")\n'); | ||
child.stdin.write('x\n'); | ||
child.stdin.end(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); |