• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3common.skipIfInspectorDisabled();
4const assert = require('assert');
5const { NodeInstance } = require('../common/inspector-helper.js');
6const fixtures = require('../common/fixtures');
7const { pathToFileURL } = require('url');
8
9const script = fixtures.path('inspector-global-function.js');
10
11async function setupDebugger(session) {
12  console.log('[test]', 'Setting up a debugger');
13  const commands = [
14    { 'method': 'Runtime.enable' },
15    { 'method': 'Debugger.enable' },
16    { 'method': 'Debugger.setAsyncCallStackDepth',
17      'params': { 'maxDepth': 0 } },
18    { 'method': 'Runtime.runIfWaitingForDebugger' },
19  ];
20  session.send(commands);
21
22  await session.waitForNotification('Debugger.paused', 'Initial pause');
23
24  // NOTE(mmarchini): We wait for the second console.log to ensure we loaded
25  // every internal module before pausing. See
26  // https://bugs.chromium.org/p/v8/issues/detail?id=10287.
27  const waitForReady = session.waitForConsoleOutput('log', 'Ready!');
28  session.send({ 'method': 'Debugger.resume' });
29  await waitForReady;
30}
31
32async function breakOnLine(session) {
33  console.log('[test]', 'Breaking in the code');
34  const commands = [
35    { 'method': 'Debugger.setBreakpointByUrl',
36      'params': { 'lineNumber': 9,
37                  'url': pathToFileURL(script).toString(),
38                  'columnNumber': 0,
39                  'condition': '' } },
40    { 'method': 'Runtime.evaluate',
41      'params': { 'expression': 'sum()',
42                  'objectGroup': 'console',
43                  'includeCommandLineAPI': true,
44                  'silent': false,
45                  'contextId': 1,
46                  'returnByValue': false,
47                  'generatePreview': true,
48                  'userGesture': true,
49                  'awaitPromise': false } },
50  ];
51  session.send(commands);
52  await session.waitForBreakOnLine(9, pathToFileURL(script).toString());
53}
54
55async function stepOverConsoleStatement(session) {
56  console.log('[test]', 'Step over console statement and test output');
57  session.send({ 'method': 'Debugger.stepOver' });
58  await session.waitForConsoleOutput('log', [0, 3]);
59  await session.waitForNotification('Debugger.paused');
60}
61
62async function runTests() {
63  // NOTE(mmarchini): Use --inspect-brk to improve avoid undeterministic
64  // behavior.
65  const child = new NodeInstance(['--inspect-brk=0'], undefined, script);
66  const session = await child.connectInspectorSession();
67  await setupDebugger(session);
68  await breakOnLine(session);
69  await stepOverConsoleStatement(session);
70  await session.runToCompletion();
71  assert.strictEqual((await child.expectShutdown()).exitCode, 0);
72}
73
74runTests().then(common.mustCall());
75