• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const initHooks = require('./init-hooks');
6const { checkInvocations } = require('./hook-checks');
7
8if (!common.isMainThread)
9  common.skip('Worker bootstrapping works differently -> different async IDs');
10
11const p = new Promise(common.mustCall(function executor(resolve) {
12  resolve(5);
13}));
14
15p.then(function afterResolution(val) {
16  assert.strictEqual(val, 5);
17  return val;
18});
19
20// Init hooks after chained promise is created
21const hooks = initHooks();
22hooks._allowNoInit = true;
23hooks.enable();
24
25
26process.on('exit', function onexit() {
27  hooks.disable();
28  hooks.sanityCheck('PROMISE');
29
30  // Because the init event was never emitted the hooks listener doesn't
31  // know what the type was. Thus check for Unknown rather than PROMISE.
32  const as = hooks.activitiesOfTypes('PROMISE');
33  const unknown = hooks.activitiesOfTypes('Unknown');
34  assert.strictEqual(as.length, 0);
35  assert.strictEqual(unknown.length, 1);
36
37  const a0 = unknown[0];
38  assert.strictEqual(a0.type, 'Unknown');
39  assert.strictEqual(typeof a0.uid, 'number');
40  checkInvocations(a0, { before: 1, after: 1 }, 'when process exits');
41});
42