@@ -5,21 +5,32 @@ common.skipIfInspectorDisabled();
5
5
common . skipIf32Bits ( ) ;
6
6
7
7
const assert = require ( 'assert' ) ;
8
+ const { inspect } = require ( 'util' ) ;
8
9
const { internalBinding } = require ( 'internal/test/binding' ) ;
9
- const { async_hook_fields, constants } = internalBinding ( 'async_wrap' ) ;
10
+ const { async_hook_fields, constants, getPromiseHooks } = internalBinding ( 'async_wrap' ) ;
10
11
const { kTotals } = constants ;
11
- const inspector = require ( 'inspector' ) ;
12
+ const inspector = require ( 'inspector/promises ' ) ;
12
13
13
14
const setDepth = 'Debugger.setAsyncCallStackDepth' ;
14
-
15
+ const emptyPromiseHooks = [ undefined , undefined , undefined , undefined ] ;
15
16
function verifyAsyncHookDisabled ( message ) {
16
17
assert . strictEqual ( async_hook_fields [ kTotals ] , 0 ,
17
18
`${ async_hook_fields [ kTotals ] } !== 0: ${ message } ` ) ;
19
+ const promiseHooks = getPromiseHooks ( ) ;
20
+ assert . deepStrictEqual (
21
+ promiseHooks , emptyPromiseHooks ,
22
+ `${ message } : promise hooks ${ inspect ( promiseHooks ) } `
23
+ ) ;
18
24
}
19
25
20
26
function verifyAsyncHookEnabled ( message ) {
21
27
assert . strictEqual ( async_hook_fields [ kTotals ] , 4 ,
22
28
`${ async_hook_fields [ kTotals ] } !== 4: ${ message } ` ) ;
29
+ const promiseHooks = getPromiseHooks ( ) ;
30
+ assert . notDeepStrictEqual (
31
+ promiseHooks , emptyPromiseHooks ,
32
+ `${ message } : promise hooks ${ inspect ( promiseHooks ) } `
33
+ ) ;
23
34
}
24
35
25
36
// By default inspector async hooks should not have been installed.
@@ -31,53 +42,38 @@ verifyAsyncHookDisabled('creating a session should not enable async hooks');
31
42
session . connect ( ) ;
32
43
verifyAsyncHookDisabled ( 'connecting a session should not enable async hooks' ) ;
33
44
34
- session . post ( 'Debugger.enable' , ( ) => {
45
+ ( async ( ) => {
46
+ await session . post ( 'Debugger.enable' ) ;
35
47
verifyAsyncHookDisabled ( 'enabling debugger should not enable async hooks' ) ;
36
-
37
- session . post ( setDepth , { invalid : 'message' } , ( ) => {
38
- verifyAsyncHookDisabled ( 'invalid message should not enable async hooks' ) ;
39
-
40
- session . post ( setDepth , { maxDepth : 'five' } , ( ) => {
41
- verifyAsyncHookDisabled ( 'invalid maxDepth (string) should not enable ' +
42
- 'async hooks' ) ;
43
-
44
- session . post ( setDepth , { maxDepth : NaN } , ( ) => {
45
- verifyAsyncHookDisabled ( 'invalid maxDepth (NaN) should not enable ' +
46
- 'async hooks' ) ;
47
-
48
- session . post ( setDepth , { maxDepth : 10 } , ( ) => {
49
- verifyAsyncHookEnabled ( 'valid message should enable async hooks' ) ;
50
-
51
- session . post ( setDepth , { maxDepth : 0 } , ( ) => {
52
- verifyAsyncHookDisabled ( 'Setting maxDepth to 0 should disable ' +
53
- 'async hooks' ) ;
54
-
55
- runTestSet2 ( session ) ;
56
- } ) ;
57
- } ) ;
58
- } ) ;
59
- } ) ;
60
- } ) ;
61
- } ) ;
62
-
63
- function runTestSet2 ( session ) {
64
- session . post ( setDepth , { maxDepth : 32 } , ( ) => {
65
- verifyAsyncHookEnabled ( 'valid message should enable async hooks' ) ;
66
-
67
- session . post ( 'Debugger.disable' , ( ) => {
68
- verifyAsyncHookDisabled ( 'Debugger.disable should disable async hooks' ) ;
69
-
70
- session . post ( 'Debugger.enable' , ( ) => {
71
- verifyAsyncHookDisabled ( 'Enabling debugger should not enable hooks' ) ;
72
-
73
- session . post ( setDepth , { maxDepth : 64 } , ( ) => {
74
- verifyAsyncHookEnabled ( 'valid message should enable async hooks' ) ;
75
-
76
- session . disconnect ( ) ;
77
- verifyAsyncHookDisabled ( 'Disconnecting session should disable ' +
78
- 'async hooks' ) ;
79
- } ) ;
80
- } ) ;
81
- } ) ;
82
- } ) ;
83
- }
48
+ await assert . rejects ( session . post ( setDepth , { invalid : 'message' } ) , { code : 'ERR_INSPECTOR_COMMAND' } ) ;
49
+ verifyAsyncHookDisabled ( 'invalid message should not enable async hooks' ) ;
50
+ await assert . rejects ( session . post ( setDepth , { maxDepth : 'five' } ) , { code : 'ERR_INSPECTOR_COMMAND' } ) ;
51
+ verifyAsyncHookDisabled ( 'invalid maxDepth (string) should not enable ' +
52
+ 'async hooks' ) ;
53
+ await assert . rejects ( session . post ( setDepth , { maxDepth : NaN } ) , { code : 'ERR_INSPECTOR_COMMAND' } ) ;
54
+ verifyAsyncHookDisabled ( 'invalid maxDepth (NaN) should not enable ' +
55
+ 'async hooks' ) ;
56
+ await session . post ( setDepth , { maxDepth : 10 } ) ;
57
+ verifyAsyncHookEnabled ( 'valid message should enable async hooks' ) ;
58
+
59
+ await session . post ( setDepth , { maxDepth : 0 } ) ;
60
+ verifyAsyncHookDisabled ( 'Setting maxDepth to 0 should disable ' +
61
+ 'async hooks' ) ;
62
+
63
+ await session . post ( setDepth , { maxDepth : 32 } ) ;
64
+ verifyAsyncHookEnabled ( 'valid message should enable async hooks' ) ;
65
+
66
+ await session . post ( 'Debugger.disable' ) ;
67
+ verifyAsyncHookDisabled ( 'Debugger.disable should disable async hooks' ) ;
68
+
69
+ await session . post ( 'Debugger.enable' ) ;
70
+ verifyAsyncHookDisabled ( 'Enabling debugger should not enable hooks' ) ;
71
+
72
+ await session . post ( setDepth , { maxDepth : 64 } ) ;
73
+ verifyAsyncHookEnabled ( 'valid message should enable async hooks' ) ;
74
+
75
+ await session . disconnect ( ) ;
76
+
77
+ verifyAsyncHookDisabled ( 'Disconnecting session should disable ' +
78
+ 'async hooks' ) ;
79
+ } ) ( ) . then ( common . mustCall ( ) ) ;
0 commit comments