• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Regression test for https://github.com/nodejs/node/issues/13237
4
5const common = require('../common');
6const assert = require('assert');
7
8if (!common.isMainThread)
9  common.skip('Worker bootstrapping works differently -> different timing');
10
11const async_hooks = require('async_hooks');
12
13const seenEvents = [];
14
15const p = new Promise((resolve) => resolve(1));
16p.then(() => seenEvents.push('then'));
17
18const hooks = async_hooks.createHook({
19  init: common.mustNotCall(),
20
21  before: common.mustCall((id) => {
22    assert.ok(id > 1);
23    seenEvents.push('before');
24  }),
25
26  after: common.mustCall((id) => {
27    assert.ok(id > 1);
28    seenEvents.push('after');
29    hooks.disable();
30  })
31});
32
33setImmediate(() => {
34  assert.deepStrictEqual(seenEvents, ['before', 'then', 'after']);
35});
36
37hooks.enable(); // After `setImmediate` in order to not catch its init event.
38