Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/detect-port.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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