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