-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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.intercept() breaks uploaded image #9359
Comments
I am able to recreate the issue from the repo provided. |
Tried Cypress v6.0.1 and the latest Even breaks when simply spying using it.only('spy only', () => {
cy.intercept('PUT', 'http://localhost:3000/upload'); // only spy on the upload
cy.visit('http://localhost:3000/');
cy.get('input').attachFile('image.jpeg');
cy.get('button').click();
cy.get('span').should(function ($span) {
expect($span).to.have.text('SUCCESS')
});
}) The command log shows Note: the image upload code var formData = new FormData();
formData.append('image', input.files[0]);
axios.put('http://localhost:3000/upload', formData) |
I just discovered this is ALSO an issue with blob downloads as I was attempting to test a PDF download by parsing the intercepted body, but the PDF parser pukes. It turns out the intercepted body has way more bytes than the actual API provided, so the bug exists in intercept on both send and receive. |
I suspect the toString() is incorrect here:
|
Same issue here and continues in version 6.1.0. Any progress on fixing it? This prevents the use of intercept in requests with formData. |
Me and colleague just spent 2 hours on figuring out why file download request was failing not even getting to back-end. It was cy.intercept that broke request somewhere in the middle (or, maybe, the very moment it was detected). |
Hey everyone 👋, The problemAs @nickpalmer mentioned, the issue lies in:
The parameter That results in a change of the actual byte length of the request body. request.req.pipe(network_1.concatStream(function (reqBody) {
request.req.body = frame.req.body = reqBody.toString()
console.log("Original content length: ", request.req.headers["content-length"], " Bytes")
console.log("Binary content length: ", reqBody.byteLength, " Bytes")
console.log("UTF-8 content length: ", Buffer.byteLength(reqBody.toString(), 'utf8'), " Bytes")
cb();
}));
Now the A possible solutionAfter some manual testing I came across this working solution: request.req.pipe(network_1.concatStream(function (reqBody) {
request.req.body = frame.req.body || reqBody.byteLength ? reqBody : undefined
cb();
})); It is key to omit Can anyone give me feedback on this solution? I would be more than willing to make a pull request for it. Cheers, |
@maxbause it sounds like you're on the right track, feel free to open a PR and I can help if you run into any issues |
The code for this is done in cypress-io/cypress#14235, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
When using cy.intercept(), an image uploaded has incorrect size and doesn't recognized as image. It's almost 2x more in size than original image.
Desired behavior
An image uploaded should be the same as the original image.
Test code to reproduce
Please clone and try: https://github.com/AlexCSR/cypress-intercept-buffer-bug
Versions
Cypress: 6.0.0
This issue looks similar to #9166 and only faced with cy.route2() / cy.intercept(), but not with cy.route().
The text was updated successfully, but these errors were encountered: