summaryrefslogtreecommitdiff
path: root/test/async-hooks/test-unhandled-rejection-context.js
blob: 8404cf71f0db6ff8205bb7f9b980c664cffd0b03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'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]);
}));