GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — n-api: separate out async_hooks test · nodejs/node@9949d55

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/addons-napi/test_make_callback
    • test-async-hooks.js
    • test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/addons-napi/test_make_callback/test-async-hooks.js‎

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const common = require('../../common');
4+
const assert = require('assert');
5+
const async_hooks = require('async_hooks');
6+
const binding = require(`./build/${common.buildType}/binding`);
7+
const makeCallback = binding.makeCallback;
8+
9+
// Check async hooks integration using async context.
10+
const hook_result = {
11+
id: null,
12+
init_called: false,
13+
before_called: false,
14+
after_called: false,
15+
destroy_called: false,
16+
};
17+
const test_hook = async_hooks.createHook({
18+
init: (id, type) => {
19+
if (type === 'test') {
20+
hook_result.id = id;
21+
hook_result.init_called = true;
22+
}
23+
},
24+
before: (id) => {
25+
if (id === hook_result.id) hook_result.before_called = true;
26+
},
27+
after: (id) => {
28+
if (id === hook_result.id) hook_result.after_called = true;
29+
},
30+
destroy: (id) => {
31+
if (id === hook_result.id) hook_result.destroy_called = true;
32+
},
33+
});
34+
35+
test_hook.enable();
36+
makeCallback(process, function() {});
37+
38+
assert.strictEqual(hook_result.init_called, true);
39+
assert.strictEqual(hook_result.before_called, true);
40+
assert.strictEqual(hook_result.after_called, true);
41+
setImmediate(() => {
42+
assert.strictEqual(hook_result.destroy_called, true);
43+
test_hook.disable();
44+
});
Collapse file

‎test/addons-napi/test_make_callback/test.js‎

Copy file name to clipboardExpand all lines: test/addons-napi/test_make_callback/test.js
-38Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const common = require('../../common');
44
const assert = require('assert');
5-
const async_hooks = require('async_hooks');
65
const vm = require('vm');
76
const binding = require(`./build/${common.buildType}/binding`);
87
const makeCallback = binding.makeCallback;
@@ -81,40 +80,3 @@ function endpoint($Object) {
8180
}
8281

8382
assert.strictEqual(Object, makeCallback(process, forward, endpoint));
84-
85-
// Check async hooks integration using async context.
86-
const hook_result = {
87-
id: null,
88-
init_called: false,
89-
before_called: false,
90-
after_called: false,
91-
destroy_called: false,
92-
};
93-
const test_hook = async_hooks.createHook({
94-
init: (id, type) => {
95-
if (type === 'test') {
96-
hook_result.id = id;
97-
hook_result.init_called = true;
98-
}
99-
},
100-
before: (id) => {
101-
if (id === hook_result.id) hook_result.before_called = true;
102-
},
103-
after: (id) => {
104-
if (id === hook_result.id) hook_result.after_called = true;
105-
},
106-
destroy: (id) => {
107-
if (id === hook_result.id) hook_result.destroy_called = true;
108-
},
109-
});
110-
111-
test_hook.enable();
112-
makeCallback(process, function() {});
113-
114-
assert.strictEqual(hook_result.init_called, true);
115-
assert.strictEqual(hook_result.before_called, true);
116-
assert.strictEqual(hook_result.after_called, true);
117-
setImmediate(() => {
118-
assert.strictEqual(hook_result.destroy_called, true);
119-
test_hook.disable();
120-
});

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.