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

intercept() sometimes parses request or response body as ArrayBuffer #17055

Closed
filiphric opened this issue Jun 22, 2021 · 16 comments
Closed

intercept() sometimes parses request or response body as ArrayBuffer #17055

filiphric opened this issue Jun 22, 2021 · 16 comments
Labels
stage: awaiting response Potential fix was proposed; awaiting response stale no activity on this issue for a long period

Comments

@filiphric
Copy link

filiphric commented Jun 22, 2021

Current behavior

Some intercepts don’t parse request or response body well, instead of JSON, it is parsed as ArrayBuffer.
Screenshot 2021-06-22 at 10 47 49

Test code to reproduce

You can find the whole code example here. I was unable to pin down what kind of response or request body caused this. I tried to create a minimalistic example but I ended up just copying the whole payload from the app I’m testing.

Versions

Problem appears from v7 and higher. .intercept() actually behaves well on 6.x versions.

@jennifer-shehane
Copy link
Member

I think this may be addressed in this issue, which will be fixed in our next release. #16292

@jennifer-shehane jennifer-shehane added the stage: awaiting response Potential fix was proposed; awaiting response label Jun 22, 2021
@filiphric
Copy link
Author

Awesome, thanks. I’ll make sure to close the issue once the release is out 👍

@alexneo2003
Copy link

after upgrade cypress to latest 7.6.0 i'm having same issue like #16292 with test example at this message

image

@filiphric
Copy link
Author

Same goes for me. I updated the example with latest version, you can observe the issue still happening.

@frankind
Copy link

frankind commented Jun 25, 2021

I also found this issue in my project too. (Cypress 7.5.0)
I revert back to Cypress 6.9.1 and it works fine.

@tiagodread
Copy link

Running into the same issue with Cypress 7.7.0:

image

@nemkin
Copy link

nemkin commented Jul 14, 2021

I'm experiencing the same issue with Hungarian strings, using Cypress 7.7.0.

Not just the special characters, but the structure of the JSON object and the distance between the special characters seems to be important.

Test code to reproduce:

const data9as = {
  a: [
    {
      a: "üaaaaaaaaaé", // 9 a-s between
      b: 1,
    },
  ],
};

const data8as = {
  a: [
    {
      a: "üaaaaaaaaé", // 8 a-s between
      b: 1,
    },
  ],
};

it("cy.intercept hungarian issue test", () => {
  cy.intercept("https://example.com/test", {
    body: { result: "ok" },
  }).as("testRequest");

  cy.window().then(() => {
    const xhr = new XMLHttpRequest();
    xhr.open("PUT", "https://example.com/test");
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify(data9as));
  });
  cy.wait("@testRequest")
    .its("request")
    .then((req) => {
      expect(req.body).to.not.be.an("ArrayBuffer"); // ❗️ fails
      expect(req.body).to.be.an("object"); // ❗️ fails
    });

  cy.window().then(() => {
    const xhr = new XMLHttpRequest();
    xhr.open("PUT", "https://example.com/test");
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify(data8as));
  });
  cy.wait("@testRequest")
    .its("request")
    .then((req) => {
      expect(req.body).to.not.be.an("ArrayBuffer"); // ✅ passes
      expect(req.body).to.be.an("object"); // ✅ passes
    });
});

@GlebkaF
Copy link

GlebkaF commented Jul 19, 2021

same issue with Russian letters

@lorenzogrv
Copy link

lorenzogrv commented Jul 30, 2021

Similar issue with tilde latin letters (áéíóú) with cypress version 7.6.0. Few notes:

  • Upgrading to 8.1.0 did not help
  • Downgrading to 6.9.1 worked

I've also found #16292 which seems fixed, but may not.

@SimeonC
Copy link

SimeonC commented Aug 3, 2021

I've found that this also happens with Japanese characters in v8.1.0 of cypress.

@lorenzogrv
Copy link

lorenzogrv commented Aug 4, 2021

@jennifer-shehane I wanted to help a bit and created reproducible failed tests → https://github.com/lorenzogrv/cy-intercept-latin-error

An excerpt

const URL = 'https://example.com/test'

function request (body) {
  // performs an XMLHttpRequest to URL
}

function dryAssert (interception) {
  const { request: req } = interception
  expect(req.body).to.not.be.an('ArrayBuffer')
  expect(req.body).to.be.an('object')
}

describe('cy.intercept latin tilde ArrayBuffer issue', () => {
  beforeEach(() => {
    cy.intercept(URL, { body: { result: 'ok' } }).as('interception')
  })

  describe('Cases working as of 8.x', () => {
    it('should work single "letter with tilde"', () => { // ✅
      request({ key: 'á' })
      cy.wait('@interception').then(dryAssert)
    })

    it('should work with fiveteen "letters with tilde"', () => { // ✅
      request({ key: 'áéíóúáéíóúáéíóú' })
      cy.wait('@interception').then(dryAssert)
    })

    it('should work with letters with tilde" within key', () => { // ✅
      request({ 'tíldéd Kéy': null })
      cy.wait('@interception').then(dryAssert)
    })
  })

  describe('Cases not working as of 8.x', () => {
    it('should work with mixed tilded and non-tilted letters', () => { // ❗️
      request({ key: 'válúéwíthsómánytíldés' })
      cy.wait('@interception').then(dryAssert)
    })

    it('should work with letters with tilde" within key and value', () => { // ❗️
      request({ 'tíldéd Kéy': 'áéíóúáéíóúáéíóú' })
      cy.wait('@interception').then(dryAssert)
    })
  })
})

After research I can conclude the JSON structure does not need to be complicated to reproduce the bug

@lorenzogrv
Copy link

I have tested the reploducible I shared above with cypress 8.2.0. Issue seems gone.

@nemkin
Copy link

nemkin commented Aug 10, 2021

Mine also passes in 8.2.0. Thank you!

@Deop
Copy link

Deop commented Aug 10, 2021

Issue we had with an ArrayBuffer response seems to have gone in 8.2 as well.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: awaiting response Potential fix was proposed; awaiting response stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests