Skip to content

Commit 7bffdc7

Browse files
authored
Merge pull request #10 from xudafeng/old-interface-compatible
Compatible old interface
2 parents f228573 + c11ca7a commit 7bffdc7

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/detect-port.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ module.exports = function() {
2323
reject('wrong number of arguments');
2424
}
2525

26-
const port = args[0];
26+
const port = parseInt(args[0], 10);
2727

28-
if (typeof port !== 'number') {
29-
reject(`wrong type of arguments with: ${port}`);
28+
if (isNaN(port)) {
29+
reject(`wrong type of arguments with: '${args[0]}'`);
3030
}
3131

3232
const loop = port => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "detect-port",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "detect available port",
55
"keywords": [
66
"detect",

test/detect-port.test.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ describe('detect port test', () => {
2828
});
2929
});
3030

31-
it('callback with wrong arguments', done => {
32-
detectPort('8080', err => {
31+
it('callback with string arg', done => {
32+
const _port = '8080';
33+
detectPort(_port, (err, port) => {
3334
if (err) {
34-
err.should.containEql('wrong type of arguments');
35+
console.log(err);
3536
}
37+
port.should.within(parseInt(_port, 10), 65535);
38+
done();
39+
});
40+
});
41+
42+
it('callback with wrong arguments', done => {
43+
detectPort('oooo', err => {
44+
err.should.containEql('wrong type of arguments');
3645
done();
3746
});
3847
});
@@ -73,7 +82,7 @@ describe('detect port test', () => {
7382

7483
it('generator with wrong arguments', function *() {
7584
try {
76-
yield detectPort('8080');
85+
yield detectPort('oooo');
7786
} catch (err) {
7887
err.should.containEql('wrong type of arguments');
7988
}

0 commit comments

Comments
 (0)