11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
41cb0ef41Sopenharmony_ciconst { strictEqual } = require('assert');
51cb0ef41Sopenharmony_ciconst { NodeInstance } = require('../common/inspector-helper.js');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciasync function testNoServerNoCrash() {
81cb0ef41Sopenharmony_ci  console.log('Test there\'s no crash stopping server that was not started');
91cb0ef41Sopenharmony_ci  const instance = new NodeInstance([],
101cb0ef41Sopenharmony_ci                                    `process._debugEnd();
111cb0ef41Sopenharmony_ci                                     process.exit(42);`);
121cb0ef41Sopenharmony_ci  strictEqual((await instance.expectShutdown()).exitCode, 42);
131cb0ef41Sopenharmony_ci}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciasync function testNoSessionNoCrash() {
161cb0ef41Sopenharmony_ci  console.log('Test there\'s no crash stopping server without connecting');
171cb0ef41Sopenharmony_ci  const instance = new NodeInstance('--inspect=0',
181cb0ef41Sopenharmony_ci                                    'process._debugEnd();process.exit(42);');
191cb0ef41Sopenharmony_ci  strictEqual((await instance.expectShutdown()).exitCode, 42);
201cb0ef41Sopenharmony_ci}
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciasync function testSessionNoCrash() {
231cb0ef41Sopenharmony_ci  console.log('Test there\'s no crash stopping server after connecting');
241cb0ef41Sopenharmony_ci  const script = `process._debugEnd();
251cb0ef41Sopenharmony_ci                  process._debugProcess(process.pid);
261cb0ef41Sopenharmony_ci                  setTimeout(() => {
271cb0ef41Sopenharmony_ci                      console.log("Done");
281cb0ef41Sopenharmony_ci                      process.exit(42);
291cb0ef41Sopenharmony_ci                  });`;
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  const instance = new NodeInstance('--inspect-brk=0', script);
321cb0ef41Sopenharmony_ci  const session = await instance.connectInspectorSession();
331cb0ef41Sopenharmony_ci  await session.send({ 'method': 'Runtime.runIfWaitingForDebugger' });
341cb0ef41Sopenharmony_ci  await session.waitForServerDisconnect();
351cb0ef41Sopenharmony_ci  strictEqual((await instance.expectShutdown()).exitCode, 42);
361cb0ef41Sopenharmony_ci}
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciasync function runTest() {
391cb0ef41Sopenharmony_ci  await testNoServerNoCrash();
401cb0ef41Sopenharmony_ci  await testNoSessionNoCrash();
411cb0ef41Sopenharmony_ci  await testSessionNoCrash();
421cb0ef41Sopenharmony_ci}
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_cirunTest().then(common.mustCall());
45