|
| 1 | +// Flags: --expose-internals |
| 2 | + |
| 3 | +'use strict'; |
| 4 | +constcommon=require('../common'); |
| 5 | + |
| 6 | +common.skipIfInspectorDisabled(); |
| 7 | + |
| 8 | +constassert=require('assert'); |
| 9 | +const{ NodeInstance }=require('../common/inspector-helper.js'); |
| 10 | + |
| 11 | +asyncfunctionrunTests(){ |
| 12 | +constchild=newNodeInstance(['-e',`(${main.toString()})()`],'',''); |
| 13 | +constsession=awaitchild.connectInspectorSession(); |
| 14 | +awaitsession.send({method: 'Runtime.enable'}); |
| 15 | +// Check that there is only one console message received. |
| 16 | +awaitsession.waitForConsoleOutput('log','before wait for debugger'); |
| 17 | +assert.ok(!session.unprocessedNotifications() |
| 18 | +.some((n)=>n.method==='Runtime.consoleAPICalled')); |
| 19 | +// Check that inspector.url() is available between inspector.open() and |
| 20 | +// inspector.waitForDebugger() |
| 21 | +const{result: { value }}=awaitsession.send({ |
| 22 | +method: 'Runtime.evaluate', |
| 23 | +params: { |
| 24 | +expression: 'process._ws', |
| 25 | +includeCommandLineAPI: true |
| 26 | +} |
| 27 | +}); |
| 28 | +assert.ok(value.startsWith('ws://')); |
| 29 | +session.send({method: 'Runtime.runIfWaitingForDebugger'}); |
| 30 | +// Check that messages after first and before second waitForDebugger are |
| 31 | +// received |
| 32 | +awaitsession.waitForConsoleOutput('log','after wait for debugger'); |
| 33 | +awaitsession.waitForConsoleOutput('log','before second wait for debugger'); |
| 34 | +assert.ok(!session.unprocessedNotifications() |
| 35 | +.some((n)=>n.method==='Runtime.consoleAPICalled')); |
| 36 | +constsecondSession=awaitchild.connectInspectorSession(); |
| 37 | +// Check that inspector.waitForDebugger can be resumed from another session |
| 38 | +secondSession.send({method: 'Runtime.runIfWaitingForDebugger'}); |
| 39 | +awaitsession.waitForConsoleOutput('log','after second wait for debugger'); |
| 40 | +assert.ok(!session.unprocessedNotifications() |
| 41 | +.some((n)=>n.method==='Runtime.consoleAPICalled')); |
| 42 | +secondSession.disconnect(); |
| 43 | +session.disconnect(); |
| 44 | + |
| 45 | +functionmain(prefix){ |
| 46 | +constinspector=require('inspector'); |
| 47 | +inspector.open(0,undefined,false); |
| 48 | +process._ws=inspector.url(); |
| 49 | +console.log('before wait for debugger'); |
| 50 | +inspector.waitForDebugger(); |
| 51 | +console.log('after wait for debugger'); |
| 52 | +console.log('before second wait for debugger'); |
| 53 | +inspector.waitForDebugger(); |
| 54 | +console.log('after second wait for debugger'); |
| 55 | +} |
| 56 | + |
| 57 | +// Check that inspector.waitForDebugger throws if there is no active |
| 58 | +// inspector |
| 59 | +constre=/^Error\[ERR_INSPECTOR_NOT_ACTIVE\]:Inspectorisnotactive$/; |
| 60 | +assert.throws(()=>require('inspector').waitForDebugger(),re); |
| 61 | +} |
| 62 | + |
| 63 | +runTests(); |
0 commit comments