@@ -5,21 +5,32 @@ common.skipIfInspectorDisabled();
55common . skipIf32Bits ( ) ;
66
77const assert = require ( 'assert' ) ;
8+ const { inspect } = require ( 'util' ) ;
89const { internalBinding } = require ( 'internal/test/binding' ) ;
9- const { async_hook_fields, constants } = internalBinding ( 'async_wrap' ) ;
10+ const { async_hook_fields, constants, getPromiseHooks } = internalBinding ( 'async_wrap' ) ;
1011const { kTotals } = constants ;
11- const inspector = require ( 'inspector' ) ;
12+ const inspector = require ( 'inspector/promises ' ) ;
1213
1314const setDepth = 'Debugger.setAsyncCallStackDepth' ;
14-
15+ const emptyPromiseHooks = [ undefined , undefined , undefined , undefined ] ;
1516function verifyAsyncHookDisabled ( message ) {
1617 assert . strictEqual ( async_hook_fields [ kTotals ] , 0 ,
1718 `${ async_hook_fields [ kTotals ] } !== 0: ${ message } ` ) ;
19+ const promiseHooks = getPromiseHooks ( ) ;
20+ assert . deepStrictEqual (
21+ promiseHooks , emptyPromiseHooks ,
22+ `${ message } : promise hooks ${ inspect ( promiseHooks ) } `
23+ ) ;
1824}
1925
2026function verifyAsyncHookEnabled ( message ) {
2127 assert . strictEqual ( async_hook_fields [ kTotals ] , 4 ,
2228 `${ async_hook_fields [ kTotals ] } !== 4: ${ message } ` ) ;
29+ const promiseHooks = getPromiseHooks ( ) ;
30+ assert . notDeepStrictEqual (
31+ promiseHooks , emptyPromiseHooks ,
32+ `${ message } : promise hooks ${ inspect ( promiseHooks ) } `
33+ ) ;
2334}
2435
2536// By default inspector async hooks should not have been installed.
@@ -31,53 +42,38 @@ verifyAsyncHookDisabled('creating a session should not enable async hooks');
3142session . connect ( ) ;
3243verifyAsyncHookDisabled ( 'connecting a session should not enable async hooks' ) ;
3344
34- session . post ( 'Debugger.enable' , ( ) => {
45+ ( async ( ) => {
46+ await session . post ( 'Debugger.enable' ) ;
3547 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