1

I'm trying to mutate the value of my config in memory for testing, I've tried adding process.env.ALLOW_CONFIG_MUTATIONS=true in several spots in the application, as well as through the command line and my .env file.

The config.util.getEnv('ALLOW_CONFIG_MUTATION') method always returns undefined.

I've also tried using importFresh and MockRequest as per examples I've seen online, neither of which allow me to mutate the config in memory, and then reset the value later.

Does anyone have any idea about this?

Update: here's an example of what I'm trying to accomplish

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

Thanks!

1 Answers1

0

If it is the same config module that I have used (I think I is) then add a custom-environment-variables.js OR test.js with you test config.

test.js will need an ENV=test to work and the custom-environment-variables need something like (for Mac's and NPM) $ npm run funcTest -> yarn serverRunning && NODE_ENV=test wdio wdio.conf.js.

the JSON will look something like

{
  test: 'Value'
}
MrPickles
  • 810
  • 1
  • 9
  • 27
  • Thanks for the response @MrPickles - I'm actually already using a test config, but I need to modify it's value mid test. I'll update my question with an example! – Quinn Langille Jun 28 '18 at 15:05
  • OK. I can't think of a time when config would change mid process, or if this is even possible. I am guessing you have found a way and therefor want to test it. if so ... (pause to thing) ... it may need a new test (`npm run test-config`) to get the desired effect. But as I said I can't think of a way to get in that state and unfortunately can't help :( at this time. but will have a think on it none the less. – MrPickles Jun 28 '18 at 21:07