React-starter-kit: How to set a different NODE_ENV?

Created on 6 Jan 2017  路  4Comments  路  Source: kriasoft/react-starter-kit

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?

question

All 4 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings