question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component Testing, I cannot set the NODE_ENV=test

See original GitHub issue

Current behavior

Currently, the NODE_ENV stays as development.

I tried:

  1. using --env NODE_ENV=test
  2. 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:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lmiller1990commented, Jun 13, 2022

Hi! Please see the documentation on environment variables. You probably want CYPRESS_NODE_ENV=test? Then you can do Cypress.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.

0reactions
lmiller1990commented, Jun 14, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found