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

Allow direct access to os level environment variable #22523

Open
Songyu-Wang opened this issue Jun 25, 2022 · 2 comments
Open

Allow direct access to os level environment variable #22523

Songyu-Wang opened this issue Jun 25, 2022 · 2 comments
Labels
E2E Issue related to end-to-end testing topic: environment variables type: enhancement Requested enhancement of existing feature

Comments

@Songyu-Wang
Copy link
Contributor

What would you like?

I would like a way to directly look up os level environment variables without having to port them in one of the ways mentioned here https://docs.cypress.io/guides/guides/environment-variables#Setting

Why is this needed?

Currently, our team heavily relies on environment variables to figure out how the test script should behave. A few examples can be: branch tag, if print log, if dry run, if smoke test, testing env, test framework feature flag 1, test framework feature flag 2 and etc. As you can see, some of them are not necessarily cypress testing specific so we have to universally store them as os level environment variables so it is accessible for the whole thing. Everytime we add or change something, we have to find the cypress run -env VARIABLE=${VARIABLE:-default},VARIABLE=${VARIABLE:-default},VARIABLE=${VARIABLE:-default},VARIABLE=${VARIABLE:-default}...... and update it. The line to execute cypress is getting harder and harder to read and maintain. It would be just easier to directly access os env vars in the test script.

Other

Yes, we can absolutely work around it with example like https://stackoverflow.com/a/64773906, but it would be great to just have build in support for it

@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label Jun 27, 2022
@tbiethman
Copy link
Contributor

tbiethman commented Jun 29, 2022

@Songyu-Wang thanks for reaching out. I can route this enhancement request for follow-up with our functional teams.

I did want to point out that, as the Cypress config file is a JS file now, you have more options when it comes to setting Cypress-specific env in the config file:

// cypress.config.js
const { defineConfig } = require('cypress')

const cypressEnv = {}

if (process.env.USE_CASE_1) {
  cypressEnv.keyA = process.env.KEY_A
  cypressEnv.keyB = 'b'
} else if (process.env.USE_CASE_2) {
  cypressEnv.keyC = process.env.KEY_C
  cypressEnv.keyD = 'd'
}

module.exports = defineConfig({
  env: cypressEnv,
  e2e: {
    ...
  },
})

Doing it this way would be more flexible than chaining all the necessary values from the command line, and it might provide a nice abstraction from your OS-level values if there is ever a divergence.

@tbiethman tbiethman added type: enhancement Requested enhancement of existing feature topic: environment variables E2E-core and removed stage: investigating Someone from Cypress is looking into this labels Jun 29, 2022
@Songyu-Wang
Copy link
Contributor Author

Hello, @tbiethman yes, I understand this, but still, we have to port the envs using js instead of bash. It's the same procedure just in different code format. It doesn't really eliminate any intermediate steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing topic: environment variables type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

No branches or pull requests

5 participants