fixture with `.json` file extension ignores specified encoding and applies JSON.parse
See original GitHub issueCurrent behavior:
cy.fixture('upload.json', 'hex').then(s=>assert.typeOf(s, 'string')) // fails
cy.fixture('upload.foojson', 'hex').then(s=>assert.typeOf(s, 'string')) // passes
Desired behavior:
JSON.parse should not be applied when encoding is set.
Versions
Cypress 3.8.3, Windows 10, Electron 78
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
fixture | Cypress Documentation
Default Encoding. Cypress automatically determines the encoding for the following file types: . json.
Read more >Cypress Fixtures - ProgramsBuzz
Cypress Fixture Command is used to load a fixed set of data located in different files including JSON and Image file. cy.fixture() yields ......
Read more >JSON Files - Spark 3.3.1 Documentation
Property Name Default Scope
primitivesAsString false read
prefersDecimal false read
allowComments false read
Read more >What is the difference between cy.readFile and cy.fixture in ...
readFile("test.txt") will read from (path-to-project)\test.txt . ... cy.fixture() assumes the encoding for certain file extensions while cy.
Read more >How to use a JSON document, Utf8JsonReader, and ...
The JsonElement type provides array and object enumerators along with APIs ... Parse(jsonString)!; // Write JSON from a JsonNode var options ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can recreate this.
When the file has an extension of
.json
, we just do a JSON.parse and don’t consider the encoding at all as you can see in this line https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/fixture.coffee#L106:L106Somewhat related #5395
Closing since there’s been no response. If someone can elaborate on the use case of encoding in hex format, we can consider reopening.