node/test/async-hooks/test-unhandled-rejection-context.js
Antoine du Hamel cf46746b8a
test: add trailing commas in async-hooks tests (#45549)
PR-URL: https://github.com/nodejs/node/pull/45549
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2022-11-21 18:43:47 +01:00

28 lines
665 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const initHooks = require('./init-hooks');
const async_hooks = require('async_hooks');
if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');
const promiseAsyncIds = [];
const hooks = initHooks({
oninit(asyncId, type) {
if (type === 'PROMISE') {
promiseAsyncIds.push(asyncId);
}
},
});
hooks.enable();
Promise.reject();
process.on('unhandledRejection', common.mustCall(() => {
assert.strictEqual(promiseAsyncIds.length, 1);
assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[0]);
}));