From e016e952e640770ceba13cef186387f37c406709 Mon Sep 17 00:00:00 2001 From: Konstantin Ulitin Date: Sun, 12 May 2024 22:33:07 +0200 Subject: [PATCH] test: add `Debugger.setInstrumentationBreakpoint` known issue PR-URL: https://github.com/nodejs/node/pull/31137 Refs: https://github.com/nodejs/node/issues/31138 Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott Reviewed-By: James M Snell --- test/common/index.js | 3 +- .../dep.js | 1 + .../main.js | 1 + ...st-inspector-instrumentation-breakpoint.js | 54 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/inspector-instrumentation-breakpoint/dep.js create mode 100644 test/fixtures/inspector-instrumentation-breakpoint/main.js create mode 100644 test/known_issues/test-inspector-instrumentation-breakpoint.js diff --git a/test/common/index.js b/test/common/index.js index 84805723e4be6a..4fbaf91fea1ef9 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -603,7 +603,8 @@ function printSkipMessage(msg) { function skip(msg) { printSkipMessage(msg); - process.exit(0); + // In known_issues test, skipping should produce a non-zero exit code. + process.exit(require.main?.filename.startsWith(path.resolve(__dirname, '../known_issues/')) ? 1 : 0); } // Returns true if the exit code "exitCode" and/or signal name "signal" diff --git a/test/fixtures/inspector-instrumentation-breakpoint/dep.js b/test/fixtures/inspector-instrumentation-breakpoint/dep.js new file mode 100644 index 00000000000000..e2ba44676df631 --- /dev/null +++ b/test/fixtures/inspector-instrumentation-breakpoint/dep.js @@ -0,0 +1 @@ +console.log('dep loaded'); diff --git a/test/fixtures/inspector-instrumentation-breakpoint/main.js b/test/fixtures/inspector-instrumentation-breakpoint/main.js new file mode 100644 index 00000000000000..a0b8fdf1c94ad4 --- /dev/null +++ b/test/fixtures/inspector-instrumentation-breakpoint/main.js @@ -0,0 +1 @@ +require('./dep'); diff --git a/test/known_issues/test-inspector-instrumentation-breakpoint.js b/test/known_issues/test-inspector-instrumentation-breakpoint.js new file mode 100644 index 00000000000000..0105097f2baf4a --- /dev/null +++ b/test/known_issues/test-inspector-instrumentation-breakpoint.js @@ -0,0 +1,54 @@ +// This test validates inspector's Debugger.setInstrumentationBreakpoint method. +// Refs: https://github.com/nodejs/node/issues/31138 + +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const { resolve: UrlResolve } = require('url'); +const fixtures = require('../common/fixtures'); +const { NodeInstance } = require('../common/inspector-helper.js'); + +async function testBreakpointBeforeScriptExecution(session) { + console.log('[test]', + 'Verifying debugger stops on start of each script ' + + '(Debugger.setInstrumentationBreakpoint with beforeScriptExecution)'); + const commands = [ + { 'method': 'Runtime.enable' }, + { 'method': 'Debugger.enable' }, + { 'method': 'Debugger.setInstrumentationBreakpoint', + 'params': { 'instrumentation': 'beforeScriptExecution' } }, + { 'method': 'Runtime.runIfWaitingForDebugger' }, + ]; + + await session.send(commands); + + // Break on start + await session.waitForBreakOnLine( + 0, UrlResolve(session.scriptURL().toString(), 'main.js')); + await session.send([{ 'method': 'Debugger.resume' }]); + + // Script loaded + await session.waitForBreakOnLine( + 0, UrlResolve(session.scriptURL().toString(), 'main.js')); + await session.send([{ 'method': 'Debugger.resume' }]); + + // Script loaded + await session.waitForBreakOnLine( + 0, UrlResolve(session.scriptURL().toString(), 'dep.js')); + await session.send([{ 'method': 'Debugger.resume' }]); +} + +async function runTest() { + const main = fixtures.path('inspector-instrumentation-breakpoint', 'main.js'); + const child = new NodeInstance(['--inspect-brk=0'], '', main); + + const session = await child.connectInspectorSession(); + await testBreakpointBeforeScriptExecution(session); + await session.runToCompletion(); + assert.strictEqual((await child.expectShutdown()).exitCode, 0); +} + +runTest();