Component Testing, I cannot set the NODE_ENV=test
See original GitHub issueCurrent behavior
Currently, the NODE_ENV stays as development.
I tried:
- using --env NODE_ENV=test
- export NODE_ENV=test;
Desired behavior
A way to set NODE_ENV=test before cypress runs component tests.
Test code to reproduce
cypress open --component --browser chrome
export NODE_ENV=test; cypress open --component --browser chrome
NODE_ENV=test; cypress open --component --browser chrome
cypress open --component --browser chrome --env NODE_ENV=test
Cypress Version
10.1
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Jest + process.env.NODE_ENV not testing properly
In my test I want to test that if NODE_ENV is production, USE_DEV_TOOLS returns false however, if I try to change the NODE_ENV...
Read more >how to set node_env=test in node js Code Example
src/App.js Attempted import error: 'Switch' is not exported from 'react-router-dom'. ./src/components/Header/HeaderElements.js [1] Module not found: Can't ...
Read more >Configuring Jest
A list of paths to modules that run some code to configure or set up the testing environment. Each setupFile will be run...
Read more >Mock process.env In Your Cypress React Tests
How to mock the .env values in your Cypress end-to-end tests for React applications ... The App.js component uses these values in its...
Read more >Writing API Tests with Jest
So where do we set this NODE_ENV variable? Let's do that in our __tests__/students.test.js file! process.env.NODE_ENV = " ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! Please see the documentation on environment variables. You probably want
CYPRESS_NODE_ENV=test
? Then you can doCypress.env('NODE_ENV')
in your tests.A follow up question: are you trying to access
process.env.NODE_ENV
? There is this similar stack overflow question that might be useful: https://stackoverflow.com/questions/57818181/how-to-use-process-env-variables-in-browser-running-by-cypress.I don’t think there is a bug here, per-se, so I will close this, since I don’t see any actionable bug (yet). I will continue responding if you’ve got more questions (and re-open if we really do have a bug). Some more information about your use case (what are you testing) and stack (webpack, vite, react etc) would be helpful.
Interesting - potentially a bug in Cypress, or in the integration w/ msw… if you can post a minimal reproduction, I can take a look (know both msw and Cypress internals pretty well). Without more info, it’s difficult to advise.