cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

`CYPRESS_env` is a reserved environment variable name

Open gilzow opened this issue 1 year ago • 0 comments

Description

When I export CYPRESS_env, I expect that value to override the env:env value set in the config file, but nothing happened instead.

URL of Issue(s)

https://docs.cypress.io/guides/guides/environment-variables

Steps to replicate

  1. In your terminal: export CYPRESS_env=development
  2. In your cypress.config.js file:
    env: {
      barfoo: "from config",
      env: "local",
    },
  1. In a testing file, add
console.log('Env is ' + Cypress.env('env'))
  1. Run the test

Output will be

Env is local

Where I would expect it to be

Env is development

Browser

Chrome 125.0.6422.113

Device

  • [X] PC
  • [X] Mac
  • [ ] iPhone
  • [ ] iPad
  • [ ] Android Phone
  • [ ] Android Tablet

Additional Information

Given the documentation on Environment Variable states:

Environment variables that match a corresponding configuration option will override any value set in the Cypress configuration.

And the note above that section states:

The environment variable CYPRESS_INTERNAL_ENV is reserved and should not be set.

I was surprised when I was unable to get CYPRESS_env to override the env:env value I had set in the cypress.config.js file (specifically so I can set some intercepts when testing locally vs testing in our development instance). I initially thought it was a bug with Cypress (and submitted an issue) but according to @jennifer-shehane :

CYPRESS_env accepts an object as its argument, to override the entire env object. [emphasis mine]

This behavior needs to be documented possibly with a note alongside the one for CYPRESS_INTERNAL_ENV.

gilzow avatar Jun 21 '24 18:06 gilzow