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

Usage with Nuxt, Typescript and Jest #7327

Closed
MartinMalinda opened this issue May 13, 2020 · 13 comments
Closed

Usage with Nuxt, Typescript and Jest #7327

MartinMalinda opened this issue May 13, 2020 · 13 comments

Comments

@MartinMalinda
Copy link

MartinMalinda commented May 13, 2020

I've played with Cypress for the first time today and the first impression is great, thanks for all the work on this! That being said, while Cypress ran fine, the main app showed a lot of TS errors in build.

There are existing repositories that I look into for guidance:

Test code to reproduce

Minimal reproduction:

https://github.com/MartinMalinda/nuxt-jest-cypress-typescript

npx cypress open works
npm run dev errors out with type conflicts

@MartinMalinda
Copy link
Author

One solution that would probably work would be installing cypress to a different folder with a separate package.json. But it seems like this against the philosophy of Cypress that it should be part of the main application.

@jennifer-shehane
Copy link
Member

type conflicts shown below. Most of these are duplicate of #6690

Screen Shot 2020-05-14 at 12 24 28 PM

Screen Shot 2020-05-14 at 12 24 48 PM

@MartinMalinda
Copy link
Author

These errors still persist in 4.6.0

https://github.com/MartinMalinda/nuxt-jest-cypress-typescript

@brian-mann
Copy link
Member

@MartinMalinda I believe you need to add a tsconfig.json file in your cypress folder to the effect of this...

{
   "extends": "../tsconfig.json",
   "compilerOptions": {
      "types": ["cypress"]
   }
}

@tgriesser can you weigh in here?

@MartinMalinda
Copy link
Author

Thanks @brian-mann. I've already experimented with this separate tsconfig with no luck. The errors appear even if there's no tsconfig.json at all and only /// <reference types="cypress" /> which means that only mention of cypress type will create conflicts.

@MartinMalinda
Copy link
Author

But it seems like I had types under wrong place. I've pushed latest to master: https://github.com/MartinMalinda/nuxt-jest-cypress-typescript/blob/master/cypress/tsconfig.json

@tgriesser
Copy link
Member

From your latest commit, I believe it should just be "types": ["cypress"], not "types": ["@types/cypress"] because Cypress ships with its own types.

@tgriesser
Copy link
Member

I'm also not sure that you need the "include": ["../node_modules/cypress", in there

@MartinMalinda
Copy link
Author

@tgriesser I see, thank you. The conflicts when running npm run dev are still there. Visual Studio picks up the types well, the errors only appear during build which suggests it might be nuxt-ts that causes problems.

@MartinMalinda
Copy link
Author

I managed to get the build running.

I did these two things:

  1. removed extend from the tsconfig.json in cypress folder - I guess the extend merged the types, not overrode it and that caused the conflicts
  2. I added cypress to exclude in the root tsconfig.json

I'll try run tests, use TS etc to check if this solves everything.

@MartinMalinda
Copy link
Author

I made it work in the main app as well. It seems like extend can be done - the types get overriden properly. The build happens correctly for both cypress and the main app, it's just that there's type errors in VS Code. They disappear if I remove the extend or if I add /// <reference types="cypress" /> at the top of the file.

@yunlonglee
Copy link

yunlonglee commented Jul 8, 2020

Thx i also make it work when I added tests/e2e to exclude in the root tsconfig.json

tests/e2e is my cypress folder

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "lib": ["esnext", "esnext.asynciterable", "dom"],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noImplicitAny": false,
    "noEmit": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"]
    },
    "types": ["@types/node", "@nuxt/vue-app", "@types/jest"]
  },
  "exclude": ["tests/e2e"]
}

@jennifer-shehane
Copy link
Member

Closing as resolved.

If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants