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 environment-variables deep merging from "cypress.env.json" and system variables #29008

Open
LazaroOnline opened this issue Feb 26, 2024 · 0 comments
Labels
stage: proposal 💡 No work has been done of this issue type: feature New feature that does not currently exist

Comments

@LazaroOnline
Copy link
Contributor

LazaroOnline commented Feb 26, 2024

What would you like?

Allow deep merging of cypress.env.json, that is:

for a cypress.env.json with:

{
  "p1": 1,
  "p2": { "a": 1, "b": 2 }
}

and a cypress.config.js with:

env: {
  p2: { b: 0, c: 3 }
}

The current result is: (p2.a will be lost)

{
  p1: 1,
  p2: { b: 0, c: 3 }
}

But would be better if it did a deep merge like the one from lodash:
Cypress._.merge(envFromCypressConfigJs, envFromCypressEnvJson)

{
  p1: 1,
  p2: { a:1, b: 0, c: 3 }
}

Then for system environment variables to also support modifying a nested value without replacing the whole root object,
it can be done by passing a JSON string and using the same merging logic as lodash merge,
or it can also be done in a similar way that is done in dotnet AspNetCore config,
by using a delimiter like the double underscore __ since in environment variables it is supported by all platforms.

Example with double underscore:
CYPRESS_myConfig__subProperty=2 would change just the env.myConfig.subProperty

Example with JSON:
CYPRESS_myConfig='{ "subProperty": 2 }' would change just the env.myConfig.subProperty

If this is a breaking change then it could have a feature flag to activate this new behavior like useEnvironmentVariablesDeepMerge: true in cypress.config.

Why is this needed?

At the moment, when using cypress.env.json we are forced to duplicate all values within nested properties, unnecessarily duplicating things, and almost all config in our projects is within nested properties.

Other

No response

@jennifer-shehane jennifer-shehane added type: feature New feature that does not currently exist stage: proposal 💡 No work has been done of this issue labels Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: proposal 💡 No work has been done of this issue type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests

2 participants