|
| 1 | +// Flags: --expose-internals |
| 2 | +'use strict'; |
| 3 | +const common = require('../common'); |
| 4 | + |
| 5 | +common.skipIfInspectorDisabled(); |
| 6 | + |
| 7 | +const assert = require('assert'); |
| 8 | +const fixtures = require('../common/fixtures'); |
| 9 | +const { NodeInstance } = require('../common/inspector-helper.js'); |
| 10 | + |
| 11 | +function assertNoUrlsWhileConnected(response) { |
| 12 | + assert.strictEqual(response.length, 1); |
| 13 | + assert.ok(!response[0].hasOwnProperty('devtoolsFrontendUrl')); |
| 14 | + assert.ok(!response[0].hasOwnProperty('webSocketDebuggerUrl')); |
| 15 | +} |
| 16 | + |
| 17 | +function assertScopeValues({ result }, expected) { |
| 18 | + const unmatched = new Set(Object.keys(expected)); |
| 19 | + for (const actual of result) { |
| 20 | + const value = expected[actual['name']]; |
| 21 | + assert.strictEqual(actual['value']['value'], value); |
| 22 | + unmatched.delete(actual['name']); |
| 23 | + } |
| 24 | + assert.deepStrictEqual(Array.from(unmatched.values()), []); |
| 25 | +} |
| 26 | + |
| 27 | +async function testBreakpointOnStart(session) { |
| 28 | + console.log('[test]', |
| 29 | + 'Verifying debugger stops on start (--inspect-brk option)'); |
| 30 | + const commands = [ |
| 31 | + { 'method': 'Runtime.enable' }, |
| 32 | + { 'method': 'Debugger.enable' }, |
| 33 | + { 'method': 'Debugger.setPauseOnExceptions', |
| 34 | + 'params': { 'state': 'none' } }, |
| 35 | + { 'method': 'Debugger.setAsyncCallStackDepth', |
| 36 | + 'params': { 'maxDepth': 0 } }, |
| 37 | + { 'method': 'Profiler.enable' }, |
| 38 | + { 'method': 'Profiler.setSamplingInterval', |
| 39 | + 'params': { 'interval': 100 } }, |
| 40 | + { 'method': 'Debugger.setBlackboxPatterns', |
| 41 | + 'params': { 'patterns': [] } }, |
| 42 | + { 'method': 'Runtime.runIfWaitingForDebugger' } |
| 43 | + ]; |
| 44 | + |
| 45 | + await session.send(commands); |
| 46 | + await session.waitForBreakOnLine(0, session.scriptURL()); |
| 47 | +} |
| 48 | + |
| 49 | +async function testBreakpoint(session) { |
| 50 | + console.log('[test]', 'Setting a breakpoint and verifying it is hit'); |
| 51 | + const commands = [ |
| 52 | + { 'method': 'Debugger.setBreakpointByUrl', |
| 53 | + 'params': { 'lineNumber': 5, |
| 54 | + 'url': session.scriptURL(), |
| 55 | + 'columnNumber': 0, |
| 56 | + 'condition': '' |
| 57 | + } |
| 58 | + }, |
| 59 | + { 'method': 'Debugger.resume' }, |
| 60 | + ]; |
| 61 | + await session.send(commands); |
| 62 | + const { scriptSource } = await session.send({ |
| 63 | + 'method': 'Debugger.getScriptSource', |
| 64 | + 'params': { 'scriptId': session.mainScriptId } }); |
| 65 | + assert(scriptSource && (scriptSource.includes(session.script())), |
| 66 | + `Script source is wrong: ${scriptSource}`); |
| 67 | + |
| 68 | + await session.waitForConsoleOutput('log', ['A message', 5]); |
| 69 | + const paused = await session.waitForBreakOnLine(5, session.scriptURL()); |
| 70 | + const scopeId = paused.params.callFrames[0].scopeChain[0].object.objectId; |
| 71 | + |
| 72 | + console.log('[test]', 'Verify we can read current application state'); |
| 73 | + const response = await session.send({ |
| 74 | + 'method': 'Runtime.getProperties', |
| 75 | + 'params': { |
| 76 | + 'objectId': scopeId, |
| 77 | + 'ownProperties': false, |
| 78 | + 'accessorPropertiesOnly': false, |
| 79 | + 'generatePreview': true |
| 80 | + } |
| 81 | + }); |
| 82 | + assertScopeValues(response, { t: 1001, k: 1 }); |
| 83 | + |
| 84 | + let { result } = await session.send({ |
| 85 | + 'method': 'Debugger.evaluateOnCallFrame', 'params': { |
| 86 | + 'callFrameId': '{"ordinal":0,"injectedScriptId":1}', |
| 87 | + 'expression': 'k + t', |
| 88 | + 'objectGroup': 'console', |
| 89 | + 'includeCommandLineAPI': true, |
| 90 | + 'silent': false, |
| 91 | + 'returnByValue': false, |
| 92 | + 'generatePreview': true |
| 93 | + } |
| 94 | + }); |
| 95 | + |
| 96 | + assert.strictEqual(result['value'], 1002); |
| 97 | + |
| 98 | + result = (await session.send({ |
| 99 | + 'method': 'Runtime.evaluate', 'params': { |
| 100 | + 'expression': '5 * 5' |
| 101 | + } |
| 102 | + })).result; |
| 103 | + assert.strictEqual(result['value'], 25); |
| 104 | +} |
| 105 | + |
| 106 | +async function runTest() { |
| 107 | + const child = new NodeInstance(['--inspect-brk=0', '--experimental-modules'], |
| 108 | + '', fixtures.path('es-modules/loop.mjs')); |
| 109 | + |
| 110 | + const session = await child.connectInspectorSession(); |
| 111 | + assertNoUrlsWhileConnected(await child.httpGet(null, '/json/list')); |
| 112 | + await testBreakpointOnStart(session); |
| 113 | + await testBreakpoint(session); |
| 114 | + await session.runToCompletion(); |
| 115 | + assert.strictEqual((await child.expectShutdown()).exitCode, 55); |
| 116 | +} |
| 117 | + |
| 118 | +common.crashOnUnhandledRejection(); |
| 119 | + |
| 120 | +runTest(); |
0 commit comments