From 3c11ef50e522cd32991d8a087df576ee80cc0d8f Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Tue, 4 Aug 2015 17:54:59 +0100 Subject: [PATCH] fix: env.match test The previous test was expecting the .match value to be a function rather than a regexp which is what the README shows. So I've fixed the code to match against a real regexp, and test if the stringified version of the regexp function is [object RegExp]. I've also updated the tests to prime the process.env with values that are specifically tested for to ensure it's correctly loading the env values. Fixex indexzero/nconf#178 --- lib/nconf/stores/env.js | 2 +- test/complete-test.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/nconf/stores/env.js b/lib/nconf/stores/env.js index aa775f3..2d921de 100644 --- a/lib/nconf/stores/env.js +++ b/lib/nconf/stores/env.js @@ -24,7 +24,7 @@ var Env = exports.Env = function (options) { this.whitelist = options.whitelist || []; this.separator = options.separator || ''; - if (typeof options.match === 'function' + if (({}).toString.call(options.match) === '[object RegExp]' && typeof options !== 'string') { this.match = options.match; } diff --git a/test/complete-test.js b/test/complete-test.js index 70ad31c..8a90092 100644 --- a/test/complete-test.js +++ b/test/complete-test.js @@ -16,12 +16,23 @@ var fs = require('fs'), var completeTest = helpers.fixture('complete-test.json'), complete = helpers.fixture('complete.json'); +// prime the process.env +process.env['NCONF_foo'] = 'bar'; +process.env.FOO = 'bar'; +process.env.BAR = 'zalgo'; +process.env.NODE_ENV = 'debug'; +process.env.FOOBAR = 'should not load'; + vows.describe('nconf/multiple-stores').addBatch({ "When using the nconf with multiple providers": { topic: function () { var that = this; helpers.cp(complete, completeTest, function () { - nconf.env(); + nconf.env({ + // separator: '__', + match: /^NCONF_/, + whitelist: ['NODE_ENV', 'FOO', 'BAR'] + }); nconf.file({ file: completeTest }); nconf.use('argv', { type: 'literal', store: data }); that.callback(); @@ -34,7 +45,7 @@ vows.describe('nconf/multiple-stores').addBatch({ }, "env vars": { "are present": function () { - Object.keys(process.env).forEach(function (key) { + ['NODE_ENV', 'FOO', 'BAR', 'NCONF_foo'].forEach(function (key) { assert.equal(nconf.get(key), process.env[key]); }); }