summaryrefslogtreecommitdiff
path: root/test/node-api/test_make_callback/test-async-hooks.js
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-11-17 12:34:54 -0800
committerGabriel Schulhof <gabriel.schulhof@intel.com>2018-12-04 13:58:17 -0800
commit938e11882b96e19b443477571455088baaa054d8 (patch)
treeeb828a60957a2881995ba9a83f44a32a18fbff16 /test/node-api/test_make_callback/test-async-hooks.js
parent83ee137c4565112177f22f2c735b266b22262220 (diff)
downloadandroid-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.gz
android-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.bz2
android-node-v8-938e11882b96e19b443477571455088baaa054d8.zip
test: partition N-API tests
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>
Diffstat (limited to 'test/node-api/test_make_callback/test-async-hooks.js')
-rw-r--r--test/node-api/test_make_callback/test-async-hooks.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/node-api/test_make_callback/test-async-hooks.js b/test/node-api/test_make_callback/test-async-hooks.js
new file mode 100644
index 0000000000..755a2389c6
--- /dev/null
+++ b/test/node-api/test_make_callback/test-async-hooks.js
@@ -0,0 +1,44 @@
+'use strict';
+
+const common = require('../../common');
+const assert = require('assert');
+const async_hooks = require('async_hooks');
+const binding = require(`./build/${common.buildType}/binding`);
+const makeCallback = binding.makeCallback;
+
+// Check async hooks integration using async context.
+const hook_result = {
+ id: null,
+ init_called: false,
+ before_called: false,
+ after_called: false,
+ destroy_called: false,
+};
+const test_hook = async_hooks.createHook({
+ init: (id, type) => {
+ if (type === 'test') {
+ hook_result.id = id;
+ hook_result.init_called = true;
+ }
+ },
+ before: (id) => {
+ if (id === hook_result.id) hook_result.before_called = true;
+ },
+ after: (id) => {
+ if (id === hook_result.id) hook_result.after_called = true;
+ },
+ destroy: (id) => {
+ if (id === hook_result.id) hook_result.destroy_called = true;
+ },
+});
+
+test_hook.enable();
+makeCallback(process, function() {});
+
+assert.strictEqual(hook_result.init_called, true);
+assert.strictEqual(hook_result.before_called, true);
+assert.strictEqual(hook_result.after_called, true);
+setImmediate(() => {
+ assert.strictEqual(hook_result.destroy_called, true);
+ test_hook.disable();
+});