Closed bryguy closed 3 years ago
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:
const test_data = JSON.parse('[' + Cypress.env('stringified_json').join(',') + ']');
This issue was introduced in 5.0.0.
CYPRESS_stringified_json='[{"type": "foo", "value": "bar"}, {"type": "fizz", "value": "buzz"}]' cypress open
spec.js
it('correctly parses stringified JSON data', () => {
expect(Cypress.env('stringified_json')).to.equal(
'[{"type": "foo", "value": "bar"}, {"type": "fizz", "value": "buzz"}]'
)
})
I'm sure this PR likely introduced this: https://github.com/cypress-io/cypress/pull/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. We'll update this issue and reference the changelog when it's released.
Released in 6.3.0
.
This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v6.3.0, please open a new issue.
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)