11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// The async_hook that we enable would register the process.emitWarning() 81cb0ef41Sopenharmony_ci// call from loading the N-API addon as asynchronous activity because 91cb0ef41Sopenharmony_ci// it contains a process.nextTick() call. Monkey patch it to be a no-op 101cb0ef41Sopenharmony_ci// before we load the addon in order to avoid this. 111cb0ef41Sopenharmony_ciprocess.emitWarning = () => {}; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst { runInCallbackScope } = require(`./build/${common.buildType}/binding`); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst expectedResource = {}; 161cb0ef41Sopenharmony_ciconst expectedResourceType = 'test-resource'; 171cb0ef41Sopenharmony_cilet insideHook = false; 181cb0ef41Sopenharmony_cilet expectedId; 191cb0ef41Sopenharmony_ciasync_hooks.createHook({ 201cb0ef41Sopenharmony_ci init: common.mustCall((id, type, triggerAsyncId, resource) => { 211cb0ef41Sopenharmony_ci if (type !== expectedResourceType) { 221cb0ef41Sopenharmony_ci return; 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci assert.strictEqual(resource, expectedResource); 251cb0ef41Sopenharmony_ci expectedId = id; 261cb0ef41Sopenharmony_ci }), 271cb0ef41Sopenharmony_ci before: common.mustCall((id) => { 281cb0ef41Sopenharmony_ci assert.strictEqual(id, expectedId); 291cb0ef41Sopenharmony_ci insideHook = true; 301cb0ef41Sopenharmony_ci }), 311cb0ef41Sopenharmony_ci after: common.mustCall((id) => { 321cb0ef41Sopenharmony_ci assert.strictEqual(id, expectedId); 331cb0ef41Sopenharmony_ci insideHook = false; 341cb0ef41Sopenharmony_ci }), 351cb0ef41Sopenharmony_ci}).enable(); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_cirunInCallbackScope(expectedResource, expectedResourceType, () => { 381cb0ef41Sopenharmony_ci assert(insideHook); 391cb0ef41Sopenharmony_ci}); 40