From 2dc180b6f0e9065d48704b52e8ec94f14f3807ed Mon Sep 17 00:00:00 2001 From: xudafeng Date: Mon, 31 Oct 2016 08:54:18 +0800 Subject: [PATCH 1/2] Compatible old interface --- lib/detect-port.js | 6 +++--- package.json | 5 +++-- test/detect-port.test.js | 17 +++++++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/detect-port.js b/lib/detect-port.js index 3859484..9d3cbf9 100644 --- a/lib/detect-port.js +++ b/lib/detect-port.js @@ -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 => { diff --git a/package.json b/package.json index d0b03fb..d17922f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "detect-port", - "version": "1.0.4", + "version": "1.0.5", "description": "detect available port", "keywords": [ "detect", @@ -23,7 +23,8 @@ "jshint": "*", "mocha": "2.2.4", "pre-commit": "^1.1.3", - "should": "~6.0.3" + "should": "~6.0.3", + "startserver": "^1.3.1" }, "scripts": { "test": "make test", diff --git a/test/detect-port.test.js b/test/detect-port.test.js index 391e611..1f263e5 100644 --- a/test/detect-port.test.js +++ b/test/detect-port.test.js @@ -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(); }); }); @@ -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'); } From c11ca7ae47e86503b25b13266567417eb2a96f59 Mon Sep 17 00:00:00 2001 From: xudafeng Date: Mon, 31 Oct 2016 08:56:23 +0800 Subject: [PATCH 2/2] clean up deps --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index d17922f..889c7a6 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "jshint": "*", "mocha": "2.2.4", "pre-commit": "^1.1.3", - "should": "~6.0.3", - "startserver": "^1.3.1" + "should": "~6.0.3" }, "scripts": { "test": "make test",