summaryrefslogtreecommitdiff
path: root/test/inspector-cli/test-inspector-cli-invalid-args.js
blob: 841d7a883178d7ece188e8ba60dccab8305bb195 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const common = require('../common');

common.skipIfInspectorDisabled();

const fixtures = require('../common/fixtures');
const startCLI = require('../common/inspector-cli');

const assert = require('assert');
const { createServer } = require('net');

// Launch CLI w/o args.
{
  const cli = startCLI([]);
  cli.quit()
    .then((code) => {
      assert.strictEqual(code, 1);
      assert.match(cli.output, /^Usage:/, 'Prints usage info');
    });
}

// Launch w/ invalid host:port.
{
  const cli = startCLI(['localhost:914']);
  cli.quit()
    .then((code) => {
      assert.match(
        cli.output,
        /failed to connect/,
        'Tells the user that the connection failed');
      assert.strictEqual(code, 1);
    });
}

// Launch w/ unavailable port.
(async () => {
  const blocker = createServer((socket) => socket.end());
  const port = await new Promise((resolve, reject) => {
    blocker.on('error', reject);
    blocker.listen(0, '127.0.0.1', () => resolve(blocker.address().port));
  });

  try {
    const script = fixtures.path('inspector-cli', 'three-lines.js');
    const cli = startCLI([`--port=${port}`, script]);
    const code = await cli.quit();

    assert.doesNotMatch(
      cli.output,
      /report this bug/,
      'Omits message about reporting this as a bug');
    assert.ok(
      cli.output.includes(`waiting for 127.0.0.1:${port} to be free`),
      'Tells the user that the port wasn\'t available');
    assert.strictEqual(code, 1);
  } finally {
    blocker.close();
  }
})().then(common.mustCall());