abramenal / cypress-file-upload

File upload testing made easy
https://npm.im/cypress-file-upload
MIT License
498 stars 89 forks source link

V5.0.0 breaks repeated uploads #264

Closed yonigibbs closed 3 years ago

yonigibbs commented 3 years ago

With version 5.0.0, if the test simulates a user uploading one file then another (to replace the first one), on the second upload the system thinks that two files are being uploaded at once, rather than just one. This is different from what happened in v4.x, and is different from what happens if a user manually executes the uploads.

The code I'm using is written in Elm rather than JS or TS, so that might be related, I'm not sure.

A repo that demonstrates the issue is available here: https://github.com/yonigibbs/cypress-file-upload-repeated-uploads

Versions

Cypress 5.0.0 Ubuntu 18.0.4 Chrome 87 / FireFox 84

abramenal commented 3 years ago

@yonigibbs hi there, thanks for submitting the issue!

I wasn't completely sure about this logic, but we indeed have place where we keep previously attached files. https://github.com/abramenal/cypress-file-upload/blob/main/src/helpers/attachFileToElement.js#L5

I think originally it was related to command chaining calls, but since not it is not supported, we can drop this logic as well.

JanLoebel commented 3 years ago

Same problem here :) Is there any workaround?

Edit: found a way cy.get('input[type=file]').then($el => { $el.val('') });

abramenal commented 3 years ago

Thanks everyone, just released the fix in v5.0.1

yonigibbs commented 3 years ago

Awesome! Thanks for the really fast turnaround, @abramenal 👍

yonigibbs commented 3 years ago

Hey @abramenal. I just tried this out with the example repo I originally linked, and unfortunately it doesn't look like it's resolved the issue (at least in my example). If you check out that repo (the master branch) and update the dependency to v5.0.1 then run Cypress the example test still fails. (It passes when using v4.1.1.)

yonigibbs commented 3 years ago

@abramenal, I might be totally barking up the wrong tree here, but is it possible that NPM hasn't quite got the right version of the code? I see that the code fix was basically to remove the call to Array.prototype.forEach.call(element.files, f => dataTransfer.items.add(f)); (see PR here). I checked the latest code in this GitHub repo and there are now no more calls to Array.prototype.forEach.call. But when I grab the package from NPM and look in dist/bundle.js I still see that call (albeit in the minified form). Is that maybe the culprit?

abramenal commented 3 years ago

@yonigibbs this is rare, but might be possible still. If you still see it there, then it is indeed this. Let me publish a new build then. Will you me able to check it again with v5.0.2?

yonigibbs commented 3 years ago

Yup, got the notification email and already tried. 5.0.2 does indeed resolve it. Thanks! 👍