mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 17:57:53 +00:00

Partition test/addons-napi into test/js-native-api and test/node-api to isolate the Node.js-agnostic portion of the N-API tests from the Node.js-specific portion. PR-URL: https://github.com/nodejs/node/pull/24557 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
30 lines
844 B
JavaScript
30 lines
844 B
JavaScript
'use strict';
|
|
|
|
const common = require('../../common');
|
|
const assert = require('assert');
|
|
const async_hooks = require('async_hooks');
|
|
|
|
// The async_hook that we enable would register the process.emitWarning()
|
|
// call from loading the N-API addon as asynchronous activity because
|
|
// it contains a process.nextTick() call. Monkey patch it to be a no-op
|
|
// before we load the addon in order to avoid this.
|
|
process.emitWarning = () => {};
|
|
|
|
const { runInCallbackScope } = require(`./build/${common.buildType}/binding`);
|
|
|
|
let insideHook = false;
|
|
async_hooks.createHook({
|
|
before: common.mustCall((id) => {
|
|
assert.strictEqual(id, 1000);
|
|
insideHook = true;
|
|
}),
|
|
after: common.mustCall((id) => {
|
|
assert.strictEqual(id, 1000);
|
|
insideHook = false;
|
|
})
|
|
}).enable();
|
|
|
|
runInCallbackScope({}, 1000, 1000, () => {
|
|
assert(insideHook);
|
|
});
|