question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fixture with `.json` file extension ignores specified encoding and applies JSON.parse

See original GitHub issue

Current 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, May 19, 2020

I can recreate this.

it('not hex value', () => {
  // when file ext is .json this fails
  cy.fixture('movies.json', 'hex').then(s => assert.typeOf(s, 'string')) // fails
})

it('hex value', () => {
  // other extensions pass
  cy.fixture('movies.foojson', 'hex').then(s => assert.typeOf(s, 'string')) // passes
})
Screen Shot 2020-05-19 at 6 27 13 PM

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:L106

Somewhat related #5395

0reactions
jennifer-shehanecommented, Jun 11, 2021

Closing since there’s been no response. If someone can elaborate on the use case of encoding in hex format, we can consider reopening.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found