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

cy.task() doesn't work as expected with Cypress version 12.16.0 #27200

Closed
CarleneCannon-Conner opened this issue Jul 5, 2023 · 5 comments · Fixed by #27282
Closed

cy.task() doesn't work as expected with Cypress version 12.16.0 #27200

CarleneCannon-Conner opened this issue Jul 5, 2023 · 5 comments · Fixed by #27282
Assignees
Labels
E2E Issue related to end-to-end testing

Comments

@CarleneCannon-Conner
Copy link

Current behavior

I am attempting to migrate from cypress version 10.11.0 to version 12.16.0. When running existing tests it appears that cy.tasks() no longer works as it once did. It gives the error cy.task() must only be invoked from the spec file or support file.

Upon further investigation, it looks as though it works fine if the array of objects passed to the function is less than 67 objects. As a quick fix in our codebase I intend to propose breaking up our large array into smaller chunks.

I also tested against versions 12.14.0 and 12.15.0. Only version 12.14.0 worked, so it is likely the breaking change was introduced in version 12.15.0 and has persisted to version 12.16.0.

Desired behavior

It would be nice if a fix could be implemented so that cy.tasks() works with large arrays as it used to in previous versions.

Test code to reproduce

In our codebase we are using in an after() to collate a couple of arrays, one of which contains very large array of objects.
Here is a simplified version of it. Note if I use less objects e.g. 50 it works as expected.

module.exports = (on) => {
  on('task', {
    example({ arr0, arr1 }) {
      // do something with arr0 and arr1
      return null;
    },
  });
after(() => {
    const arr0 = [ {x: 0, y: 1, z: 2}]; // typically contains only 1 object
    const arr1 = [ // contains at least 67 objects
       {x: 0, y: 1, z: 2}
        .... 
    ];

    cy.task('example', { arr0, arr1) });
});

Cypress Version

12.16.0

Node version

v16.14.0

Operating System

macOS 13.4.1

Debug Logs

No response

Other

No response

@chrisbreiding
Copy link
Contributor

@CarleneCannon-Conner I'm unable to reproduce this with Cypress 12.16.0. Here is what I used for the test code:

it('issue #27200', () => {})

after(() => {
  const arr0 = [{ x: 0, y: 1, z: 2 }]
  const arr1 = (new Array(9999)).fill(0).map(() => ({ x: 0, y: 1, z: 2 }))

  cy.task('example', { arr0, arr1 })
})

For me, this fails in 12.15.0 but passes in 12.16.0. This looks like a bug that was fixed in 12.16.0, so it would surprising for it still to be an issue.

Would you mind double-checking that you're running 12.16.0 and that the test code above triggers the issue?

If you still encounter the issue with 12.16.0, do you see any red error messages in the browser devtools console? The aforementioned bug was always accompanied by a 413 (Payload Too Large) or similar error.

@estefafdez
Copy link

Same here, we can still reproduce this issue on Cypress 12.16.0 (when it worked on Cypress 12.14.0)

@chrisbreiding
Copy link
Contributor

@estefafdez Are also you able to reproduce it on Cypress 12.17.0? If so, can you provide a minimal reproduction of the issue using cypress-test-tiny?

@estefafdez
Copy link

@chrisbreiding there you go: cypress-io/cypress-test-tiny#83 check my PR. You can reproduce the issue in your repo when running the spec on the project.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 20, 2023

Released in 12.17.2.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jul 20, 2023
@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue and removed stage: needs information Not enough info to reproduce the issue labels Oct 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
E2E Issue related to end-to-end testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants