1

我正在尝试改变内存中配置的值以进行测试,我尝试process.env.ALLOW_CONFIG_MUTATIONS=true在应用程序中添加几个位置,以及通过命令行和我的.env文件。

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)
}

谢谢!

4

1 回答 1

0

如果它是我使用的相同配置模块(我想我是),那么在你的测试配置中添加一个custom-environment-variables.jsOR 。test.js

test.js 需要一个ENV=test才能工作,而 custom-environment-variables 需要类似 (for Mac's and NPM) $ npm run funcTest->之类的东西yarn serverRunning && NODE_ENV=test wdio wdio.conf.js

JSON看起来像

{
  test: 'Value'
}
于 2018-06-27T20:59:26.390 回答