Skip to content

Better handle reserved key CYPRESS_ENV being set by users to valid values#6437

Merged
jennifer-shehane merged 12 commits into
developfrom
issue-6436-warn-cypress-env
Mar 6, 2020
Merged

Better handle reserved key CYPRESS_ENV being set by users to valid values#6437
jennifer-shehane merged 12 commits into
developfrom
issue-6436-warn-cypress-env

Conversation

@jennifer-shehane
Copy link
Copy Markdown
Member

@jennifer-shehane jennifer-shehane commented Feb 13, 2020

User facing changelog

  • We now warn when setting the reserved key CYPRESS_INTERNAL_ENV to a non-production value.

Additional details

  • I've renamed the CYPRESS_ENV variable to CYPRESS_INTERNAL_ENV. The use of this keyword is not frequent, but the consequences of accidentally setting it are complete blocker for users trying to record and it a real headache to debug from within support.
  • We were previously only erroring and exiting on invalid values, but a user could pass valid, non-production values that would result in unexpected consequences. We now warn in this situation so they would at least get some indication that they did something wrong.
  • The check for 'non-production' values includes a check for undefined which will set our default and I don't suspect anyone would set 'undefined' anyway.

See https://github.com/cypress-io/cypress-services/issues/2194

How has the user experience changed?

Before: Can't find projectID

The most optimistic error is that it can't find the projectId (because the project doesn't exist in staging) - this results in a string of emails to support because their project definitely exists!

$ CYPRESS_ENV=staging cypress run --record --key abc123
We could not find a project with the ID: f0paa2

This projectId came from your 'cypress.json' file or an environment variable.

Please log into the Dashboard and find your project.

We will list the correct projectId in the 'Settings' tab.

Alternatively, you can create a new project using the Desktop Application.

https://on.cypress.io/dashboard

Before: recording to staging db 😬

If their project is found, it could just record to staging - this results in a string of emails to support because they see it recording but do not see the recordings in their Dashboard!

$ CYPRESS_ENV=staging cypress run --record --key abc123

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.8.3                                                                              │
  │ Browser:    Electron 78 (headless)                                                             │
  │ Specs:      1 found (api_spec.js)  
  │ Params:     Tag: false, Group: false, Parallel: false                                          │
  │ Run URL:    https://dashboard-staging.cypress.io/projects/123456/runs/3777                     │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

After:

The CYPRESS_ENV is now `CYPRESS_INTERNAL_ENV, which is less likely to be set by users for their own use.

After: Warning when setting to not production or undefined

$ CYPRESS_INTERNAL_ENV=staging cypress run --record --key abc123

⚠ Warning: It looks like you're passing CYPRESS_INTERNAL_ENV=staging

The environment variable "CYPRESS_INTERNAL_ENV" is reserved and should only be used internally.

Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.

PR Tasks

@cypress-bot
Copy link
Copy Markdown
Contributor

cypress-bot Bot commented Feb 13, 2020

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@cypress
Copy link
Copy Markdown

cypress Bot commented Feb 13, 2020



Test summary

6966 0 97 0


Run details

Project cypress
Status Passed
Commit e96ab04
Started Mar 6, 2020 9:09 AM
Ended Mar 6, 2020 9:15 AM
Duration 05:38 💡
OS Linux Debian - 10.0
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@jennifer-shehane jennifer-shehane changed the title Add warning when setting CYPRESS_ENV to non-production value [WIP] Add warning when setting CYPRESS_ENV to non-production value Feb 13, 2020
@jennifer-shehane jennifer-shehane changed the title [WIP] Add warning when setting CYPRESS_ENV to non-production value [WIP] Rename CYPRESS_ENV to CYPRESS_INTERNAL_ENV + Add warning when setting CYPRESS_INTERNAL_ENV to non-production value Mar 4, 2020
@jennifer-shehane jennifer-shehane changed the title [WIP] Rename CYPRESS_ENV to CYPRESS_INTERNAL_ENV + Add warning when setting CYPRESS_INTERNAL_ENV to non-production value [WIP] Better handle CYPRESS_ENV being set to staging Mar 4, 2020
@jennifer-shehane jennifer-shehane changed the title [WIP] Better handle CYPRESS_ENV being set to staging Better handle CYPRESS_ENV being set to staging Mar 4, 2020
@jennifer-shehane jennifer-shehane requested review from a team, brian-mann and kuceb and removed request for a team March 4, 2020 07:27
@jennifer-shehane jennifer-shehane changed the title Better handle CYPRESS_ENV being set to staging Better handle reserved key CYPRESS_ENV being set by users to valid values Mar 4, 2020
@jennifer-shehane jennifer-shehane requested review from bahmutov and removed request for kuceb March 5, 2020 05:42
Comment thread cli/lib/cli.js Outdated

if (!util.isValidCypressEnvValue(process.env.CYPRESS_ENV)) {
debug('invalid CYPRESS_ENV value', process.env.CYPRESS_ENV)
const CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to avoid repetition

const {CYPRESS_INTERNAL_ENV} = process.env

bahmutov
bahmutov previously approved these changes Mar 5, 2020
Copy link
Copy Markdown
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, will avoid the unnecessary confusion

@jennifer-shehane jennifer-shehane deleted the issue-6436-warn-cypress-env branch August 28, 2025 13:09
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

Successfully merging this pull request may close these issues.

Warn when using reserved key CYPRESS_ENV with non production value

2 participants