-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Possible type definition conflict on @types/chai #1087
Comments
we should not use fuzzy versions, because breaking changes in dependencies can happen. I am also against bringing in |
Cypress doesn't have to use The issues isn't in Cypress type definitions, but rather in having more than 1 I agree that fuzzy versions can break things, however, I think fuzzy version strings for type declaration dependencies is preferable to requiring developers to manage transitive dependencies. |
I see, but still |
I think the issue is deeper than just conflicts in I think the solution for TypeScript users should be to have their own Proposal: I'll try this out and post back. |
That sounds like the best plan for solution - isolating cypress types via ts config
…Sent from my iPhone
On Dec 19, 2017, at 10:37, Nicholas Boll ***@***.***> wrote:
I think the issue is deeper than just conflicts in chai. The conflict can happen for any type definition declared on global (jest, mocha, chai, jquery, etc). The issue is Cypress is basically its own environment. The good news is Cypress is meant to run in its own subdirectory of a project (it could be in its own repo, but I like it in the source project).
I think the solution for TypeScript users should be to have their own tsconfig.json where you can set up a more limited environment. I'm experimenting with that right now. It would be good to put these best practices in the TypeScript example with some explanation as to why. If people use that example as a starting point, it will reduce the likelihood that someone will run into this issue.
Proposal:
The idea is you have a tsconfig.json in the cypress folder. This tsconfig.json extends from the tsconfig.json in the base of the project. It has a baseUrl that references the project base path (most likely ../node_modules). It has a typeRoots that picks ../node_modules/cypress/types before ..***@***.*** to ensure Cypress gets resolved first. Maybe include manually references ../node_modules/cypress/types as well.
I'll try this out and post back.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I have done some experimentation. Here's what works:
{
/* ... */
"types" : ["mocha"] // or "jest" or any other global module your project needs.
/* ... */
}
{
"extends": "../tsconfig",
"compilerOptions": {
"baseUrl": "../node_modules" // needed if your tests import npm modules
},
"include": [
"../node_modules/cypress/types",
"**/*.ts"
]
} Cypress seems to handle TypeScript just fine without any extra configuration, so the |
@kirjai, will that solve your issue? |
I have made https://github.com/bahmutov/test-add-typescript-to-cypress where I have both Jest and Cypress and by having separate |
@bahmutov thanks for providing the repo i checked it out and from what i can see, it works not because of the types isolation, but because of the And if I add In my case, i don't see any problems with enabling that flag, so that solution works for me 👍 thanks for taking the time to investigate this :) However, if separating |
@kirjai You are right that separating From https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types
I don't think there is an ideal solution. Cypress uses globals for convenience (no
I think skipping lib checks is the easiest solution with the least overhead. It also solves issues like |
@NicholasBoll thank you, there are some great suggestions there. Totally understand and agree with everything you've said 👍 |
Confirmed, it was skipLibCheck I added to get around Jest "Set" problem. Ok, so the recommended solution is ultimately {
"compilerOptions": {
"skipLibCheck": true
}
} in the root |
why not make |
Hi, can we make this a bit more alive? I see this as big issue and moving mocha to peer dependency as the best option - i just spent non-trivial time now to define the types in app |
I just got bitten by this... I have Jest for unit tests written in TypeScript, and I just added in Cypress but have my Cypress tests kept as the default I have tried everything listed in this issue as well as other issues and repos:
This is a serious issue and it should be reopened @bahmutov I was able to fix this by doing the following: {
"compilerOptions": {
"types": [],
"skipLibCheck": true,
"paths": {
"chai": ["./noop.d.ts"]
}
}
} In the root you need to create an empty file called Super not ideal, but it got me out of a bind short of not using Cypress at all. |
cypress ships mocha, which declares e.g. `describe` on a top level, as does jest. unfortunately their types are incompatible, forcing us to either resort to whitelisting types (which is tedious) or blindly trusting .d.ts-files. to learn more, you might want to look here: cypress-io/cypress#1087
…est types we now trust .d.ts-files blindly, mostly because the mocha shipped by cypress conflicts with jest otherwise. an alternative approach would be to whitelist @types per `"types": ["jest", "graphql", ...],`, but as this introduces a high chance of forgetting to add new libs here, we stick with skipLibCheck. ------------------- to learn more, you might want to look here: cypress-io/cypress#1087
we now trust .d.ts-files blindly, mostly because the mocha shipped by cypress conflicts with jest otherwise. an alternative approach would be to whitelist @types per `"types": ["jest", "graphql", ...],`, but as this introduces a high chance of forgetting to add new libs here, we stick with skipLibCheck. ------------------- to learn more, you might want to look here: cypress-io/cypress#1087
we now trust .d.ts-files blindly, mostly because the mocha shipped by cypress conflicts with jest otherwise. an alternative approach would be to whitelist @types per `"types": ["jest", "graphql", ...],`, but as this introduces a high chance of forgetting to add new libs here, we stick with skipLibCheck. ------------------- to learn more, you might want to look here: cypress-io/cypress#1087
Why is this issue closed? Doesn't feel like it's solved, at all. |
We are trying to move all |
we now trust .d.ts-files blindly, mostly because the mocha shipped by cypress conflicts with jest otherwise. an alternative approach would be to whitelist @types per `"types": ["jest", "graphql", ...],`, but as this introduces a high chance of forgetting to add new libs here, we stick with skipLibCheck. ------------------- to learn more, you might want to look here: cypress-io/cypress#1087
@Vheissu You did a lot of things that should work. Be sure to restart your TS language service after each change as it is sometimes not picked up. In VS Code it is "Restart TS" something in the command palette. This is a hard problem and I'm glad the Cypress team is working to fix the issue and reduce the developer setup burden. |
we now trust .d.ts-files blindly, mostly because the mocha shipped by cypress conflicts with jest otherwise. an alternative approach would be to whitelist @types per `"types": ["jest", "graphql", ...],`, but as this introduces a high chance of forgetting to add new libs here, we stick with skipLibCheck. ------------------- to learn more, you might want to look here: cypress-io/cypress#1087
None of the solutions which @Vheissu described were working for me, including their last one. The thing that finally got my project working was adding the include tag: {
"compilerOptions": {
...
},
"include": [
"./node_modules/@types/jest"
],
...
} Not sure why none of the other solutions didn't work for my project, but just thought I would put this here in case somebody else is having this issue as well. |
This PR will likely fix these issues without needing the workaround #3425 |
Worked for me by adding |
…yment of a firebase cloud function. Had to add skipLibCheck : true to main tsconfig.ts file for success per cypress-io/cypress#1087
Not sure if still relevant but I came across this problem and fixed it via adding: then |
Yet another fix, in case someone finds it useful. I had confict issues with global types. The issue I had was that after installing Cypress, suddenly my Angular specs started complaining because the My (hacky) fix was adding this to the main
I did that because you can only |
I ended up with this solution: |
Adding |
Still having this issue, what is supposed to solve it? |
@mi-mazouz Yes, this was meant to be fixed as part of #3425 in 3.2.0. 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. |
@jdtzmn solution worked for me |
The issue specifically reappeared after latest update to 4.4.1, is there any change that could have affected this? Will try to produce a repro later. |
Unfortunately, I didn't have the option to exclude Cypress from my compiled files ( I need to import the run method ). I solved by overriding the types that Cypress was using to override my types: declare namespace Chai {
export type ExpectStatic = jest.Expect;
}
declare namespace Mocha {
export type TestFunction = jest.It;
} |
It's sad that this has no universal fix. Tried all the solutions and none worked |
The joanllenas posted worked for me :) |
The
package.json
usessave-exact=true
. I didn't really notice this when I added type for Cypress-wrapped types, but it can causes issues if a type definition defined global variables (you can't duplicate global declarations). The issue I'm seeing is in@types/chai
.It looks like Cypress depends on
chai@^3.5.0
(Chai is at 4 now - looks likenested
was added). A project could also use chai at a different version - normally not a problem as bothnpm
andyarn
will embed on conflict detection. But TypeScript won't handle this conflict as gracefully for type definitions. I guess there are a few options to fix this.*
^3.5.0 || ^4.0.0
yarn
, you can just override using a resolution: https://yarnpkg.com/lang/en/docs/selective-version-resolutions/@types/chai
as a dependencyEither dependency version string change should prevent
yarn
ornpm
from detecting a conflict and flatten the dependency.Personally I think handling
3.5+
is okay. I can open an issue later. There is a workaround (I'm using yarn, so it will allow resolution overrides).Is this a Feature or Bug?
Bug
How to reproduce:
If your application uses TypeScript and you depend on
@types/chai
in any version other than4.0.8
Additional Info (images, stack traces, etc)
The text was updated successfully, but these errors were encountered: