|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +common.skipIfInspectorDisabled(); |
| 5 | + |
| 6 | +const assert = require('node:assert/strict'); |
| 7 | + |
| 8 | +const fixtures = require('../common/fixtures'); |
| 9 | +const { NodeInstance } = require('../common/inspector-helper'); |
| 10 | + |
| 11 | +async function testBreakpointBeforeScriptExecution(session) { |
| 12 | + console.log( |
| 13 | + '[test]', |
| 14 | + 'Verifying debugger stops on start of each script ' + |
| 15 | + '(Debugger.setInstrumentationBreakpoint with beforeScriptExecution)', |
| 16 | + ); |
| 17 | + |
| 18 | + const commands = [ |
| 19 | + { method: 'Runtime.enable' }, |
| 20 | + { method: 'Debugger.enable' }, |
| 21 | + { |
| 22 | + method: 'Debugger.setInstrumentationBreakpoint', |
| 23 | + params: { instrumentation: 'beforeScriptExecution' }, |
| 24 | + }, |
| 25 | + { method: 'Runtime.runIfWaitingForDebugger' }, |
| 26 | + ]; |
| 27 | + |
| 28 | + await session.send(commands); |
| 29 | + |
| 30 | + const mainURL = new URL('main.js', session.scriptURL()).href; |
| 31 | + |
| 32 | + // Break on start. |
| 33 | + await session.waitForBreakOnLine(3, 'node:internal/main/run_main_module'); |
| 34 | + await session.send([{ method: 'Debugger.resume' }]); |
| 35 | + |
| 36 | + // Script loaded. |
| 37 | + await session.waitForBreakOnLine(0, mainURL); |
| 38 | + await session.send([{ method: 'Debugger.resume' }]); |
| 39 | + |
| 40 | + // Dependency loaded. |
| 41 | + await session.waitForBreakOnLine(0, mainURL); |
| 42 | +} |
| 43 | + |
| 44 | +async function runTest() { |
| 45 | + const main = fixtures.path( |
| 46 | + 'inspector-instrumentation-breakpoint', |
| 47 | + 'main.js', |
| 48 | + ); |
| 49 | + |
| 50 | + const child = new NodeInstance(['--inspect-brk=0'], '', main); |
| 51 | + const session = await child.connectInspectorSession(); |
| 52 | + |
| 53 | + await testBreakpointBeforeScriptExecution(session); |
| 54 | + await session.runToCompletion(); |
| 55 | + |
| 56 | + assert.strictEqual((await child.expectShutdown()).exitCode, 0); |
| 57 | +} |
| 58 | + |
| 59 | +runTest(); |
0 commit comments