-
Notifications
You must be signed in to change notification settings - Fork 3.3k
CYPRESS_ env variable string value containing commas parsed as multiple values #8818
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
Comments
As a temporary workaround, I updated the actual test that started breaking with the following hack to unmangle the value back into its original stringified JSON format like so:
|
This issue was introduced in 5.0.0. Reproducible example
it('correctly parses stringified JSON data', () => {
expect(Cypress.env('stringified_json')).to.equal(
'[{"type": "foo", "value": "bar"}, {"type": "fizz", "value": "buzz"}]'
)
}) 4.12.15.0.0WhyI'm sure this PR likely introduced this: #8151 We would be open to a PR to fix this. |
The requested change was to return the original JSON string. But the goal of #8151 was to parse and return a useful value from Cypress side. So, I decided to parse the JSON string to object. |
The code for this is done in cypress-io/cypress#9584, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
After upgrading Cypress from 4.10.0 to 5.3.0, one of my tests started failing. This appears to be due to a change in the way
CYPRESS_
environment variables are getting parsed between the two versions.I'm passing a string of JSON data to my test via a
CYPRESS_
prefixed environment variable like so:When attempting to call
JSON.parse(Cypress.env('stringified_json'))
on that value in my test, the test started failing with the following error:After digging in a little bit, I found that instead of the expected JSON string, the value for that variable now contains an array of the passed string value split on every comma. Here's the output for 5.3.0 using the simplified test code attached below:
Desired behavior
Simply pass through the value for the environment variable without splitting on commas the same way it used to be passed in 4.10.0. Here's the output of the test code attached below for 4.10.0:
Test code to reproduce
Versions
Cypress: Cypress 5.3.0
Operating System: macOS 10.15.7
Browser: Electron 83 (headless)
The text was updated successfully, but these errors were encountered: