Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit cc7bdfc

Browse files
author
Jan Krems
committed
feat: Properly fail with invalid host:port
1 parent 3bba0f2 commit cc7bdfc

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

Diff for: lib/node-inspect.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ class NodeInspector {
123123
const attemptConnect = () => {
124124
++connectionAttempts;
125125
this.stdout.write('.');
126-
this.client.connect()
127-
.then(null, () => {
126+
return this.client.connect()
127+
.then(() => {
128+
this.stdout.write(' done');
129+
}, () => {
128130
// If it's failed to connect 10 times then print failed message
129131
if (connectionAttempts >= 10) {
130-
this.print(' failed to connect, please retry');
132+
this.stdout.write(' failed to connect, please retry\n');
131133
process.exit(1);
132134
}
133135
return delay(500).then(() => attemptConnect());

Diff for: test/cli/invalid-args.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const tap = require('tap');
3+
4+
const startCLI = require('./start-cli');
5+
6+
tap.test('launch CLI w/o args', (t) => {
7+
const cli = startCLI([]);
8+
return cli.quit()
9+
.then((code) => {
10+
t.equal(code, 1, 'exits with non-zero exit code');
11+
t.match(cli.output, /^Usage:/, 'Prints usage info');
12+
});
13+
});
14+
15+
tap.test('launch w/ invalid host:port', (t) => {
16+
const cli = startCLI(['localhost:914']);
17+
return cli.quit()
18+
.then((code) => {
19+
t.match(cli.output, 'failed to connect',
20+
'Tells the user that the connection failed');
21+
t.equal(code, 1, 'exits with non-zero exit code');
22+
});
23+
});

Diff for: test/cli/no-args.test.js

-13
This file was deleted.

0 commit comments

Comments
 (0)