|
| 1 | +// Flags: --expose-internals |
| 2 | +'use strict'; |
| 3 | +constcommon=require('../common'); |
| 4 | + |
| 5 | +common.skipIfInspectorDisabled(); |
| 6 | + |
| 7 | +constassert=require('assert'); |
| 8 | +constfixtures=require('../common/fixtures'); |
| 9 | +const{ NodeInstance }=require('../common/inspector-helper.js'); |
| 10 | + |
| 11 | +functionassertNoUrlsWhileConnected(response){ |
| 12 | +assert.strictEqual(response.length,1); |
| 13 | +assert.ok(!response[0].hasOwnProperty('devtoolsFrontendUrl')); |
| 14 | +assert.ok(!response[0].hasOwnProperty('webSocketDebuggerUrl')); |
| 15 | +} |
| 16 | + |
| 17 | +functionassertScopeValues({ result },expected){ |
| 18 | +constunmatched=newSet(Object.keys(expected)); |
| 19 | +for(constactualofresult){ |
| 20 | +constvalue=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 | +asyncfunctiontestBreakpointOnStart(session){ |
| 28 | +console.log('[test]', |
| 29 | +'Verifying debugger stops on start (--inspect-brk option)'); |
| 30 | +constcommands=[ |
| 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 | +awaitsession.send(commands); |
| 46 | +awaitsession.waitForBreakOnLine(0,session.scriptURL()); |
| 47 | +} |
| 48 | + |
| 49 | +asyncfunctiontestBreakpoint(session){ |
| 50 | +console.log('[test]','Setting a breakpoint and verifying it is hit'); |
| 51 | +constcommands=[ |
| 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 | +awaitsession.send(commands); |
| 62 | +const{ scriptSource }=awaitsession.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 | +awaitsession.waitForConsoleOutput('log',['A message',5]); |
| 69 | +constpaused=awaitsession.waitForBreakOnLine(5,session.scriptURL()); |
| 70 | +constscopeId=paused.params.callFrames[0].scopeChain[0].object.objectId; |
| 71 | + |
| 72 | +console.log('[test]','Verify we can read current application state'); |
| 73 | +constresponse=awaitsession.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 }=awaitsession.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=(awaitsession.send({ |
| 99 | +'method': 'Runtime.evaluate','params': { |
| 100 | +'expression': '5 * 5' |
| 101 | +} |
| 102 | +})).result; |
| 103 | +assert.strictEqual(result['value'],25); |
| 104 | +} |
| 105 | + |
| 106 | +asyncfunctionrunTest(){ |
| 107 | +constchild=newNodeInstance(['--inspect-brk=0','--experimental-modules'], |
| 108 | +'',fixtures.path('es-modules/loop.mjs')); |
| 109 | + |
| 110 | +constsession=awaitchild.connectInspectorSession(); |
| 111 | +assertNoUrlsWhileConnected(awaitchild.httpGet(null,'/json/list')); |
| 112 | +awaittestBreakpointOnStart(session); |
| 113 | +awaittestBreakpoint(session); |
| 114 | +awaitsession.runToCompletion(); |
| 115 | +assert.strictEqual((awaitchild.expectShutdown()).exitCode,55); |
| 116 | +} |
| 117 | + |
| 118 | +common.crashOnUnhandledRejection(); |
| 119 | + |
| 120 | +runTest(); |
0 commit comments