• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4common.skipIfInspectorDisabled();
5
6const assert = require('assert');
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  session.send({ method: 'Runtime.runIfWaitingForDebugger' });
28  // Check that messages after first and before second waitForDebugger are
29  // received
30  await session.waitForConsoleOutput('log', 'after wait for debugger');
31  await session.waitForConsoleOutput('log', 'before second wait for debugger');
32  assert.ok(!session.unprocessedNotifications()
33                    .some((n) => n.method === 'Runtime.consoleAPICalled'));
34  const secondSession = await child.connectInspectorSession();
35  // Check that inspector.waitForDebugger can be resumed from another session
36  secondSession.send({ method: 'Runtime.runIfWaitingForDebugger' });
37  await session.waitForConsoleOutput('log', 'after second wait for debugger');
38  assert.ok(!session.unprocessedNotifications()
39                    .some((n) => n.method === 'Runtime.consoleAPICalled'));
40  secondSession.disconnect();
41  session.disconnect();
42
43  function main(prefix) {
44    const inspector = require('inspector');
45    inspector.open(0, undefined, false);
46    process._ws = inspector.url();
47    console.log('before wait for debugger');
48    inspector.waitForDebugger();
49    console.log('after wait for debugger');
50    console.log('before second wait for debugger');
51    inspector.waitForDebugger();
52    console.log('after second wait for debugger');
53  }
54
55  // Check that inspector.waitForDebugger throws if there is no active
56  // inspector
57  const re = /^Error \[ERR_INSPECTOR_NOT_ACTIVE\]: Inspector is not active$/;
58  assert.throws(() => require('inspector').waitForDebugger(), re);
59}
60
61runTests().then(common.mustCall());
62