Files
node/test/parallel/test-async-wrap-promise-after-enabled.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

40 lines
963 B
JavaScript

'use strict';
// Regression test for https://github.com/nodejs/node/issues/13237
const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
common.skip('Worker bootstrapping works differently -> different timing');
}
const async_hooks = require('async_hooks');
const seenEvents = [];
const p = new Promise((resolve) => resolve(1));
p.then(() => seenEvents.push('then')).then(common.mustCall());
const hooks = async_hooks.createHook({
init: common.mustNotCall(),
before: common.mustCall((id) => {
assert.ok(id > 1);
seenEvents.push('before');
}),
after: common.mustCall((id) => {
assert.ok(id > 1);
seenEvents.push('after');
hooks.disable();
})
});
setImmediate(common.mustCall(() => {
assert.deepStrictEqual(seenEvents, ['before', 'then', 'after']);
}));
hooks.enable(); // After `setImmediate` in order to not catch its init event.