From b9321b200a6d5ceb5941f1b25e8a290028353fbf Mon Sep 17 00:00:00 2001 From: Adrien Becchis Date: Sat, 4 Nov 2017 04:22:13 +0100 Subject: [PATCH] transformer can now return an undefined key (#289) --- lib/nconf/common.js | 2 +- test/complete-test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/nconf/common.js b/lib/nconf/common.js index 9aa69ee..0adcf01 100644 --- a/lib/nconf/common.js +++ b/lib/nconf/common.js @@ -154,7 +154,7 @@ common.transform = function(map, fn) { if (!result) { return null; - } else if (result.key && typeof result.value !== 'undefined') { + } else if (result.key) { return result; } diff --git a/test/complete-test.js b/test/complete-test.js index 0245fdf..d1f9462 100644 --- a/test/complete-test.js +++ b/test/complete-test.js @@ -242,6 +242,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 return an undefined value": { + topic: function () { + + function testTransform(obj) { + if (obj.key === 'FOO') { + return {key: 'FOO', value: undefined}; + } + + 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