Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test to verify that throwing in monitoring listener results in
exit code 7
  • Loading branch information
Flarna committed Jan 10, 2020
commit c3b5f2d9ade48fce728dd7934a535df71cbe8048
11 changes: 11 additions & 0 deletions test/fixtures/uncaught-exceptions/uncaught-monitor2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

// Keep the event loop alive.
setTimeout(() => {}, 1e6);

process.on('uncaughtExceptionMonitor', (err) => {
console.log(`Monitored: ${err.message}, will throw now`);
missingFunction();
});

throw new Error('Shall exit');
Comment thread
Flarna marked this conversation as resolved.
22 changes: 21 additions & 1 deletion test/parallel/test-process-uncaught-exception-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fixtures = require('../common/fixtures');

{
// Verify exit behavior is unchanged
const fixture = fixtures.path('uncaught-exceptions', 'uncaught-monitor.js');
const fixture = fixtures.path('uncaught-exceptions', 'uncaught-monitor1.js');
execFile(
process.execPath,
[fixture],
Expand All @@ -22,6 +22,26 @@ const fixtures = require('../common/fixtures');
);
}

{
// Verify exit behavior is unchanged
const fixture = fixtures.path('uncaught-exceptions', 'uncaught-monitor2.js');
execFile(
process.execPath,
[fixture],
common.mustCall((err, stdout, stderr) => {
assert.strictEqual(err.code, 7);
assert.strictEqual(Object.getPrototypeOf(err).name, 'Error');
assert.strictEqual(stdout, 'Monitored: Shall exit, will throw now\n');
const errLines = stderr.trim().split(/[\r\n]+/);
const errLine = errLines.find((l) => /^ReferenceError/.exec(l));
assert.strictEqual(
errLine,
'ReferenceError: missingFunction is not defined'
);
})
);
}

const theErr = new Error('MyError');

process.on(
Expand Down