• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 'use strict';
2 const common = require('../common');
3 common.skipIfInspectorDisabled();
4 common.skipIf32Bits();
5 const { NodeInstance } = require('../common/inspector-helper');
6 const assert = require('assert');
7 
8 const script = `runTest();
9 function runTest() {
10   const p = Promise.resolve();
11   p.then(function break1() { // lineNumber 3
12     debugger;
13   });
14   p.then(function break2() { // lineNumber 6
15     debugger;
16   });
17 }
18 `;
19 
20 async function runTests() {
21   const instance = new NodeInstance(undefined, script);
22   const session = await instance.connectInspectorSession();
23   await session.send([
24     { 'method': 'Runtime.enable' },
25     { 'method': 'Debugger.enable' },
26     { 'method': 'Debugger.setAsyncCallStackDepth',
27       'params': { 'maxDepth': 10 } },
28     { 'method': 'Debugger.setBlackboxPatterns',
29       'params': { 'patterns': [] } },
30     { 'method': 'Runtime.runIfWaitingForDebugger' },
31   ]);
32 
33   await session.waitForBreakOnLine(0, '[eval]');
34   await session.send({ 'method': 'Debugger.resume' });
35 
36   console.error('[test] Waiting for break1');
37   debuggerPausedAt(await session.waitForBreakOnLine(4, '[eval]'),
38                    'break1', 'runTest:3');
39 
40   await session.send({ 'method': 'Debugger.resume' });
41 
42   console.error('[test] Waiting for break2');
43   debuggerPausedAt(await session.waitForBreakOnLine(7, '[eval]'),
44                    'break2', 'runTest:6');
45 
46   await session.runToCompletion();
47   assert.strictEqual((await instance.expectShutdown()).exitCode, 0);
48 }
49 
50 function debuggerPausedAt(msg, functionName, previousTickLocation) {
51   assert(
52     !!msg.params.asyncStackTrace,
53     `${Object.keys(msg.params)} contains "asyncStackTrace" property`);
54 
55   assert.strictEqual(msg.params.callFrames[0].functionName, functionName);
56   assert.strictEqual(msg.params.asyncStackTrace.description, 'Promise.then');
57 
58   const frameLocations = msg.params.asyncStackTrace.callFrames.map(
59     (frame) => `${frame.functionName}:${frame.lineNumber}`);
60   assertArrayIncludes(frameLocations, previousTickLocation);
61 }
62 
63 function assertArrayIncludes(actual, expected) {
64   const expectedString = JSON.stringify(expected);
65   const actualString = JSON.stringify(actual);
66   assert(
67     actual.includes(expected),
68     `Expected ${actualString} to contain ${expectedString}.`);
69 }
70 
71 runTests().then(common.mustCall());
72