• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3const common = require('../common');
4
5common.skipIfInspectorDisabled();
6
7const assert = require('assert');
8const { Session } = require('inspector');
9const path = require('path');
10const { pathToFileURL } = require('url');
11
12function debugged() {
13  return 42;
14}
15
16async function test() {
17  const session1 = new Session();
18  const session2 = new Session();
19
20  session1.connect();
21  session2.connect();
22
23  let session1Paused = false;
24  let session2Paused = false;
25
26  session1.on('Debugger.paused', () => session1Paused = true);
27  session2.on('Debugger.paused', () => session2Paused = true);
28
29  console.log('Connected');
30
31  session1.post('Debugger.enable');
32  session2.post('Debugger.enable');
33  console.log('Debugger was enabled');
34
35  await new Promise((resolve, reject) => {
36    session1.post('Debugger.setBreakpointByUrl', {
37      'lineNumber': 12,
38      'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
39      'columnNumber': 0,
40      'condition': ''
41    }, (error, result) => {
42      return error ? reject(error) : resolve(result);
43    });
44  });
45  console.log('Breakpoint was set');
46
47  debugged();
48
49  // Both sessions will receive the paused event
50  assert(session1Paused);
51  assert(session2Paused);
52  console.log('Breakpoint was hit');
53
54  session1.disconnect();
55  session2.disconnect();
56  console.log('Sessions were disconnected');
57}
58
59const interval = setInterval(() => {}, 1000);
60test().then(common.mustCall(() => {
61  clearInterval(interval);
62  console.log('Done!');
63}));
64