node/test/pseudo-tty/test-async-wrap-getasyncid-tty.js
Daniel Bevenius da8641f3b4 src: move process.binding('async_wrap') internal
This commit makes the async_wrap builtin an internal builtin, and
changes usage of the builtin from using process.binding('async_wrap')
to use internalBinding instead.

Refs: https://github.com/nodejs/node/issues/22160

PR-URL: https://github.com/nodejs/node/pull/22469
Refs: https://github.com/nodejs/node/issues/22160
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-08-27 05:42:55 +02:00

46 lines
1.3 KiB
JavaScript

// Flags: --expose-internals --no-warnings
'use strict';
// see also test/sequential/test-async-wrap-getasyncid.js
const common = require('../common');
const assert = require('assert');
const tty_wrap = process.binding('tty_wrap');
const { internalBinding } = require('internal/test/binding');
const { TTYWRAP } = internalBinding('async_wrap').Providers;
const providers = { TTYWRAP };
// Make sure that the TTYWRAP Provider is tested.
{
const hooks = require('async_hooks').createHook({
init(id, type) {
if (type === 'NONE')
throw new Error('received a provider type of NONE');
delete providers[type];
},
}).enable();
process.on('beforeExit', common.mustCall(() => {
process.removeAllListeners('uncaughtException');
hooks.disable();
const objKeys = Object.keys(providers);
if (objKeys.length > 0)
process._rawDebug(objKeys);
assert.strictEqual(objKeys.length, 0);
}));
}
function testInitialized(req, ctor_name) {
assert.strictEqual(typeof req.getAsyncId, 'function');
assert(Number.isSafeInteger(req.getAsyncId()));
assert(req.getAsyncId() > 0);
assert.strictEqual(req.constructor.name, ctor_name);
}
{
const ttyFd = common.getTTYfd();
const handle = new tty_wrap.TTY(ttyFd, false);
testInitialized(handle, 'TTY');
}