[英]How to mutate node-config in memory
我正在尝试更改内存中配置的值以进行测试,我尝试在应用程序的多个位置以及通过命令行和我的.env
文件添加process.env.ALLOW_CONFIG_MUTATIONS=true
。
config.util.getEnv('ALLOW_CONFIG_MUTATION')
方法始终返回未定义。
我还尝试按照我在网上看到的示例使用importFresh
和MockRequest
,这两个示例都不允许我更改内存中的配置,然后在以后重置该值。
有人对此有任何想法吗?
更新 :这是我要完成的工作的一个示例
const config = require (config);
const app = new App(config)
it(`does a thing with base config`, () => { ... }
it('does a thing with modified config, () => {
// here i would need to modify my config value and
// have it change the original config that's currently in
// application memory
config = newConfig
expect(config.get('newValues')).to.equal(true)
}
谢谢!
如果它与我使用的配置模块相同(我想是),则在测试配置中添加一个custom-environment-variables.js
或test.js
test.js将需要一个ENV=test
才能工作,而自定义环境变量需要类似的东西(对于Mac和NPM) $ npm run funcTest
> yarn serverRunning && NODE_ENV=test wdio wdio.conf.js
JSON看起来像
{
test: 'Value'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.