Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting process.env to empty object #5042

Closed
amitguptagwl opened this issue Aug 27, 2019 · 9 comments
Closed

setting process.env to empty object #5042

amitguptagwl opened this issue Aug 27, 2019 · 9 comments

Comments

@amitguptagwl
Copy link

Current behavior:

cy.log( "Environment: " + JSON.stringify(process.env,null,4)  );

output in browser console

Environment: {}

Desired behavior:

It should not mutate/empty the process.env.

Versions

OS: Ubuntu 18
Cypress: 3.4.1

@jennifer-shehane
Copy link
Member

Could you please provide what the process.env value is here normally?

console.log(process.env) // <-- what does this print to console?

cy.log( "Environment: " + JSON.stringify(process.env,null,4)  );

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Aug 27, 2019
@amitguptagwl
Copy link
Author

amitguptagwl commented Aug 28, 2019

Not sure why but console.log doesn't work in case of cypress. I thought Cypress is overriding it.

@mpahuja
Copy link

mpahuja commented Aug 28, 2019

@amitguptagwl it should be logging to the browser console when you run the tests.
use cypress open to open cypress in interactive mode, run the test and open browser console to see the log you added above.

@amitguptagwl
Copy link
Author

Thanks @mpahuja .

@jennifer-shehane
It is {} in both case.

@mpahuja
Copy link

mpahuja commented Aug 30, 2019

i am assuming you have read this? https://docs.cypress.io/guides/guides/environment-variables.html#Setting

@amitguptagwl
Copy link
Author

@mpahuja Yes, I did. My question is about why process.env is empty? Because currently, I need to make multiple tasks to pass the correct environment variables to run my tests in a different environment. On top of that, I have the tasks to run the tests for the different user journey. They again need to be duplicated per environment.

@jennifer-shehane
Copy link
Member

Cypress is run in the browser environment, so there will is no access to Node in the browser nor Node's process.env within the spec files.

You can access Node, such as process.env within the support/index.js or plugins/index.js files however for use of any setup you require.

@jennifer-shehane jennifer-shehane removed the stage: needs information Not enough info to reproduce the issue label Jan 7, 2020
@dandv
Copy link

dandv commented Jun 26, 2020

Impressive that Cypress supports 5 or 6 ways of setting environment variables, but surprising that the uber-popular dotenv is not one of them.

There's a plugin for dotenv, but I've wasted the last hour trying to get it to work, to no avail.

@morficus
Copy link

morficus commented Jul 4, 2020

@dandv are you still having issues getting the plugin to work?
I've tested it using Cypress 4.9 and didn't see any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants