Skip to content

fix: return raw fixture when encoding is specified #32155

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

Merged
merged 5 commits into from
Aug 8, 2025

Conversation

adamalston
Copy link
Contributor

@adamalston adamalston commented Aug 5, 2025

Additional details

I'm not sure if an end-to-end test should also be added. This one worked when I added it in packages/driver/cypress/e2e/commands/fixtures.cy.js:

it('should return encoded JSON', () => {
  const fixture = 'example'
  const fixtures = [
    { fixture, encoding: undefined, content: { example: true } },
    // TODO: Use the same file in all `fixture` calls after
    // https://github.com/cypress-io/cypress/issues/32138 is addressed.
    { fixture: 'app', encoding: 'base64', content: 'ewogICJzb21lIjogImpzb24iLAogICJmb28iOiB7CiAgICAiYmFyIjogImJheiIKICB9Cn0K' },
    // TODO: Use the same file in all `fixture` calls after
    // https://github.com/cypress-io/cypress/issues/32138 is addressed.
    { fixture: 'valid', encoding: 'utf8', content: '{\n  "foo": 1,\n  "bar": {\n    "baz": "cypress"\n  }\n}\n' },
    // TODO: Use the same file in all `fixture` calls after
    // https://github.com/cypress-io/cypress/issues/32138 is addressed.
    { fixture: 'null.json', encoding: '', content: 'bnVsbAo=' },
  ]

  fixtures.forEach(({ fixture, encoding, content }) => {
    cy.fixture(fixture, encoding).should('deep.equal', content)
  })
})

Steps to test

cd packages/server
yarn test-watch test/unit/fixture_spec.js # tests should pass
git checkout develop packages/server/lib/fixture.js # tests should fail

How has the user experience changed?

N/A

PR Tasks

@cypress-app-bot
Copy link
Collaborator

@adamalston
Copy link
Contributor Author

Hmm, the throws when json is invalid test fails locally without the changes in f9350b7 but it fails in CI with them.

Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamalston a unit test should be all that is necessary here since the e2e test would essentially be testing the same functionality that we care about. My only concern is that this could possibly be disruptive, but I can't think of a case that would be problematic off the top of my head. Either way this will be making it's way into Cypress 15.

Thank you for the contribution!

@AtofStryker AtofStryker merged commit 39c1759 into cypress-io:develop Aug 8, 2025
9 of 11 checks passed
@adamalston adamalston deleted the 32139-decode branch August 8, 2025 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fixture with base64 encoding returns an object instead of a string
4 participants