1'use strict';
2
3const common = require('../common');
4
5const assert = require('assert');
6const initHooks = require('./init-hooks');
7const async_hooks = require('async_hooks');
8
9if (!common.isMainThread)
10  common.skip('Worker bootstrapping works differently -> different async IDs');
11
12const promiseAsyncIds = [];
13const hooks = initHooks({
14  oninit(asyncId, type) {
15    if (type === 'PROMISE') {
16      promiseAsyncIds.push(asyncId);
17    }
18  },
19});
20
21hooks.enable();
22Promise.reject();
23
24process.on('unhandledRejection', common.mustCall(() => {
25  assert.strictEqual(promiseAsyncIds.length, 1);
26  assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[0]);
27}));
28