-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
inspector: added inspector.waitForDebugger() #28453
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Flags: --expose-internals | ||
|
||
'use strict'; | ||
const common = require('../common'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { NodeInstance } = require('../common/inspector-helper.js'); | ||
|
||
async function runTests() { | ||
const child = new NodeInstance(['-e', `(${main.toString()})()`], '', ''); | ||
const session = await child.connectInspectorSession(); | ||
await session.send({ method: 'Runtime.enable' }); | ||
// Check that there is only one console message received. | ||
await session.waitForConsoleOutput('log', 'before wait for debugger'); | ||
assert.ok(!session.unprocessedNotifications() | ||
.some((n) => n.method === 'Runtime.consoleAPICalled')); | ||
// Check that inspector.url() is available between inspector.open() and | ||
// inspector.waitForDebugger() | ||
const { result: { value } } = await session.send({ | ||
method: 'Runtime.evaluate', | ||
params: { | ||
expression: 'process._ws', | ||
includeCommandLineAPI: true | ||
} | ||
}); | ||
assert.ok(value.startsWith('ws://')); | ||
session.send({ method: 'Runtime.runIfWaitingForDebugger' }); | ||
// Check that messages after first and before second waitForDebugger are | ||
// received | ||
await session.waitForConsoleOutput('log', 'after wait for debugger'); | ||
await session.waitForConsoleOutput('log', 'before second wait for debugger'); | ||
assert.ok(!session.unprocessedNotifications() | ||
.some((n) => n.method === 'Runtime.consoleAPICalled')); | ||
const secondSession = await child.connectInspectorSession(); | ||
// Check that inspector.waitForDebugger can be resumed from another session | ||
secondSession.send({ method: 'Runtime.runIfWaitingForDebugger' }); | ||
await session.waitForConsoleOutput('log', 'after second wait for debugger'); | ||
assert.ok(!session.unprocessedNotifications() | ||
.some((n) => n.method === 'Runtime.consoleAPICalled')); | ||
secondSession.disconnect(); | ||
session.disconnect(); | ||
|
||
function main(prefix) { | ||
const inspector = require('inspector'); | ||
inspector.open(0, undefined, false); | ||
process._ws = inspector.url(); | ||
console.log('before wait for debugger'); | ||
inspector.waitForDebugger(); | ||
console.log('after wait for debugger'); | ||
console.log('before second wait for debugger'); | ||
inspector.waitForDebugger(); | ||
console.log('after second wait for debugger'); | ||
} | ||
|
||
// Check that inspector.waitForDebugger throws if there is no active | ||
// inspector | ||
const re = /^Error \[ERR_INSPECTOR_NOT_ACTIVE\]: Inspector is not active$/; | ||
assert.throws(() => require('inspector').waitForDebugger(), re); | ||
} | ||
|
||
runTests(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should This include a timeout to prevent blocking forever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding timeout for this (as well as inspector.open) is definitely something we should do. I think it should be a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me. I prefer to do this work in separate PR if you do not mind.