11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
41cb0ef41Sopenharmony_cicommon.skipIf32Bits();
51cb0ef41Sopenharmony_ciconst { NodeInstance } = require('../common/inspector-helper.js');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst script = `
91cb0ef41Sopenharmony_cisetTimeout(() => {
101cb0ef41Sopenharmony_ci  debugger;
111cb0ef41Sopenharmony_ci  process.exitCode = 55;
121cb0ef41Sopenharmony_ci}, 50);
131cb0ef41Sopenharmony_ci`;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciasync function skipBreakpointAtStart(session) {
161cb0ef41Sopenharmony_ci  await session.waitForBreakOnLine(1, '[eval]');
171cb0ef41Sopenharmony_ci  await session.send({ 'method': 'Debugger.resume' });
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciasync function checkAsyncStackTrace(session) {
211cb0ef41Sopenharmony_ci  console.error('[test]', 'Verify basic properties of asyncStackTrace');
221cb0ef41Sopenharmony_ci  const paused = await session.waitForBreakOnLine(2, '[eval]');
231cb0ef41Sopenharmony_ci  assert(paused.params.asyncStackTrace,
241cb0ef41Sopenharmony_ci         `${Object.keys(paused.params)} contains "asyncStackTrace" property`);
251cb0ef41Sopenharmony_ci  assert(paused.params.asyncStackTrace.description, 'Timeout');
261cb0ef41Sopenharmony_ci  assert(paused.params.asyncStackTrace.callFrames
271cb0ef41Sopenharmony_ci           .some((frame) => frame.url === 'node:internal/process/execution'));
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciasync function runTests() {
311cb0ef41Sopenharmony_ci  const instance = new NodeInstance(undefined, script);
321cb0ef41Sopenharmony_ci  const session = await instance.connectInspectorSession();
331cb0ef41Sopenharmony_ci  await session.send([
341cb0ef41Sopenharmony_ci    { 'method': 'Runtime.enable' },
351cb0ef41Sopenharmony_ci    { 'method': 'Debugger.enable' },
361cb0ef41Sopenharmony_ci    { 'method': 'Debugger.setAsyncCallStackDepth',
371cb0ef41Sopenharmony_ci      'params': { 'maxDepth': 10 } },
381cb0ef41Sopenharmony_ci    { 'method': 'Debugger.setBlackboxPatterns',
391cb0ef41Sopenharmony_ci      'params': { 'patterns': [] } },
401cb0ef41Sopenharmony_ci    { 'method': 'Runtime.runIfWaitingForDebugger' },
411cb0ef41Sopenharmony_ci  ]);
421cb0ef41Sopenharmony_ci  await skipBreakpointAtStart(session);
431cb0ef41Sopenharmony_ci  await checkAsyncStackTrace(session);
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  await session.runToCompletion();
461cb0ef41Sopenharmony_ci  assert.strictEqual((await instance.expectShutdown()).exitCode, 55);
471cb0ef41Sopenharmony_ci}
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_cirunTests().then(common.mustCall());
50