Skip to content

Commit aeb772a

Browse files
TomChantleracburdine
authored andcommitted
fix(config): ensure port number is treated as an integer (#452)
closes #451 - ensure port number is treated as an integer so portfinder increments it correctly - update tests to reflect new behavior
1 parent b348105 commit aeb772a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/commands/config/advanced.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const includes = require('lodash/includes');
66
const validator = require('validator');
77
const url = require('url');
88

9-
const BASE_PORT = '2368';
9+
const BASE_PORT = 2368;
1010
const knownMailServices = [
1111
'aol', 'dynectemail', 'fastmail', 'gmail', 'godaddy', 'godaddyasia', 'godaddyeurope', 'hot.ee', 'hotmail', 'icloud',
1212
'mail.ee', 'mail.ru', 'mailgun', 'mailjet', 'mandrill', 'postmark', 'qq', 'qqex', 'sendgrid',
@@ -47,12 +47,12 @@ module.exports = {
4747
return 'Port must be an integer.';
4848
}
4949

50-
return portfinder.getPortPromise({port: value}).then((port) => {
51-
return (port === value) || `Port '${value}' is in use.`;
50+
return portfinder.getPortPromise({port: parseInt(value)}).then((port) => {
51+
return (parseInt(port) === parseInt(value)) || `Port '${value}' is in use.`;
5252
});
5353
},
5454
defaultValue: config => {
55-
let port = url.parse(config.get('url')).port || BASE_PORT;
55+
let port = parseInt(url.parse(config.get('url')).port || BASE_PORT);
5656
return portfinder.getPortPromise({port: port});
5757
},
5858
default: 2368,

test/unit/commands/config-spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ describe('Unit: Command > Config', function () {
401401
expect(results.validateExpectsTrue).to.be.true;
402402
expect(results.validateExpectsMessage).to.match(/'2366' is in use/);
403403

404-
expect(portPromiseStub.calledWithExactly({ port: '2366' })).to.be.true;
405-
expect(portPromiseStub.calledWithExactly({ port: '2367' })).to.be.true;
406-
expect(portPromiseStub.calledWithExactly({ port: '2368' })).to.be.true;
407-
expect(portPromiseStub.calledWithExactly({ port: '2369' })).to.be.true;
404+
expect(portPromiseStub.calledWithExactly({ port: 2366 })).to.be.true;
405+
expect(portPromiseStub.calledWithExactly({ port: 2367 })).to.be.true;
406+
expect(portPromiseStub.calledWithExactly({ port: 2368 })).to.be.true;
407+
expect(portPromiseStub.calledWithExactly({ port: 2369 })).to.be.true;
408408
});
409409
});
410410
});

0 commit comments

Comments
 (0)