Skip to content
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

route2 stub for img elements using Fixtures returns text/plain as content type #8623

Closed
TonyHernandezAtMS opened this issue Sep 18, 2020 · 12 comments · Fixed by #8916
Closed
Assignees
Labels
topic: cy.intercept() type: unexpected behavior User expected result, but got another

Comments

@TonyHernandezAtMS
Copy link

TonyHernandezAtMS commented Sep 18, 2020

Current behavior:

route2 when configured with image fixtures returns content text/plain.

image

Desired behavior:

route2 configured with fixtures should return images with correct content type.

Test code to reproduce

Here is a repo with a set of tests.
https://github.com/TonyHernandezAtMS/cypress-test-tiny/
I have found that when I first run this test in Chrome, the first test ends up in a loop requesting the image over and over. If I perform a Empty Cache and Hard Reload in the browser then the tests will progress through all of them.

Versions

5.2.0, Windows, all browsers

@TonyHernandezAtMS
Copy link
Author

@flotwig Hoping you can take a look at this.

@flotwig
Copy link
Contributor

flotwig commented Sep 21, 2020

@TonyHernandezAtMS as a workaround, you can specify the content-type manually for responses. Using your example:

    cy.fixture("fixture1/pictures/category.jpg").then((pic) => {
      cy.route2("images/category.jpg", { body: pic, headers: { 'content-type': 'image/jpeg' } });
    });

I'm pretty sure this problem also exists for the fixture API:

// this probably also sends the wrong content-type, but can be fixed
cy.route2('images/category.jpg', { fixture: 'fixture1/pictures/category.jpg' })

I'm not sure if there is going to be a way to fix the pattern you've provided in the OP, but we can definitely fix this usage.

@flotwig flotwig added topic: cy.intercept() type: unexpected behavior User expected result, but got another labels Sep 21, 2020
@TonyHernandezAtMS
Copy link
Author

@flotwig
I tried your snippet:

    cy.fixture("fixture1/pictures/category.jpg").then((pic) => {
      cy.route2("images/category.jpg", { body: pic, headers: { 'content-type': 'image/jpeg' } });
    });

It didn't work. The browser still shows a blank placeholder. I've attached the HAR file and have updated the repo with this snippet.

@flotwig
Copy link
Contributor

flotwig commented Sep 23, 2020

@TonyHernandezAtMS try this maybe:

cy.route2('images/category.jpg', { fixture: 'fixture1/pictures/category.jpg', headers: { 'content-type': 'image/jpeg' } })

@bahmutov
Copy link
Contributor

You know we have https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/stubbing-spying__route2 where you could try and show how it is working or not working without guessing

@bahmutov
Copy link
Contributor

Tried the image spying and stubbing, so far no luck, see cypress-io/cypress-example-recipes#570 (comment)

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Sep 29, 2020
@TonyHernandezAtMS
Copy link
Author

@flotwig @bahmutov
Hi Zach and Gleb - Any update?

@bahmutov
Copy link
Contributor

bahmutov commented Oct 6, 2020 via email

@TonyHernandezAtMS
Copy link
Author

TonyHernandezAtMS commented Oct 6, 2020 via email

@flotwig
Copy link
Contributor

flotwig commented Oct 21, 2020

This was actually a 2-part bug - the wrong Content-Type was getting assigned, /and/ the fixture body was getting incorrectly encoded to base64, which is why #8623 (comment) didn't work. Opened a PR to fix #8916

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Oct 22, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Oct 22, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 22, 2020

The code for this is done in cypress-io/cypress#8916, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 27, 2020

Released in 5.5.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.5.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.intercept() type: unexpected behavior User expected result, but got another
Projects
None yet
4 participants