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

[7.0.1]Bug: uploading a fixture break Cypress #15898

Closed
LukasM937 opened this issue Apr 9, 2021 · 22 comments · Fixed by #16306
Closed

[7.0.1]Bug: uploading a fixture break Cypress #15898

LukasM937 opened this issue Apr 9, 2021 · 22 comments · Fixed by #16306
Assignees
Labels
topic: cy.intercept() type: regression A bug that didn't appear until a specific Cy version release

Comments

@LukasM937
Copy link

LukasM937 commented Apr 9, 2021

I upgraded Cypress from 5.5.0 to 6.8.0 noticing a issue with the uploading from images as fixtures.
This issue was present also when one manually uploads a image to the tested site.
Since this issue, manifested after the update, I updated to 7.0.0 (and to 7.0.1 for that matter).

Current behavior

Cypress breaks when uploading an Image, thus stoping execution.

Test code to reproduce

This is the breaking part of the test,
while "cy.wait('imageRequest')" is open during it it breaks.

Due to some uncertainty in confindelity I sadly can't publish the full test.

cy.fixture('testimage.png').as('image')
cy.get('.block').last().within(() => {
    cy.get('.grid-row .grid-column .plugin-image .form input[type=file]').then(function (el) {
    cy.wait('@imageRequest')
    // cy.wait('@pageSaveRequest')
    // convert the image base64 string to a blob
    const blob = Cypress.Blob.base64StringToBlob(this.image, 'image/png')

    const file = new File([blob], 'testimage.png', { type: 'image/png' })
    const list = new DataTransfer()

    list.items.add(file)
    const myFileList = list.files

    el[0].files = myFileList
    el[0].dispatchEvent(new Event('change', { bubbles: true }))
    })
})

Error Message

TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer or Uint8Array. Received type number (137)
    at write_ (_http_outgoing.js:696:11)
    at ClientRequest.write (_http_outgoing.js:661:15)
    at Request.write (/path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:1496:27)
    at /path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:546:20
    at Array.forEach (<anonymous>:null:null)
    at end (/path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:545:23)
    at Immediate._onImmediate (/path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:578:7)
    at processImmediate (internal/timers.js:461:21)
 {
  code: 'ERR_INVALID_ARG_TYPE'
}
TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer or Uint8Array. Received type number (137)
    at write_ (_http_outgoing.js:696:11)
    at ClientRequest.write (_http_outgoing.js:661:15)
    at Request.write (/path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:1496:27)
    at /path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:546:20
    at Array.forEach (<anonymous>:null:null)
    at end (/path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:545:23)
    at Immediate._onImmediate (/path/from/userTo/Caches/Cypress/7.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/request/request.js:578:7)
    at processImmediate (internal/timers.js:461:21)

Versions

It works in 5.5.0,
from 6.0.1 it doesn't work but did not brake,
from 7.0.0 it breaks Cypress.

@MatthiasDamm
Copy link

same here, it's also crashing when you're just selecting a file in the UI testrunner, so it might be more mabye an underlying problem and not with the test istelf?

@MatthiasDamm
Copy link

MatthiasDamm commented Apr 10, 2021

Think it's same as #15901

@verheyenkoen
Copy link
Contributor

verheyenkoen commented Apr 13, 2021

Having a very similar (if not the same) issue.

@LukasM937 Can you post your full test. I guess you are starting off with a cy.intercept to alias the route to wait on.

In my case I was in the process of migrating from cy.route to cy.intercept and the former is still working while the latter is causing the crash, so the bug is probably cy.intercept related.

@verheyenkoen
Copy link
Contributor

I also noticed it does not crash if you stub the upload (POST) response.

@jennifer-shehane
Copy link
Member

We're not sure if this is a duplicate of #15901 exactly since a fully reproducible example wasn't provided.

Can someone provide a reproducible example?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Apr 22, 2021
@jennifer-shehane
Copy link
Member

We merged in a fix for the other issue #15946, so you may try the next release around Monday to see if this issue is resolved if it is actually related.

@verheyenkoen
Copy link
Contributor

@jennifer-shehane Is that a patch release? I'm subscribed to the releases page so I should get a notification I guess?

@jennifer-shehane
Copy link
Member

@verheyenkoen We'll have a feature release on Monday like we do every 2 weeks, barring any complications on the release day. You could technically download the pre-release if you want to follow instructions on the specific commit: a702835#commitcomment-49866616

@verheyenkoen
Copy link
Contributor

@jennifer-shehane Tested that (not sure if I did it correctly though) and didn't fix my issue. Will try again on Monday after release. If not I'll try to come up with a reproducible repo.

@LukasM937
Copy link
Author

We merged in a fix for the other issue #15946, so you may try the next release around Monday to see if this issue is resolved if it is actually related.

Thank you for the Information!
To have the test in a reproducible state, one needs access to the software we had build the test for, thus it took quite some time for the approval.
I'll check out the fix next week but build up the test to reproduce it.

Thank you for your work!

@verheyenkoen
Copy link
Contributor

verheyenkoen commented Apr 27, 2021

Release 7.2.0 didn't fix our issue. Will try to create a reproducible test suite.

@LukasM937
Copy link
Author

@verheyenkoen, It looks like that. I look at the workaround with reverting to using cy.route. I'll post the outcome when the tests are finish.
@jennifer-shehane If it is okay I would send you a token (to keep the exposure at a minimum) and post the test file here.

@verheyenkoen
Copy link
Contributor

verheyenkoen commented Apr 27, 2021

@jennifer-shehane Here's a a test suite (using yarn) with both a cy.route() and cy.intercept() version of the same test. The former success without a problem. The latter causes the crash above.

@donalmurtagh
Copy link

I've tested this with release 7.2.0 and the issue still exists. In my case I'm uploading an Excel (.xlsx) file using this command

Cypress.Commands.add('apiCreateTask', (eventId, task, fileName) => {
  cy.intercept('POST', '/api/task').as('postTask')
  const fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

  cy.window().then(window => {
    cy.fixture(fileName, 'binary').then((file) => {
      // File in binary format gets converted to blob so it can be sent as Form data
      const fileBlob = Cypress.Blob.binaryStringToBlob(file, fileType)
      const fileToUpload = new File([fileBlob], 'testing.xlsx', { type: fileType })
      window.model.taskService.saveTask(eventId, task, fileToUpload)
    })
  })

  return cy.wait('@postTask')
})

taskService.saveTask is the app action shown below

  async saveTask (task, file) {
    const requestBody = new FormData()
    requestBody.append('file', file)

    const options = {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    }
    await http.post('/api/task', requestBody, options)
  }

@jennifer-shehane
Copy link
Member

@verheyenkoen Thanks so much for providing a reproducible example. I can see Cypress crashing when running the tests in this repo: https://github.com/verheyenkoen/cypress-upload-intercept-problem

  • npm i
  • cypress open or cypress run

@cypress-bot cypress-bot bot added stage: to do and removed stage: needs information Not enough info to reproduce the issue labels Apr 27, 2021
@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope type: regression A bug that didn't appear until a specific Cy version release labels Apr 27, 2021
@jennifer-shehane
Copy link
Member

There's an example in this issue that may or may not be related. In that example, there is no uploading from within Cypress, but simply uploading a video within their app that is running inside Cypress. See #16223 (comment)

@cypress-bot cypress-bot bot added stage: work in progress and removed stage: ready for work The issue is reproducible and in scope stage: to do labels Apr 27, 2021
@verheyenkoen
Copy link
Contributor

@jennifer-shehane Which is basically what my example repo does except it does the uploading from within Cypress. If you remove the intercept there is no problem. Also if you stub the response it doesn't crash I noticed. Tested in Chrome, Electron and Firefox (both GUI and CLI).

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels May 3, 2021
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 3, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 3, 2021

The code for this is done in cypress-io/cypress#16306, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@jennifer-shehane
Copy link
Member

If you would like to download the pre-release version of Cypress to get this fix. Follow the instructions here

@verheyenkoen
Copy link
Contributor

@jennifer-shehane I already tested it on my test suite mentioned above and it works (on darwin).

@LukasM937
Copy link
Author

@jennifer-shehane I also tested it on the breaking test.
The breaking issue is fixed Thank you for that! And it seems that also the uploading issue was fixed along the way!

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 10, 2021

Released in 7.3.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.intercept() type: regression A bug that didn't appear until a specific Cy version release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants