I am trying to set process.env.NODE_ENV to "test" when I run my tests.
I make use of it when I'm logging.
In the test/setup.js I set NODE_ENV like this:
process.env.NODE_ENV = 'test';
And I run the tests using npm run integration-test:
"integration-test": "npm run build && mocha \"test/**/*.test.js\" --require test/setup.js --require babel-register --timeout 30000"
I logged the NODE_ENV in server.js and it says it is "development".
After digging for a while, I have configured it is set in the webpack config file
...
new webpack.DefinePlugin({
'process.env.NODE_ENV': isDebug ? '"development"' : '"production"',
'process.env.BROWSER': false,
__DEV__: isDebug,
}),
...
What is the best way to change the NODE_ENV without messing around in the webpack config file?
How can I set it to be "test" when I execute my integration tests?
@itaied246 First glance, think something like this would work (off the top of my head, have not checked)..
...
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"` || (isDebug ? '"development"' : '"production"'),
'process.env.BROWSER': false,
__DEV__: isDebug,
}),
...
Then do:
NODE_ENV=test npm start
If the NODE_ENV is specified then that will be used, otherwise default logic is used.
It is still actual @itaied246?
/cc @koistya @frenzzy
No, I figured it out.
Since the integration tests I was writing required building the app, I had to modify the NODE_ENV parameter in the webpack config.