abramenal / cypress-file-upload

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

[Bug] Wrong content-length with `binary` encoding #240

Closed Hulkmaster closed 3 years ago

Hulkmaster commented 3 years ago

Description:

We have image upload test, which was working on cypress 5.2.0, now we decided to upgrade to 5.6.0, and we started to have error

(prev usage) .attachFile('image/10kb-image.jpg')

(also not working)

          .attachFile({
            filePath: 'image/10kb-image.jpg',
            encoding: 'binary'
          })

(hack usage - works)

          .attachFile({
            filePath: 'image/10kb-image.jpg',
            encoding: 'ascii',
            mimeType: 'image/png'
          })

with default/binary usage Content-Length: 10203

with ascii usage Content-Length: 10204

So our backend responses with 422, because content length mismatch

(test image) 10kb-image

Versions

Cypress: 5.6.0 Plugin: 4.1.1

Hulkmaster commented 3 years ago

also doesn't seem to be Cypress bug 🤔

    cy.fixture('image/10kb-image.jpg', 'binary')
      .then((file) => {
        console.log(file.length);
      })
      .fixture('image/10kb-image.jpg', 'ascii')
      .then((file) => {
        console.log(file.length);
      })
9916
9916
Hulkmaster commented 3 years ago

okay, seems like its route2 doing something during intercepting

works cy.server().route('POST', '...').as('avatar');

does not work cy.route2('POST', '...').as('avatar');