|
| 1 | +// Flags: --expose-internals |
| 2 | + |
| 3 | +'use strict'; |
| 4 | +const common = require('../common'); |
| 5 | + |
| 6 | +common.skipIfInspectorDisabled(); |
| 7 | + |
| 8 | +const assert = require('assert'); |
| 9 | +const { NodeInstance } = require('../common/inspector-helper.js'); |
| 10 | + |
| 11 | +async function runTests() { |
| 12 | + const child = new NodeInstance(['-e', `(${main.toString()})()`], '', ''); |
| 13 | + const session = await child.connectInspectorSession(); |
| 14 | + await session.send({ method: 'Runtime.enable' }); |
| 15 | + // Check that there is only one console message received. |
| 16 | + await session.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 } } = await session.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 | + await session.waitForConsoleOutput('log', 'after wait for debugger'); |
| 33 | + await session.waitForConsoleOutput('log', 'before second wait for debugger'); |
| 34 | + assert.ok(!session.unprocessedNotifications() |
| 35 | + .some((n) => n.method === 'Runtime.consoleAPICalled')); |
| 36 | + const secondSession = await child.connectInspectorSession(); |
| 37 | + // Check that inspector.waitForDebugger can be resumed from another session |
| 38 | + secondSession.send({ method: 'Runtime.runIfWaitingForDebugger' }); |
| 39 | + await session.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 | + function main(prefix) { |
| 46 | + const inspector = 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 | + const re = /^Error \[ERR_INSPECTOR_NOT_ACTIVE\]: Inspector is not active$/; |
| 60 | + assert.throws(() => require('inspector').waitForDebugger(), re); |
| 61 | +} |
| 62 | + |
| 63 | +runTests(); |
0 commit comments