• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals --no-warnings
2'use strict';
3
4// See also test/sequential/test-async-wrap-getasyncid.js
5
6const common = require('../common');
7const assert = require('assert');
8const { internalBinding } = require('internal/test/binding');
9const { TTYWRAP } = internalBinding('async_wrap').Providers;
10const tty_wrap = internalBinding('tty_wrap');
11const providers = { TTYWRAP };
12
13// Make sure that the TTYWRAP Provider is tested.
14{
15  const hooks = require('async_hooks').createHook({
16    init(id, type) {
17      if (type === 'NONE')
18        throw new Error('received a provider type of NONE');
19      delete providers[type];
20    },
21  }).enable();
22  process.on('beforeExit', common.mustCall(() => {
23    process.removeAllListeners('uncaughtException');
24    hooks.disable();
25
26    const objKeys = Object.keys(providers);
27    if (objKeys.length > 0)
28      process._rawDebug(objKeys);
29    assert.strictEqual(objKeys.length, 0);
30  }));
31}
32
33function testInitialized(req, ctor_name) {
34  assert.strictEqual(typeof req.getAsyncId, 'function');
35  assert(Number.isSafeInteger(req.getAsyncId()));
36  assert(req.getAsyncId() > 0);
37  assert.strictEqual(req.constructor.name, ctor_name);
38}
39
40{
41  const ttyFd = common.getTTYfd();
42
43  const handle = new tty_wrap.TTY(ttyFd, false);
44  testInitialized(handle, 'TTY');
45}
46