I am adding some config values before hapi server start. Application is works fine although in test I can not use config.get(). I can get around with proxyquire. So I was wondering
- Is adding config file "dynamically" is bad design?
- Is there a way I can use config.get() in such suitation?
Any alternative approach?
//initialize.js const config = require('config'); async function startServe() { const someConfigVal = await callAPIToGetSomeJSONObject(); config.dynamicValue = someConfigVal; server.start(); } //doSomething.js const config = require('config'); function doesWork() { const valFromConfig = config.dynamicValue.X; // In test I can use proxiquire by creating config object ... } function doesNotWork() { const valFromConfig = config.get('dynamicValue.X'); // Does not work with sinon mocking as this value does not exist in config when test run. // sinon.stub(config, 'get').withArgs('dynamicValue.X').returns(someVal); ..... }