abramenal / cypress-file-upload

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

i.getType is not a function #236

Closed ismail-codinglab closed 3 years ago

ismail-codinglab commented 4 years ago

Current behavior:

image

   mime = require("mime");
    mime.getType(...);

Desired behavior:

Be able to use file without specifying mimetype

Steps to reproduce: (app code and test code)

I was not able to reproduce it on cypress tiny test

If i add the mimeType property it doesn't fail anymore

Versions

Cypress v5.3.0 cypress-file-upload v4.1.1.

slinkardbrandon commented 3 years ago

I still see this issue with cypress@6.5.0 and cypress-file-upload@5.0.2.

slinkardbrandon commented 3 years ago

Also if it wasn't clear from @ismail-codinglab's report, you can work around this by using the object notation and passing mimeType like so:

- cy.find('input[type="file"]').attachFile('./picture.png')
+ cy.find('input[type="file"]').attachFile({ filePath: './picture.png', mimeType: mime.getType('./picture.png') })
antonipelka commented 3 years ago

Hey there! I just come with a similar problem. The thing was working yesterday, but today after I've done some changes it broke. The thing I did was simply adding tsconfig.json as it is suggested in Cypress documentation. The outcome was that Cypress was using wrong package version (because I have a couple of them in the project) due to baseUrl set to ../node_modules.

When I did like so (notice removed baseUrl):

{
  "compilerOptions": {
    "allowJs": true,
    "outDir": "ts-dist",
    "types": ["cypress", "@testing-library/cypress", "cypress-file-upload"]
  },
  "include": [
    "**/*.*"
  ],
  "exclude": ["ts-dist"]
}

Then it stopped complaining. It seems to also work with jsconfig.json (with VSCode type suggestions):

{
  "compilerOptions": {
    "types": ["cypress", "@testing-library/cypress", "cypress-file-upload"]
  },
  "include": [
    "**/*.*"
  ]
}

I haven't dug deeper, but it seems it may be related more to Cypress using tsconfig.json. cypress-file-upload has the proper version of mime at node_modules/cypress-file-upload/node_modules/mime, but when baseUrl is set to ../node_modules it simply loads node_modules/mime which is an older version in my case (this one has lookup instead of getType)

Maybe it can help you find the root problem!

ismail-codinglab commented 3 years ago

@abramenal with the issue located, a reproducable example and exact method identified. Do you think it's possible to get a fix out the door?

jenkma02 commented 3 years ago

I am seeing this issue as well - Cypress 6.6.0 and cypress-file-upload 5.0.2. @slinkardbrandon i tried adding the mimeType and unfortunately that didnt work for me. i get an error mime is not defined

abramenal commented 3 years ago

I think these are 2 separate issues:

I was thinking about adding whole mime library into package's bundle. This way it'll become bigger, but there will be no way to mess up with different versions/configurations. This has also been added in v5.0.4 so both issues should be solved now.

Looking forward further feedback if it's working, or any ideas on what might be a better fix.

abramenal commented 3 years ago

Might be also related to #301

abramenal commented 3 years ago

So mime dependency is now bundled within command's source code, and #302 introduces a replacement for all node.js internals. Hence, the package will not have a single dependency required.

UPD: Released in v5.0.7