()
| 7 | const { NodeInstance } = require('../common/inspector-helper.js'); |
| 8 | |
| 9 | async function runTests() { |
| 10 | const child = new NodeInstance(['-e', `(${main.toString()})()`], '', ''); |
| 11 | const session = await child.connectInspectorSession(); |
| 12 | await session.send({ method: 'Runtime.enable' }); |
| 13 | // Check that there is only one console message received. |
| 14 | await session.waitForConsoleOutput('log', 'before wait for debugger'); |
| 15 | assert.ok(!session.unprocessedNotifications() |
| 16 | .some((n) => n.method === 'Runtime.consoleAPICalled')); |
| 17 | // Check that inspector.url() is available between inspector.open() and |
| 18 | // inspector.waitForDebugger() |
| 19 | const { result: { value } } = await session.send({ |
| 20 | method: 'Runtime.evaluate', |
| 21 | params: { |
| 22 | expression: 'process._ws', |
| 23 | includeCommandLineAPI: true |
| 24 | } |
| 25 | }); |
| 26 | assert.ok(value.startsWith('ws://')); |
| 27 | await session.send({ method: 'NodeRuntime.enable' }); |
| 28 | child.write('first'); |
| 29 | await session.waitForNotification('NodeRuntime.waitingForDebugger'); |
| 30 | await session.send({ method: 'Runtime.runIfWaitingForDebugger' }); |
| 31 | await session.send({ method: 'NodeRuntime.disable' }); |
| 32 | // Check that messages after first and before second waitForDebugger are |
| 33 | // received |
| 34 | await session.waitForConsoleOutput('log', 'after wait for debugger'); |
| 35 | await session.waitForConsoleOutput('log', 'before second wait for debugger'); |
| 36 | assert.ok(!session.unprocessedNotifications() |
| 37 | .some((n) => n.method === 'Runtime.consoleAPICalled')); |
| 38 | const secondSession = await child.connectInspectorSession(); |
| 39 | // Check that inspector.waitForDebugger can be resumed from another session |
| 40 | await session.send({ method: 'NodeRuntime.enable' }); |
| 41 | child.write('second'); |
| 42 | await session.waitForNotification('NodeRuntime.waitingForDebugger'); |
| 43 | await session.send({ method: 'Runtime.runIfWaitingForDebugger' }); |
| 44 | await session.send({ method: 'NodeRuntime.disable' }); |
| 45 | await session.waitForConsoleOutput('log', 'after second wait for debugger'); |
| 46 | assert.ok(!session.unprocessedNotifications() |
| 47 | .some((n) => n.method === 'Runtime.consoleAPICalled')); |
| 48 | secondSession.disconnect(); |
| 49 | session.disconnect(); |
| 50 | |
| 51 | function main(prefix) { |
| 52 | const inspector = require('inspector'); |
| 53 | inspector.open(0, undefined, false); |
| 54 | process._ws = inspector.url(); |
| 55 | console.log('before wait for debugger'); |
| 56 | process.stdin.once('data', (data) => { |
| 57 | if (data.toString() === 'first') { |
| 58 | inspector.waitForDebugger(); |
| 59 | console.log('after wait for debugger'); |
| 60 | console.log('before second wait for debugger'); |
| 61 | process.stdin.once('data', (data) => { |
| 62 | if (data.toString() === 'second') { |
| 63 | inspector.waitForDebugger(); |
| 64 | console.log('after second wait for debugger'); |
| 65 | process.exit(); |
| 66 | } |
no test coverage detected
searching dependent graphs…