11cb0ef41Sopenharmony_ciimport * as common from '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport * as fixtures from '../common/fixtures.mjs';
31cb0ef41Sopenharmony_ciimport assert from 'node:assert';
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst debuggerPort = common.getPort();
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciasync function spawnRunner({ execArgv, expectedPort, expectedHost, expectedInitialPort, inspectPort }) {
111cb0ef41Sopenharmony_ci  const { code, signal } = await common.spawnPromisified(
121cb0ef41Sopenharmony_ci    process.execPath,
131cb0ef41Sopenharmony_ci    ['--expose-internals', '--no-warnings', ...execArgv, fixtures.path('test-runner/run_inspect.js')], {
141cb0ef41Sopenharmony_ci      env: { ...process.env,
151cb0ef41Sopenharmony_ci             expectedPort,
161cb0ef41Sopenharmony_ci             inspectPort,
171cb0ef41Sopenharmony_ci             expectedHost,
181cb0ef41Sopenharmony_ci             expectedInitialPort }
191cb0ef41Sopenharmony_ci    });
201cb0ef41Sopenharmony_ci  assert.strictEqual(code, 0);
211cb0ef41Sopenharmony_ci  assert.strictEqual(signal, null);
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cilet offset = 0;
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciconst defaultPortCase = spawnRunner({
271cb0ef41Sopenharmony_ci  execArgv: ['--inspect'],
281cb0ef41Sopenharmony_ci  expectedPort: 9230,
291cb0ef41Sopenharmony_ci});
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciawait spawnRunner({
321cb0ef41Sopenharmony_ci  execArgv: ['--inspect=65535'],
331cb0ef41Sopenharmony_ci  expectedPort: 1024,
341cb0ef41Sopenharmony_ci});
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cilet port = debuggerPort + offset++ * 5;
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciawait spawnRunner({
391cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
401cb0ef41Sopenharmony_ci  expectedPort: port + 1,
411cb0ef41Sopenharmony_ci});
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciawait spawnRunner({
461cb0ef41Sopenharmony_ci  execArgv: ['--inspect', `--inspect-port=${port}`],
471cb0ef41Sopenharmony_ci  expectedPort: port + 1,
481cb0ef41Sopenharmony_ci});
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciawait spawnRunner({
531cb0ef41Sopenharmony_ci  execArgv: ['--inspect', `--debug-port=${port}`],
541cb0ef41Sopenharmony_ci  expectedPort: port + 1,
551cb0ef41Sopenharmony_ci});
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ciawait spawnRunner({
601cb0ef41Sopenharmony_ci  execArgv: [`--inspect=0.0.0.0:${port}`],
611cb0ef41Sopenharmony_ci  expectedPort: port + 1, expectedHost: '0.0.0.0',
621cb0ef41Sopenharmony_ci});
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ciawait spawnRunner({
671cb0ef41Sopenharmony_ci  execArgv: [`--inspect=127.0.0.1:${port}`],
681cb0ef41Sopenharmony_ci  expectedPort: port + 1, expectedHost: '127.0.0.1'
691cb0ef41Sopenharmony_ci});
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ciif (common.hasIPv6) {
721cb0ef41Sopenharmony_ci  port = debuggerPort + offset++ * 5;
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci  await spawnRunner({
751cb0ef41Sopenharmony_ci    execArgv: [`--inspect=[::]:${port}`],
761cb0ef41Sopenharmony_ci    expectedPort: port + 1, expectedHost: '::'
771cb0ef41Sopenharmony_ci  });
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci  port = debuggerPort + offset++ * 5;
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci  await spawnRunner({
821cb0ef41Sopenharmony_ci    execArgv: [`--inspect=[::1]:${port}`],
831cb0ef41Sopenharmony_ci    expectedPort: port + 1, expectedHost: '::1'
841cb0ef41Sopenharmony_ci  });
851cb0ef41Sopenharmony_ci}
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci// These tests check that setting inspectPort in run
881cb0ef41Sopenharmony_ci// would take effect and override port incrementing behavior
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ciawait spawnRunner({
931cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
941cb0ef41Sopenharmony_ci  inspectPort: port + 2,
951cb0ef41Sopenharmony_ci  expectedPort: port + 2,
961cb0ef41Sopenharmony_ci});
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ciawait spawnRunner({
1011cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1021cb0ef41Sopenharmony_ci  inspectPort: 'addTwo',
1031cb0ef41Sopenharmony_ci  expectedPort: port + 2,
1041cb0ef41Sopenharmony_ci});
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ciawait spawnRunner({
1091cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1101cb0ef41Sopenharmony_ci  inspectPort: 'string',
1111cb0ef41Sopenharmony_ci});
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ciawait spawnRunner({
1161cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1171cb0ef41Sopenharmony_ci  inspectPort: 'null',
1181cb0ef41Sopenharmony_ci  expectedPort: port + 1,
1191cb0ef41Sopenharmony_ci});
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ciawait spawnRunner({
1241cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1251cb0ef41Sopenharmony_ci  inspectPort: 'bignumber',
1261cb0ef41Sopenharmony_ci});
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ciawait spawnRunner({
1311cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1321cb0ef41Sopenharmony_ci  inspectPort: 'negativenumber',
1331cb0ef41Sopenharmony_ci});
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ciawait spawnRunner({
1381cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1391cb0ef41Sopenharmony_ci  inspectPort: 'bignumberfunc'
1401cb0ef41Sopenharmony_ci});
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ciawait spawnRunner({
1451cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1461cb0ef41Sopenharmony_ci  inspectPort: 'strfunc',
1471cb0ef41Sopenharmony_ci});
1481cb0ef41Sopenharmony_ci
1491cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ciawait spawnRunner({
1521cb0ef41Sopenharmony_ci  execArgv: [`--inspect=${port}`],
1531cb0ef41Sopenharmony_ci  inspectPort: 0,
1541cb0ef41Sopenharmony_ci  expectedInitialPort: 0,
1551cb0ef41Sopenharmony_ci});
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ciawait defaultPortCase;
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ciport = debuggerPort + offset++ * 5;
1601cb0ef41Sopenharmony_ciawait spawnRunner({
1611cb0ef41Sopenharmony_ci  execArgv: ['--inspect'],
1621cb0ef41Sopenharmony_ci  inspectPort: port + 2,
1631cb0ef41Sopenharmony_ci  expectedInitialPort: port + 2,
1641cb0ef41Sopenharmony_ci});
165