Skip to content

Commit

Permalink
Merge pull request #322 from kgoerlitz/master
Browse files Browse the repository at this point in the history
Fix #321 - TypeError: Property description must be an object: undefined
  • Loading branch information
markstos committed May 18, 2016
2 parents 01138f2 + 06738d0 commit cd3080f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/config.js
Expand Up @@ -1417,7 +1417,10 @@ util.extendDeep = function(mergeInto) {

// Copy property descriptor otherwise, preserving accessors
else {
Object.defineProperty(mergeInto, prop, Object.getOwnPropertyDescriptor(Object(mergeFrom), prop));
var descriptor = Object.getOwnPropertyDescriptor(Object(mergeFrom), prop);
if (descriptor) {
Object.defineProperty(mergeInto, prop, descriptor);
}
}
}
});
Expand Down
46 changes: 46 additions & 0 deletions test/8-config-extending.js
@@ -0,0 +1,46 @@

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

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

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

// Test for multi-instance applications
delete process.env.NODE_APP_INSTANCE;

process.env.NODE_CONFIG_STRICT_MODE = false;

var CONFIG = requireUncached('../lib/config');


vows.describe('Tests for config extending')
.addBatch({
'Extending a base configuration with another configuration': {
'Extending a configuration with another configuration should work without error': function () {

process.env.NODE_CONFIG_DIR = __dirname + '/8-config';
var base_config = require(process.env.NODE_CONFIG_DIR + path.sep + 'base-config.json');
CONFIG.util.attachProtoDeep(base_config);

assert.doesNotThrow(function () {
result = CONFIG.util.extendDeep(base_config, CONFIG);
}, 'Extending a configuration with another configuration has an error');

}
}
})
.export(module);

//
// 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
function requireUncached(module) {
delete require.cache[require.resolve(module)];
return require(module);
}

4 changes: 4 additions & 0 deletions test/8-config/base-config.json
@@ -0,0 +1,4 @@
{
"testValue": "base configuration value",
"anotherValue": "Another value"
}
3 changes: 3 additions & 0 deletions test/8-config/default.json
@@ -0,0 +1,3 @@
{
"testValue": "override configuration value"
}

0 comments on commit cd3080f

Please sign in to comment.