cypress
cypress copied to clipboard
cy.task() doesn't work as expected with Cypress version 12.16.0
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
@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.
Same here, we can still reproduce this issue on Cypress 12.16.0 (when it worked on Cypress 12.14.0)
@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?
@chrisbreiding there you go: https://github.com/cypress-io/cypress-test-tiny/pull/83 check my PR. You can reproduce the issue in your repo when running the spec on the project.
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.