E2E tests with Cypress do not use .env.test for env variables
See original GitHub issueVersion
3.0.0-beta.9
Reproduction link
https://github.com/lowski/fakturownia/tree/managing-clients - it’s an app that I use for testing different techniques for Vue.js app but setup is the default one, created by Vue-cli.
Steps to reproduce
- Create .env.test file with some env variable, i.e:
VUE_APP_API_URL=http://localhost:8081
- Try to reference that variable inside any of your client-side JavaScript files, i.e.:
console.log(process.env.VUE_APP_API_URL)
What is expected?
It is expected to print http://localhost:8081
when tests are run with Cypress
What is actually happening?
It’s printing undefined
I tried to pass --mode test
to e2e
command like this:
vue-cli-service test:e2e --mode test
But it throws error that HMR is disabled and test does not run.
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (14 by maintainers)
Top Results From Across the Web
Environment Variables | Cypress Documentation
When your tests are running, you can use the Cypress.env function to access the values of your environment variables. Option #1: configuration file....
Read more >How To Inject Environment Variables Into Cypress Tests
Cypress automatically reads all environment variables that start with CYPRESS_ prefix and makes them available in Cypress.env() object. 1 2 3
Read more >Environment Variables in Cypress End-to-End Testing
We often need to write end-to-end (e2e) tests to verify processes requesting secured resources, which demand appropriate credentials.
Read more >Specify environment variables for Cypress tests - BrowserStack
Any key/value you set in your Cypress configuration file ( cypress.json by default) under the env key will become an environment variable that...
Read more >Environment Variables in Cypress - Tools QA
Here, all the key-value pairs defined under the "env" will be considered as environment variables and can be accessed directly in the Cypress...
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
from the docs of that plugin:
From https://github.com/vuejs/vue-cli/blob/dev/docs/env.md#modes
So you can either provide a
.env.production
file, or, if you rather want to use a different mode, do this:The important part is to set NODE_ENV to production so the backend config is setup like a production build, while the environment variables can be different.
It’s still a issue, .env variables are not shared to Cypress.env nor process.env inside e2e tests. Duplicating .env content to cypress.json does not seem to be a good solution IMHO