Skip to content

Commit

Permalink
Merge pull request #169 from markstos/bump-cson-dep
Browse files Browse the repository at this point in the history
Bump cson dep to try to fix travis builds.
  • Loading branch information
lorenwest committed Nov 14, 2014
2 parents 06ad80a + 1a4e685 commit 68e8485
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 8 deletions.
14 changes: 13 additions & 1 deletion History.md
@@ -1,7 +1,19 @@

1.8.1 / 2014-11-14
==================

* Simplify syntax for defer() functions. The 'this' value in the functions is now bound
to the main configuration object, so it doesn't have to be passed into the function. (@markstos)
* new defer sub-module introduced in 1.8.0 can now be accessed by require('config/defer')
For usage, see: https://github.com/lorenwest/node-config/wiki/Configuration-Files#javascript-module---js
* Add test coverage for array merging cases. (@markstos)
* Bump dependency on cson package to 1.6.1 (@markstos)

1.8.0 / 2014-11-13
==================

* Added deferred function for evaluating configs after load
* Added deferred function for evaluating configs after load (@markstos)
For details, see: https://github.com/lorenwest/node-config/wiki/Configuration-Files#javascript-module---js
* Bumped js-yaml dependency (@markstos)

1.7.0 / 2014-10-30
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions lib/config.js
Expand Up @@ -10,8 +10,8 @@ var Yaml = null, // External libraries are lazy-loaded
CSON = null,
PPARSER = null,
JSON5 = null,
deferConfig = require('./config/defer').deferConfig,
DeferredConfig = require('./config/defer').DeferredConfig,
deferConfig = require('../defer').deferConfig,
DeferredConfig = require('../defer').DeferredConfig,
Utils = require('util'),
FileSystem = require('fs');

Expand Down Expand Up @@ -724,7 +724,7 @@ util.resolveDeferredConfigs = function (config) {
}
} else {
if (prop[property] instanceof DeferredConfig ) {
prop[property]= prop[property].resolve(completeConfig)
prop[property]= prop[property].resolve.call(completeConfig,completeConfig)
}
else {
// Nothing to do. Keep the property how it is.
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "config",
"version": "1.8.0",
"version": "1.8.1",
"main": "./lib/config.js",
"description": "Configuration control for production node deployments",
"author": "Loren West <open_source@lorenwest.com>",
Expand All @@ -23,7 +23,7 @@
"dependencies": {},
"devDependencies": {
"coffee-script": ">=1.7.0",
"cson": "~1.4.0",
"cson": "^1.6.1",
"js-yaml": "^3.2.2",
"json5": "~0.2.0",
"properties": "~1.2.1",
Expand Down
6 changes: 6 additions & 0 deletions test/3-deferred-configs.js
Expand Up @@ -39,6 +39,12 @@ exports.DeferredTest = vows.describe('Tests for deferred values').addBatch({
// If this had been treated as a deferred config value it would blow-up.
assert.equal(CONFIG.welcomeEmail.aFunc(), 'Still just a function.');
},

// This defer function didn't use args, but relied 'this' being bound to the main config object
"defer functions can simply refer to 'this'" : function () {
assert.equal(CONFIG.welcomeEmail.justThis, 'Welcome to this New Instance!');
}

}
});

Expand Down
51 changes: 51 additions & 0 deletions test/4-array-merging.js
@@ -0,0 +1,51 @@

// Test declaring deferred values.
// The key config files involved here are:
// test/config/default-array-merge.js
// test/config/local-array-merge.js


// Change the configuration directory for testing
process.env.NODE_CONFIG_DIR = __dirname + '/config';

// Hardcode $NODE_ENV=test for testing
process.env.NODE_ENV='test';

// Test for multi-instance applications
process.env.NODE_APP_INSTANCE='array-merge';

// Because require'ing config creates and caches a global singleton,
// We have to invalidate the cache to build new object based on the environment variables above
var CONFIG = requireUncached('../lib/config');

// Dependencies
var vows = require('vows'),
assert = require('assert');

exports.DeferredTest = vows.describe('Tests for merging arrays').addBatch({
'Array merging tests Tests': {
topic: function() {
return CONFIG;
},

'An empty array replaced by a full array should be replaced': function() {
console.dir(CONFIG.arrayMerging);
assert.deepEqual(CONFIG.arrayMerging.emptyArray, ['not empty anymore']);
},

'An array with one value should be replaced wholeshole': function() {
assert.deepEqual(CONFIG.arrayMerging.oneItem, ['replaced']);
},

"An array replaced by an empty array should be replaced wholesale" : function () {
assert.deepEqual(CONFIG.arrayMerging.removeMe, []);
}

}
});


function requireUncached(module){
delete require.cache[require.resolve(module)];
return require(module);
}
12 changes: 12 additions & 0 deletions test/config/default-array-merge.js
@@ -0,0 +1,12 @@

var defer = require('../../defer').deferConfig;

var config = {
arrayMerging: {
emptyArray : [],
oneItem : ['one'],
removeMe : ['some value'],
},
};

module.exports = config;
10 changes: 8 additions & 2 deletions test/config/default-defer.js
@@ -1,5 +1,5 @@

var defer = require('../../lib/config/defer').deferConfig;
var defer = require('../../defer').deferConfig;

var config = {
siteTitle : 'Site title',
Expand All @@ -15,7 +15,13 @@ config.welcomeEmail = {
// A plain function should be not disturbed.
aFunc : function () {
return "Still just a function.";
}
},

// Look ma, no arg passing. The main config object is bound to 'this'
justThis: defer(function () {
return "Welcome to this "+this.siteTitle;
}),

};

module.exports = config;
10 changes: 10 additions & 0 deletions test/config/local-array-merge.js
@@ -0,0 +1,10 @@

var config = {
arrayMerging: {
emptyArray : ['not empty anymore'], // override empty array with a value
oneItem : ['replaced'], // Replace one item with another.
removeMe : [], // Replace a full array with an empty one
},
};

module.exports = config;

0 comments on commit 68e8485

Please sign in to comment.