2017-07-24 09:23:04 -07:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfInspectorDisabled();
|
|
|
|
const assert = require('assert');
|
2017-10-13 22:42:38 -04:00
|
|
|
const { NodeInstance } = require('../common/inspector-helper.js');
|
|
|
|
const fixtures = require('../common/fixtures');
|
2018-08-30 14:59:34 -07:00
|
|
|
const { pathToFileURL } = require('url');
|
2017-07-24 09:23:04 -07:00
|
|
|
|
2022-12-13 23:51:05 +01:00
|
|
|
// This needs to be an ES module file to ensure that internal modules are
|
|
|
|
// loaded before pausing. See
|
|
|
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=1246905
|
|
|
|
const script = fixtures.path('inspector-global-function.mjs');
|
2017-07-24 09:23:04 -07:00
|
|
|
|
|
|
|
async function setupDebugger(session) {
|
|
|
|
console.log('[test]', 'Setting up a debugger');
|
|
|
|
const commands = [
|
|
|
|
{ 'method': 'Runtime.enable' },
|
|
|
|
{ 'method': 'Debugger.enable' },
|
|
|
|
{ 'method': 'Debugger.setAsyncCallStackDepth',
|
|
|
|
'params': { 'maxDepth': 0 } },
|
|
|
|
{ 'method': 'Runtime.runIfWaitingForDebugger' },
|
|
|
|
];
|
2024-02-23 14:46:29 -08:00
|
|
|
await session.send({ method: 'NodeRuntime.enable' });
|
|
|
|
await session.waitForNotification('NodeRuntime.waitingForDebugger');
|
|
|
|
await session.send(commands);
|
|
|
|
await session.send({ method: 'NodeRuntime.disable' });
|
2020-03-12 11:57:22 -07:00
|
|
|
|
|
|
|
await session.waitForNotification('Debugger.paused', 'Initial pause');
|
|
|
|
|
|
|
|
// NOTE(mmarchini): We wait for the second console.log to ensure we loaded
|
|
|
|
// every internal module before pausing. See
|
2022-12-13 23:51:05 +01:00
|
|
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=1246905
|
2020-03-12 11:57:22 -07:00
|
|
|
const waitForReady = session.waitForConsoleOutput('log', 'Ready!');
|
|
|
|
session.send({ 'method': 'Debugger.resume' });
|
|
|
|
await waitForReady;
|
2017-07-24 09:23:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async function breakOnLine(session) {
|
|
|
|
console.log('[test]', 'Breaking in the code');
|
|
|
|
const commands = [
|
|
|
|
{ 'method': 'Debugger.setBreakpointByUrl',
|
|
|
|
'params': { 'lineNumber': 9,
|
2018-08-30 14:59:34 -07:00
|
|
|
'url': pathToFileURL(script).toString(),
|
2017-07-24 09:23:04 -07:00
|
|
|
'columnNumber': 0,
|
2021-01-23 11:46:29 -08:00
|
|
|
'condition': '' } },
|
2017-07-24 09:23:04 -07:00
|
|
|
{ 'method': 'Runtime.evaluate',
|
|
|
|
'params': { 'expression': 'sum()',
|
|
|
|
'objectGroup': 'console',
|
|
|
|
'includeCommandLineAPI': true,
|
|
|
|
'silent': false,
|
|
|
|
'contextId': 1,
|
|
|
|
'returnByValue': false,
|
|
|
|
'generatePreview': true,
|
|
|
|
'userGesture': true,
|
2021-03-26 08:51:08 -07:00
|
|
|
'awaitPromise': false } },
|
2017-07-24 09:23:04 -07:00
|
|
|
];
|
|
|
|
session.send(commands);
|
2018-08-30 14:59:34 -07:00
|
|
|
await session.waitForBreakOnLine(9, pathToFileURL(script).toString());
|
2017-07-24 09:23:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async function stepOverConsoleStatement(session) {
|
|
|
|
console.log('[test]', 'Step over console statement and test output');
|
|
|
|
session.send({ 'method': 'Debugger.stepOver' });
|
|
|
|
await session.waitForConsoleOutput('log', [0, 3]);
|
|
|
|
await session.waitForNotification('Debugger.paused');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function runTests() {
|
2024-09-28 23:58:55 +10:00
|
|
|
// NOTE(mmarchini): Use --inspect-brk to improve avoid indeterministic
|
2020-03-12 11:57:22 -07:00
|
|
|
// behavior.
|
|
|
|
const child = new NodeInstance(['--inspect-brk=0'], undefined, script);
|
2017-07-24 09:23:04 -07:00
|
|
|
const session = await child.connectInspectorSession();
|
|
|
|
await setupDebugger(session);
|
|
|
|
await breakOnLine(session);
|
|
|
|
await stepOverConsoleStatement(session);
|
|
|
|
await session.runToCompletion();
|
2018-10-12 10:23:40 -07:00
|
|
|
assert.strictEqual((await child.expectShutdown()).exitCode, 0);
|
2017-07-24 09:23:04 -07:00
|
|
|
}
|
|
|
|
|
2020-04-05 22:27:46 +02:00
|
|
|
runTests().then(common.mustCall());
|