Files
node/test/parallel/test-promise-hook-exceptions.js
Antoine du Hamel e50cbc1abd test: enforce better never-settling-promise detection
Tests should be explicit regarding whether a promise is expected to
settle, and the test should fail when the behavior does not meet
expectations.

PR-URL: https://github.com/nodejs/node/pull/60976
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
2025-12-10 23:55:36 +00:00

32 lines
681 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { promiseHooks } = require('v8');
const expected = [];
function testHook(name) {
const hook = promiseHooks[name];
const error = new Error(`${name} error`);
const stop = hook(common.mustCall(() => {
stop();
throw error;
}));
expected.push(error);
}
process.on('uncaughtException', common.mustCall((received) => {
assert.strictEqual(received, expected.shift());
}, 4));
testHook('onInit');
testHook('onSettled');
testHook('onBefore');
testHook('onAfter');
const stop = promiseHooks.onInit(common.mustCall(3));
Promise.resolve().then(stop).then(common.mustCall());