Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: check inspector command Debugger.setInstrumentationBreakpoint #31137

Merged
merged 6 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/inspector-instrumentation-breakpoint/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('dep loaded');
1 change: 1 addition & 0 deletions test/fixtures/inspector-instrumentation-breakpoint/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./dep');
54 changes: 54 additions & 0 deletions test/known_issues/test-inspector-instrumentation-breakpoint.js
Original file line number Diff line number Diff line change
@@ -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');

ulitink marked this conversation as resolved.
Show resolved Hide resolved
common.skipIfInspectorDisabled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like skipping makes the test succeeds, which is considered a failure for known_issues/ tests..


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();