node/test/parallel/test-worker-non-fatal-uncaught-exception.js
Ruben Bridgewater aea9a0f77d worker: fix process._fatalException return type
This makes sure `process._fatalException()` returns a boolean when
run inside of a worker.

PR-URL: https://github.com/nodejs/node/pull/29706
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
2019-09-27 16:26:42 -07:00

26 lines
676 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
// Check that `process._fatalException()` returns a boolean when run inside a
// worker.
// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
const w = new Worker(__filename);
w.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
return;
}
process.once('uncaughtException', () => {
process.nextTick(() => {
assert.strictEqual(res, true);
});
});
const res = process._fatalException(new Error());