fix error in transform function when dealing with dropped entries (#287)
This commit is contained in:
parent
9f70ba148f
commit
b1ee63cfa4
2 changed files with 36 additions and 4 deletions
|
@ -164,7 +164,11 @@ common.transform = function(map, fn) {
|
|||
});
|
||||
|
||||
|
||||
return pairs.reduce(function(accumulator, pair) {
|
||||
return pairs
|
||||
.filter(function(pair) {
|
||||
return pair !== null;
|
||||
})
|
||||
.reduce(function(accumulator, pair) {
|
||||
accumulator[pair.key] = pair.value;
|
||||
return accumulator;
|
||||
}, {});
|
||||
|
|
|
@ -214,6 +214,34 @@ vows.describe('nconf/multiple-stores').addBatch({
|
|||
teardown: function () {
|
||||
nconf.remove('env');
|
||||
}
|
||||
}).addBatch({
|
||||
// Threw this in it's own batch to make sure it's run separately from the
|
||||
// sync check
|
||||
"When using env with a transform:fn that drops an entry": {
|
||||
topic: function () {
|
||||
|
||||
function testTransform(obj) {
|
||||
if (obj.key === 'FOO') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
var that = this;
|
||||
helpers.cp(complete, completeTest, function () {
|
||||
nconf.env({ transform: testTransform });
|
||||
that.callback();
|
||||
});
|
||||
}, "env vars": {
|
||||
"port key/value properly transformed": function() {
|
||||
assert.equal(typeof nconf.get('FOO'), 'undefined');
|
||||
}
|
||||
}
|
||||
},
|
||||
teardown: function () {
|
||||
nconf.remove('env');
|
||||
}
|
||||
}).addBatch({
|
||||
// Threw this in it's own batch to make sure it's run separately from the
|
||||
// sync check
|
||||
|
|
Loading…
Reference in a new issue