e2e shared libraries with Cypress imports break Jest types in other libraries in VSCode #12965
Labels
outdated
scope: testing tools
Issues related to Cypress / Jest / Playwright / Vitest support in Nx
type: bug
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 withProperty '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 intsconfig.base.json
and pull in dependencies that include Cypress types without causing Jest types to break in VSCode (or generally).Steps to Reproduce
libs/products/home-page/src/lib/home-page/home-page.component.spec.ts
in VSCode and see the Jest types load correctlylibs/shared/e2e-utils/src/lib/shared-e2e-utils.ts
and addimport { defineConfig } from 'cypress';
at the top of the filelibs/products/home-page/src/lib/home-page/home-page.component.spec.ts
and see the Jest types are now broken@badeball/cypress-cucumber-preprocessor
and havingimport { defineStep } from '@badeball/cypress-cucumber-preprocessor';
at the top oflibs/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 samepaths
fromtsconfig.base.json
, remove e2e library paths fromtsconfig.base.json
, and update the e2e shared and test libraries to extend thetsconfig.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 totsconfig.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
(any10.x
+ version, it seems)Nx: I've reproduced on
14.x
and15.x
The text was updated successfully, but these errors were encountered: