MCPcopy Index your code
hub / github.com/nodejs/node / runTests

Function runTests

test/parallel/test-inspector-wait-for-connection.js:9–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7const { NodeInstance } = require('../common/inspector-helper.js');
8
9async function runTests() {
10 const child = new NodeInstance(['-e', `(${main.toString()})()`], '', '');
11 const session = await child.connectInspectorSession();
12 await session.send({ method: 'Runtime.enable' });
13 // Check that there is only one console message received.
14 await session.waitForConsoleOutput('log', 'before wait for debugger');
15 assert.ok(!session.unprocessedNotifications()
16 .some((n) => n.method === 'Runtime.consoleAPICalled'));
17 // Check that inspector.url() is available between inspector.open() and
18 // inspector.waitForDebugger()
19 const { result: { value } } = await session.send({
20 method: 'Runtime.evaluate',
21 params: {
22 expression: 'process._ws',
23 includeCommandLineAPI: true
24 }
25 });
26 assert.ok(value.startsWith('ws://'));
27 await session.send({ method: 'NodeRuntime.enable' });
28 child.write('first');
29 await session.waitForNotification('NodeRuntime.waitingForDebugger');
30 await session.send({ method: 'Runtime.runIfWaitingForDebugger' });
31 await session.send({ method: 'NodeRuntime.disable' });
32 // Check that messages after first and before second waitForDebugger are
33 // received
34 await session.waitForConsoleOutput('log', 'after wait for debugger');
35 await session.waitForConsoleOutput('log', 'before second wait for debugger');
36 assert.ok(!session.unprocessedNotifications()
37 .some((n) => n.method === 'Runtime.consoleAPICalled'));
38 const secondSession = await child.connectInspectorSession();
39 // Check that inspector.waitForDebugger can be resumed from another session
40 await session.send({ method: 'NodeRuntime.enable' });
41 child.write('second');
42 await session.waitForNotification('NodeRuntime.waitingForDebugger');
43 await session.send({ method: 'Runtime.runIfWaitingForDebugger' });
44 await session.send({ method: 'NodeRuntime.disable' });
45 await session.waitForConsoleOutput('log', 'after second wait for debugger');
46 assert.ok(!session.unprocessedNotifications()
47 .some((n) => n.method === 'Runtime.consoleAPICalled'));
48 secondSession.disconnect();
49 session.disconnect();
50
51 function main(prefix) {
52 const inspector = require('inspector');
53 inspector.open(0, undefined, false);
54 process._ws = inspector.url();
55 console.log('before wait for debugger');
56 process.stdin.once('data', (data) => {
57 if (data.toString() === 'first') {
58 inspector.waitForDebugger();
59 console.log('after wait for debugger');
60 console.log('before second wait for debugger');
61 process.stdin.once('data', (data) => {
62 if (data.toString() === 'second') {
63 inspector.waitForDebugger();
64 console.log('after second wait for debugger');
65 process.exit();
66 }

Calls 12

writeMethod · 0.95
waitForConsoleOutputMethod · 0.80
someMethod · 0.80
waitForNotificationMethod · 0.80
sendMethod · 0.65
disconnectMethod · 0.65
waitForDebuggerMethod · 0.65
requireFunction · 0.50
toStringMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…