• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2// Flags: --expose-internals
3
4const common = require('../common');
5const assert = require('assert');
6const async_hooks = require('internal/async_hooks');
7const initHooks = require('./init-hooks');
8
9const expectedId = async_hooks.newAsyncId();
10const expectedTriggerId = async_hooks.newAsyncId();
11const expectedType = 'test_emit_init_type';
12const expectedResource = { key: 'test_emit_init_resource' };
13
14const hooks1 = initHooks({
15  oninit: common.mustCall((id, type, triggerAsyncId, resource) => {
16    assert.strictEqual(id, expectedId);
17    assert.strictEqual(type, expectedType);
18    assert.strictEqual(triggerAsyncId, expectedTriggerId);
19    assert.strictEqual(resource.key, expectedResource.key);
20  })
21});
22
23hooks1.enable();
24
25async_hooks.emitInit(expectedId, expectedType, expectedTriggerId,
26                     expectedResource);
27
28hooks1.disable();
29
30initHooks({
31  oninit: common.mustCall((id, type, triggerAsyncId, resource) => {
32    assert.strictEqual(id, expectedId);
33    assert.strictEqual(type, expectedType);
34    assert.notStrictEqual(triggerAsyncId, expectedTriggerId);
35    assert.strictEqual(resource.key, expectedResource.key);
36  })
37}).enable();
38
39async_hooks.emitInit(expectedId, expectedType, null, expectedResource);
40