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