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
fix: issue with array environment variables not being handled correct… #8135
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ly (#6810) Signed-off-by: Donovan Moini <donovanmoini@gmail.com>
Thanks for taking the time to open a PR!
|
…ly (#6810) Signed-off-by: Donovan Moini <donovanmoini@gmail.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
…nter-events: none` (#8095)
…on 5.4.2 🌟 (#8116) Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
#8125) * Update contributing to mention titling PRs with semantic-release * Update CONTRIBUTING.md link
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User facing changelog
Fixes an issue where Cypress environment variables intended to be arrays were saved as strings.
Additional details
When setting Cypress environment variables as arrays, they are stored as a string of the array instead of an array. By default, all environment variables are stored as strings, but some environment variables are intended to be numbers or booleans. That issue gets resolved in packages/server/lib/util/coerce.js by checking if any Cypress environment variables are meant to be a number or boolean, and if so converting them. But there is no check to see if a Cypress environment variable is meant to be an array.
This issue is resolved by added a helper function (
toArray
) to check if the Cypress environment variable can be converted into an array and addingtoArray
to be checked in thecoerce
function. One important part intoArray
is updating thetoString
method for the returned array. This is because the default arraytoString
method returns one string containing each array element separated by commas, but without '[' or ']'. If an environment variable is intended to be an array, it will be a string beginning and ending with '[' and ']' respectively. For example, ifexport CYPRESS_ARR=[1,2,3]
, thenprocess.env['CYPRESS_ARR']: '[1,2,3]'
. But[1,2,3].toString() = '1,2,3'
, so comparing the two values would returnfalse
and not correctly update the Cypress environment variable to be an array. To correctly compare the Cypress environment variable with the returned array fromtoArray
, the returned array'stoString
method must be updated to include '[' and ']'.How has the user experience changed?
Now when setting Cypress environment variables as arrays, they are correctly converted to arrays. Below are examples from #6810.
Before:
After:
The example with
CYPRESS_testFiles
was originally intended as a workaround for #6810 before this pull request. WhileCYPRESS_testFiles
is technically parsed correctly, I doubt that a user would want the array elements to contain quotation marks within their strings and have an element such as" "**/475*""
instead of"**/475*"
. To avoid this, make sure to set array Cypress environment variables with each element in quotation marks and each element delimited by a single comma without a whitespace (i.e.CYPRESS_testFiles=["**/196*","**/475*","**/476*"]
.This also works when setting Cypress environment variables via
--env
.cypress run --env foo="[bar1,bar2,bar3]"
PR Tasks
cypress-documentation
?type definitions
?cypress.schema.json
?