11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
71cb0ef41Sopenharmony_ciconst startCLI = require('../common/debugger');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ciconst { createServer } = require('net');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// Launch w/ unavailable port.
131cb0ef41Sopenharmony_ci(async () => {
141cb0ef41Sopenharmony_ci  const blocker = createServer((socket) => socket.end());
151cb0ef41Sopenharmony_ci  const port = await new Promise((resolve, reject) => {
161cb0ef41Sopenharmony_ci    blocker.on('error', reject);
171cb0ef41Sopenharmony_ci    blocker.listen(0, '127.0.0.1', () => resolve(blocker.address().port));
181cb0ef41Sopenharmony_ci  });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  try {
211cb0ef41Sopenharmony_ci    const script = fixtures.path('debugger', 'three-lines.js');
221cb0ef41Sopenharmony_ci    const cli = startCLI([`--port=${port}`, script]);
231cb0ef41Sopenharmony_ci    const code = await cli.quit();
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    assert.doesNotMatch(
261cb0ef41Sopenharmony_ci      cli.output,
271cb0ef41Sopenharmony_ci      /report this bug/,
281cb0ef41Sopenharmony_ci      'Omits message about reporting this as a bug');
291cb0ef41Sopenharmony_ci    assert.ok(
301cb0ef41Sopenharmony_ci      cli.output.includes(`waiting for 127.0.0.1:${port} to be free`),
311cb0ef41Sopenharmony_ci      'Tells the user that the port wasn\'t available');
321cb0ef41Sopenharmony_ci    assert.strictEqual(code, 1);
331cb0ef41Sopenharmony_ci  } finally {
341cb0ef41Sopenharmony_ci    blocker.close();
351cb0ef41Sopenharmony_ci  }
361cb0ef41Sopenharmony_ci})().then(common.mustCall());
37