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.

e2e tests not reading .local.env file.

See original GitHub issue

Current Behaviour

When I run a react app with @nrwl/web:dev-server, .local.env is loaded, as described here: https://nx.dev/angular/cli/overview#loading-environment-variables

When I run the e2e tests created by the react plugin, the variables are undefined.

Expected Behavior

The e2e version of the front end app should have the variables available.

Steps to Reproduce

Setup an app similar to the react tutorial.

Add a .local.env, with some values that begin with NX_. Console.log those values on app start.

Failure Logs

No failure logs

Environment

➜ yarn nx --version        
yarn run v1.22.4
$ nx --version
9.4.5

➜ node --version                              
v13.14.0
➜ cat /etc/lsb-release                     
DISTRIB_ID=Pop
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Pop!_OS 20.04 LTS"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
cereallarcenycommented, Dec 30, 2020

Update 30/12/20

We’ve now determined that Cypress will load environment variables in the correct order, and NOT overwrite them in subsequent .env files, but ONLY if both environment variable files are placed in the appropriate app folder. In other words, if you have .local.env and .env in the root of your project, you’re going to have problems. If you place those files inside the app that you’re running e2e against, it works as expected.

We would love some clarification on whether this is intentional or not - it still doesn’t seem to be the expected behavior.

4reactions
vsavkincommented, Jul 9, 2020

@Cammisuli @jaysoo we should probably add the same feature to the cypress builder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to read environment files from e2e tests? - Stack Overflow
I'm using Cypress for the e2e tests. For instance, I want to use the base URL, so that it depends on the environment...
Read more >
Environment Variables | Cypress Documentation
In Cypress, "environment variables" are variables that are accessible via Cypress.env . These are not the same as OS-level environment variables.
Read more >
How to create dynamic E2E testing environments | by Shai Tubul
Configuring and deploying an environment. We defined YAML files that describe the E2E test environments, so each YAML file describes one environment as...
Read more >
Cypress v10 Environment Variables - Gleb Bahmutov
We see only the environment variables from the e2e block. ... we can access the process environment variables, or read local files, etc....
Read more >
Run your Cypress suites across environments reusing the ...
Now, for you to execute your e2e tests across environments there would ... in the .env files. eg below is the .env file...
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