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

e2e shared libraries with Cypress imports break Jest types in other libraries in VSCode #12965

Closed
wrslatz opened this issue Nov 3, 2022 · 2 comments
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@wrslatz
Copy link
Contributor

wrslatz commented Nov 3, 2022

Current Behavior

When we have a shared library for e2e utilities that have a paths alias in tsconfig.base.json, the Jest types in .spec.ts unit tests in other libraries break in VSCode with
Property 'toEqual' does not exist on type 'Assertion'.

This has a large developer experience impact for VSCode users. From what I can see, this only impacts VSCode but I'm not familiar enough with VSCode TypeScript support to raise an issue there or even find if this is a known issue. This does not impact running Jest via Nx or jest directly.

Expected Behavior

e2e shared libraries can have paths entries in tsconfig.base.json and pull in dependencies that include Cypress types without causing Jest types to break in VSCode (or generally).

Steps to Reproduce

  1. Clone https://github.com/nrwl/nx-examples
  2. Open libs/products/home-page/src/lib/home-page/home-page.component.spec.ts in VSCode and see the Jest types load correctly
  3. Open libs/shared/e2e-utils/src/lib/shared-e2e-utils.ts and add import { defineConfig } from 'cypress'; at the top of the file
  4. Go back to libs/products/home-page/src/lib/home-page/home-page.component.spec.ts and see the Jest types are now broken
  5. Installing and using other dependencies that pull in Cypress types also causes the issue. In our case, using @badeball/cypress-cucumber-preprocessor and having import { defineStep } from '@badeball/cypress-cucumber-preprocessor'; at the top of libs/shared/e2e-utils/src/lib/shared-e2e-utils.ts also causes the issue.

Additional Info

Removing imports that bring in Cypress types from the shared library or removing the paths alias for the e2e library make the type errors in VSCode go away.

Another workaround is to skip Jest global types and import the types directly
import {expect, jest, test} from '@jest/globals';

Another workaround that maintains global types that we applied is to create a tsconfig.cypress.json, copy all of the same paths from tsconfig.base.json, remove e2e library paths from tsconfig.base.json, and update the e2e shared and test libraries to extend the tsconfig.cypress.json. This is all a manual process to manage, requires additional work on top of the current generators to setup for new libraries, and I'm not sure it works with Nx affected analysis on changes to tsconfig.cypress.json, etc.

Related issues
#892
#816

cypress-io/cypress#22059
cypress-io/cypress#6156
microsoft/TypeScript#22331

Failure Logs

N/A

Environment

VSCode: 1.73.0
TypeScript: typescript
Cypress: 10.7.0 (any 10.x+ version, it seems)
Nx: I've reproduced on 14.x and 15.x

@AgentEnder AgentEnder added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Nov 3, 2022
@barbados-clemens barbados-clemens self-assigned this Nov 5, 2022
@barbados-clemens
Copy link
Contributor

this happens due to the tsconfig including both cypress and jest files in it's program.

this should be fixed in 61d7d74

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

3 participants