2017-07-17 14:51:26 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfInspectorDisabled();
|
|
|
|
common.skipIf32Bits();
|
2017-10-14 02:42:38 +00:00
|
|
|
const { NodeInstance } = require('../common/inspector-helper');
|
2017-07-17 14:51:26 +00:00
|
|
|
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();
|
2024-02-23 22:46:29 +00:00
|
|
|
await session.send({ method: 'NodeRuntime.enable' });
|
|
|
|
await session.waitForNotification('NodeRuntime.waitingForDebugger');
|
2017-07-17 14:51:26 +00:00
|
|
|
await session.send([
|
|
|
|
{ 'method': 'Runtime.enable' },
|
|
|
|
{ 'method': 'Debugger.enable' },
|
|
|
|
{ 'method': 'Debugger.setAsyncCallStackDepth',
|
|
|
|
'params': { 'maxDepth': 10 } },
|
|
|
|
{ 'method': 'Debugger.setBlackboxPatterns',
|
|
|
|
'params': { 'patterns': [] } },
|
2021-03-26 15:51:08 +00:00
|
|
|
{ 'method': 'Runtime.runIfWaitingForDebugger' },
|
2017-07-17 14:51:26 +00:00
|
|
|
]);
|
2024-09-13 18:36:02 +00:00
|
|
|
await session.send({ method: 'NodeRuntime.disable' });
|
2017-07-17 14:51:26 +00:00
|
|
|
|
2019-01-30 22:13:45 +00:00
|
|
|
await session.waitForBreakOnLine(0, '[eval]');
|
2017-08-01 22:28:51 +00:00
|
|
|
await session.send({ 'method': 'Debugger.resume' });
|
|
|
|
|
2017-07-17 14:51:26 +00:00
|
|
|
console.error('[test] Waiting for break1');
|
2019-01-30 22:13:45 +00:00
|
|
|
debuggerPausedAt(await session.waitForBreakOnLine(4, '[eval]'),
|
|
|
|
'break1', 'runTest:3');
|
2017-07-17 14:51:26 +00:00
|
|
|
|
|
|
|
await session.send({ 'method': 'Debugger.resume' });
|
|
|
|
|
|
|
|
console.error('[test] Waiting for break2');
|
2019-01-30 22:13:45 +00:00
|
|
|
debuggerPausedAt(await session.waitForBreakOnLine(7, '[eval]'),
|
|
|
|
'break2', 'runTest:6');
|
2017-07-17 14:51:26 +00:00
|
|
|
|
|
|
|
await session.runToCompletion();
|
2018-10-12 17:11:12 +00:00
|
|
|
assert.strictEqual((await instance.expectShutdown()).exitCode, 0);
|
2017-07-17 14:51:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function debuggerPausedAt(msg, functionName, previousTickLocation) {
|
|
|
|
assert(
|
|
|
|
!!msg.params.asyncStackTrace,
|
|
|
|
`${Object.keys(msg.params)} contains "asyncStackTrace" property`);
|
|
|
|
|
|
|
|
assert.strictEqual(msg.params.callFrames[0].functionName, functionName);
|
2017-11-30 10:17:51 +00:00
|
|
|
assert.strictEqual(msg.params.asyncStackTrace.description, 'Promise.then');
|
2017-07-17 14:51:26 +00:00
|
|
|
|
|
|
|
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}.`);
|
|
|
|
}
|
|
|
|
|
2020-04-05 20:27:46 +00:00
|
|
|
runTests().then(common.mustCall());
|