Node-config's custom-environment-variables.json doesn't seem to be overriding values in default.json when NODE_ENV is set to 'test.' Here's an extremely simple config:
config/default.json:
{
"jwtPrivateKey": "defaultkey"
}
config/custom-environment-variables.json:
{
"jwtPrivateKey": "JWTPRIVATEKEY"
}
config/test.json:
{}
app.js:
console.log('NODE_ENV': + process.env.NODE_ENV);
console.log('Env: ' + process.env.JWTPRIVATEKEY);
console.log("Config: " + config.get('jwtPrivateKey'));
This works as expected: I get NODE_ENV=undefined (so node-config will default to 'development'), & the next two lines both print the correct value set in the environment variable. However, if I try to run a simple test with Jest & print the same:
tests/some.test.js:
test('Some Test', () => {
console.log('NODE_ENV:' + process.env.NODE_ENV);
console.log('Env: ' + process.env.JWTPRIVATEKEY);
console.log("Config: " + config.get('jwtPrivateKey'));
});
I get NODE_ENV=test, Env=the correct value set in the environment variable...but Config=defaultKey.
In other words: although it shows that the environment variable is set to the right value, node-config doesn't seem to be pulling it in through custom-environment-variables.json.
Is this a bug? I've scoured the documentation but been unable to find any reason for this discrepancy.