ac-node
Version:
A common module for building Atlassian Connect add-ons
78 lines (65 loc) • 1.96 kB
JavaScript
var assert = require('assert');
var Config = require('..').Config;
var os = require('os');
var hostname = os.hostname().toLowerCase();
describe('ac config', function () {
describe('created with no options', function () {
var config = Config();
it('should return defaults', function () {
assert.equal(config.HOSTNAME, hostname);
assert.equal(config.PORT, 3000);
assert.equal(config.LOCAL_BASE_URL, 'http://' + hostname + ':3000');
});
});
describe('created in dev mode', function () {
var config = Config({
development: {
port: 4000
},
production: {
port: -1
}
}, {
NODE_ENV: 'development'
});
it('should return development values or defaults', function () {
assert.equal(config.HOSTNAME, hostname);
assert.equal(config.PORT, 4000);
assert.equal(config.LOCAL_BASE_URL, 'http://' + hostname + ':4000');
});
});
describe('created in prod mode', function () {
var config = Config({
development: {
localBaseUrl: 'fail'
},
production: {
localBaseUrl: 'https://example.com'
}
}, {
NODE_ENV: 'production'
});
it('should return production values or defaults', function () {
assert.equal(config.HOSTNAME, hostname);
assert.equal(config.PORT, 3000);
assert.equal(config.LOCAL_BASE_URL, 'https://example.com');
});
});
describe('created in any mode', function () {
var config = Config({
development: {
port: -1,
localBaseUrl: 'https://example.com:$PORT'
}
}, {
PORT: 1234
});
it('should override values with those from the env arg (which defaults to process.env)', function () {
assert.equal(config.PORT, 1234);
assert.equal(config.LOCAL_BASE_URL, 'https://example.com:1234');
});
});
// TODO:
// - test defaulting to dev mode
// - explicitly test string var replacements
});