Merge pull request #126 from strongloop/fix/number-isFinite

executor: fix port lookup
This commit is contained in:
Miroslav Bajtoš 2015-04-23 09:26:29 +02:00
commit c3bbc13fd8
2 changed files with 25 additions and 17 deletions

View File

@ -115,9 +115,7 @@ function setPort(app, instructions) {
process.env.npm_package_config_port,
app.get('port'),
3000
], function isNumberLike(v) {
return Number.isFinite(parseInt(v, 10));
});
], isFinite);
if (port !== undefined) {
var portType = typeof port;

View File

@ -294,6 +294,21 @@ describe('executor', function() {
});
describe('with PaaS and npm env variables', function() {
beforeEach(function cleanEnvironment() {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
delete process.env.npm_config_host;
delete process.env.OPENSHIFT_SLS_IP;
delete process.env.OPENSHIFT_NODEJS_IP;
delete process.env.HOST;
delete process.env.npm_package_config_host;
delete process.env.npm_config_port;
delete process.env.OPENSHIFT_SLS_PORT;
delete process.env.OPENSHIFT_NODEJS_PORT;
delete process.env.PORT;
delete process.env.npm_package_config_port;
});
function bootWithDefaults() {
app = loopback();
boot.execute(app, someInstructions({
@ -322,7 +337,7 @@ describe('executor', function() {
assertHonored('PORT', 'HOST');
});
it('should prioritize sources', function() {
it('should prioritize host sources', function() {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
process.env.npm_config_host = randomHost();
process.env.OPENSHIFT_SLS_IP = randomHost();
@ -332,13 +347,9 @@ describe('executor', function() {
bootWithDefaults();
assert.equal(app.get('host'), process.env.npm_config_host);
});
delete process.env.npm_config_host;
delete process.env.OPENSHIFT_SLS_IP;
delete process.env.OPENSHIFT_NODEJS_IP;
delete process.env.HOST;
delete process.env.npm_package_config_host;
it('should prioritize port sources', function() {
process.env.npm_config_port = randomPort();
process.env.OPENSHIFT_SLS_PORT = randomPort();
process.env.OPENSHIFT_NODEJS_PORT = randomPort();
@ -346,14 +357,7 @@ describe('executor', function() {
process.env.npm_package_config_port = randomPort();
bootWithDefaults();
assert.equal(app.get('host'), process.env.npm_config_host);
assert.equal(app.get('port'), process.env.npm_config_port);
delete process.env.npm_config_port;
delete process.env.OPENSHIFT_SLS_PORT;
delete process.env.OPENSHIFT_NODEJS_PORT;
delete process.env.PORT;
delete process.env.npm_package_config_port;
});
function randomHost() {
@ -373,6 +377,12 @@ describe('executor', function() {
boot.execute(app, someInstructions({ config: { port: undefined } }));
assert.equal(app.get('port'), 3000);
});
it('should ignore non-numeric port values in ENV', function() {
process.env.PORT = '123invalid';
boot.execute(app, someInstructions({ config: { port: 3000 } }));
assert.equal(app.get('port'), 3000);
});
});
it('calls function exported by boot/init.js', function() {