Skip to content

Commit

Permalink
Merge pull request #10 from xudafeng/old-interface-compatible
Browse files Browse the repository at this point in the history
Compatible old interface
  • Loading branch information
xudafeng committed Oct 31, 2016
2 parents f228573 + c11ca7a commit 7bffdc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/detect-port.js
Expand Up @@ -23,10 +23,10 @@ module.exports = function() {
reject('wrong number of arguments');
}

const port = args[0];
const port = parseInt(args[0], 10);

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

const loop = port => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "detect-port",
"version": "1.0.4",
"version": "1.0.5",
"description": "detect available port",
"keywords": [
"detect",
Expand Down
17 changes: 13 additions & 4 deletions test/detect-port.test.js
Expand Up @@ -28,11 +28,20 @@ describe('detect port test', () => {
});
});

it('callback with wrong arguments', done => {
detectPort('8080', err => {
it('callback with string arg', done => {
const _port = '8080';
detectPort(_port, (err, port) => {
if (err) {
err.should.containEql('wrong type of arguments');
console.log(err);
}
port.should.within(parseInt(_port, 10), 65535);
done();
});
});

it('callback with wrong arguments', done => {
detectPort('oooo', err => {
err.should.containEql('wrong type of arguments');
done();
});
});
Expand Down Expand Up @@ -73,7 +82,7 @@ describe('detect port test', () => {

it('generator with wrong arguments', function *() {
try {
yield detectPort('8080');
yield detectPort('oooo');
} catch (err) {
err.should.containEql('wrong type of arguments');
}
Expand Down

0 comments on commit 7bffdc7

Please sign in to comment.