-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Editors are unable to properly locate types for spec files #816
Comments
hi @stijnvn somehow the same on my side. I did not use jest specific matchers like said here (and you are using jest-marbles?) that is why I did not run into issues concerning that - expect for the intellisense in vscode. I get I think it is a vscode issue, shouldn't it respect the do you have a matcher at hand from pure |
... and are you using a vscode extension for jest? just wondering, I use vscode-jest, but not very actively at the moment ... |
I'm not using any jest related vscode extensions. I'm using jest-marbles. It seems to me that vsode only looks after |
thx for the info about the extension. I can confirm that vscode seems to only check a |
tried to explicitly
and at the named identifiers
The link points to I thought if I stick to use imports like above this name clashing could not happen. Any thoughts on that? |
I am experiencing similar problem but also when running tests I get 'TypeError: expect(...).toBeObservable is not a function'. Do you experience it only with vscode or when running as well? I have created workspace using nx 6.4.0. |
Webstorm has this issue as well |
you need to uninstall jasmine and @types/jasmine to have correct type in your IDE. or specify the types config in tsconfig.json to include jest |
hi @sandangel you will need adding |
of course, you should not use protractor either. use cypress for that ^^ |
... but renaming |
Hi, is really the only solution to rename |
Hi all, So we've been looking into and discussing this issue. Thank you for all the debugging in this thread. I would like to generalize this issue to encompass #892 as well. @skydever Was correct with the two typescript issues. There are two ways to fix and could (but not necessarily) involve some significant changes to the workspace. Basically, the constraints are the following:
We have seen large monorepos use both solutions and are not sure which one to go with for the Nx workspace. You can use either one of the "fixes" above as you wish. We would like to hear what the community thinks is a better fix. |
@FrozenPandaz What about the workaround of adding |
@FrozenPandaz appending |
This is interesting. Do you know how this works? There are projects which will not have the test-setup.ts because it does not require it. |
@FrozenPandaz any insights from how you've set up new apps with cypress in nx 7.0? Encountered the issue when updating nx of an existing workspace to 7.0.0, so I'd imagine you've made it compatible for new 7.0.0 applications. |
We've discussed this issue and the better solution seems to be adding Adding I will also be writing a page for this in the wiki to explain more. (Link TBD) |
Where can I find the documentation? |
Adding |
Still same problem using Jasmine + Cypress in VS Code. : |
@Stronhold did you include a tsconfig.json file inside your cypress folder? https://docs.cypress.io/guides/tooling/typescript-support.html#Configure-tsconfig-json |
Yes, I do have. In fact it is created by the schematic |
@danielgeri @Stronhold I'm having the same issue. I included the tsconfig in the cypress folder but still get |
tsconfig inside cypress folder will affect cypres spec files but not existing files for karma unit tests. |
Could you show us how you did separate cypress and your main project ? |
There is also one more "workaround", just add empty import statement inside .spec.ts file like this: import { } from 'jasmine'; and methods such as .toHaveBeenCalled, .toBeTruthy and all jasmine.Matchers should be recognised. 🔨 |
Thanks sanidz but I still get errors using the empty import. The only time vscode picks up correctly jasmine is when I uninstall cypress package. |
@AltarBeastiful I excluded the cypress folder from the root tsconfig.json file and that fixed it for me |
Adding an exclude works, in my root tsconfig.json I have:
Thanks ! I'll open a PR to cypress doc to document this. |
Adding Does it work for anyone else ? |
I created a file in
but it does not help, has there maybe something changed with nx 8.4.3? |
Fix is working for me in 8.4.3 |
It does for me (in VSCode). Thanks! |
For those of you trying out this solution, I also had to add |
@maximedupre could you give more context? could you post your |
This is a nightmare. |
Just started seeing this issue in Jest test files after upgrading to Cypress 10.
Seems this is acknowledged in cypress-io/cypress#22059 (comment) with a workaround, though I'm not sure why my Jest test files in libraries would be importing Cypress types from a different part of the workspace. This concerns me for performance reasons as well. Might create a separate issue with minimal repro for this one. EDIT: Maybe Nx could apply changes proposed in cypress-io/cypress-documentation#4559 to resolve the new issues since Cypress 10? |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
Editors use the next highest
tsconfig.json
to provide intellisense and thus are unable to grab the appropriate types.Expected Behavior
Types are attainable by editors/
tsserver
to properly provide intellisense in the workspace.Background
The constraints are the following:
Jest, Jasmine, and Chai (through cypress) all define global typings (expect, describe, it) which conflict with each other
a. The only way to workaround here is to delete the typings you do not want.
b. This is most likely not the approach we want to take here
VSCode (tsserver) uses the next highest tsconfig.json to provide intellisense in a .ts file.
a. One fix for this, we could generate a tsconfig.json along with tsconfig.app.json/tsconfig.lib.json/tsconfig.e2e.json and tsconfig.spec.json. That file would only be used by the editor and not targetted by any tools. However, I realize that is a lot of configuration.
b. The other option is to use /// <reference types="..." at the top of each file. This is a more granular approach and basically allows using specified types in the particular file. This would have to be added to every file (possibly even application code). We could generate this based on the project where code is being generated but you would have to maintain this when manually creating files (jest projects get a reference to jest types, karma projects get references to jasmine types).
We have seen large monorepos use both solutions and are not sure which one to go with for the Nx workspace. You can use either one of the "fixes" above as you wish. We would like to hear what the community thinks is a better fix.
Original Issue
Visual Studio Code detects Jasmine instead of Jest.
When I try to use the
toBeObservable
matcher, I get the following error message:The problem seems to be related with how Visual Studio Code resolves type definitions. It does not use the
tsconfig.spec.json
but still seems to use the imports defined intest-setup.ts
. As a workaround I have added an import for Jest on top oftest-setup.ts
:For some reason, tests of nx application of the type
node-app
are correctly type-checked as Jest suites by Visual Studio Code.Can this be fixed in nx? Or should this be fixed in Visual Studio Code?
The text was updated successfully, but these errors were encountered: