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

When generating cypress component tests in nx 19.7.3 - nx library imports are not resolved #27921

Open
1 of 4 tasks
astrodomas opened this issue Sep 16, 2024 · 0 comments
Open
1 of 4 tasks
Assignees
Labels
scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@astrodomas
Copy link

astrodomas commented Sep 16, 2024

Current Behavior

Just tested this on a fresh nx monorepo setup.

  1. Generate 2 @nx/next libraries (lest say lib1 and lib2)
  2. Make an import of lib2 in lib1.
  3. Generate @nx/next component-configuration
  4. Run component tests
  5. Get error:
    Error: The following error originated from your test code, not from Cypress.

 > Cannot find module '@my/lib2'
  1. If the import is removed it runs successfully.

Expected Behavior

When importing a local monorepo library - cypress component test should resolve imports.

GitHub Repo

No response

Steps to Reproduce

  1. Generate 2 @nx/next libraries (lest say lib1 and lib2)
  2. Make an import of lib2 in lib1.
  3. Generate @nx/next component-configuration
  4. Run component tests
  5. Get error:
    Error: The following error originated from your test code, not from Cypress.

 > Cannot find module '@my/lib2'
  1. If the import is removed it runs successfully.

Nx Report

$ npx nx report

 NX   Report complete - copy this into the issue template

Node           : 20.9.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 9.5.1

nx                 : 19.7.3
@nx/js             : 19.7.3
@nx/jest           : 19.7.3
@nx/linter         : 19.7.3
@nx/eslint         : 19.7.3
@nx/workspace      : 19.7.3
@nx/cypress        : 19.7.3
@nx/devkit         : 19.7.3
@nx/eslint-plugin  : 19.7.3
@nx/next           : 19.7.3
@nx/react          : 19.7.3
@nrwl/tao          : 19.7.3
@nx/web            : 19.7.3
@nx/webpack        : 19.7.3
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/next/plugin
@nx/cypress/plugin
@nx/eslint/plugin
@nx/jest/plugin
@nx/webpack/plugin

Failure Logs

> nx run my-lib:component-test

> cypress run --component



DevTools listening on ws://127.0.0.1:64154/devtools/browser/f0e26e5e-eb27-4762-91cb-efc19634bd90
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://127.0.0.1:8080/
<i> [webpack-dev-server] Content not from webpack is served from 'C:\Users\DominykasAstrauskas\repos\org\libs\my-lib\public' directory
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin
Entrypoint main [big] 562 KiB = runtime.js 33.3 KiB main.js 528 KiB
chunk (runtime: runtime) cypress-support-file.css, cypress-support-file.js (cypress-support-file) 1.71 KiB (javascript) 75 bytes (css/mini-extract) [rendered]
chunk (runtime: runtime) main.js (main) (id hint: vendors) 183 KiB [initial] [rendered] reused as split chunk (cache group: defaultVendors)
chunk (runtime: runtime) runtime.js (runtime) 9.39 KiB [entry] [rendered]
chunk (runtime: runtime) spec-0.css, spec-0.js (spec-0) 1.53 KiB (javascript) 76 bytes (css/mini-extract) [rendered]        
chunk (runtime: runtime) vendors-node_modules_cypress_react18_dist_cypress-react_esm-bundler_js.js (id hint: vendors) 1.02 MiB [rendered] split chunk (cache group: defaultVendors)
chunk (runtime: runtime) vendors-node_modules_react_index_js.js (id hint: vendors) 85.7 KiB [rendered] split chunk (cache group: defaultVendors)
chunk (runtime: runtime) vendors-node_modules_react_jsx-dev-runtime_js.js (id hint: vendors) 41.3 KiB [rendered] split chunk (cache group: defaultVendors)

ERROR in ./src/lib/my-lib.cy.tsx 5:0-34
Module not found: Error: Can't resolve '@my/lib2' in 'C:\<myorg>\org\libs\my-lib\src\lib'

webpack compiled with 1 error (3e8662c3985d689b)
No errors found.

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        13.14.2                                                                        │
  │ Browser:        Electron 118 (headless)                                                        │
  │ Node Version:   v20.9.0 (C:\Program Files\nodejs\node.exe)                                     │
  │ Specs:          1 found (my-lib.cy.tsx)                                                        │
  │ Searched:       **/*.cy.{js,jsx,ts,tsx}                                                        │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  my-lib.cy.tsx                                                                   (1 of 1)


  1) An uncaught error was detected outside of a test

  0 passing (255ms)
  1 failing

  1) An uncaught error was detected outside of a test:
     Error: The following error originated from your test code, not from Cypress.

  > Cannot find module '@my/lib2'

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.
      at webpackMissingModule (http://localhost:8080/__cypress/src/spec-0.js:37:50)
      at 823 (http://localhost:8080/__cypress/src/spec-0.js:37:133)
      at Function.__webpack_require__ (http://localhost:8080/__cypress/src/runtime.js:23:42)




  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      0                                                                                │
  │ Failing:      1                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  1                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     0 seconds                                                                        │
  │ Spec Ran:     my-lib.cy.tsx                                                                    │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Screenshots)

  -  C:\<myOrg>\dist\cypress\libs\my-lib\screenshots\my-l     (1280x720)
     ib.cy.tsx\An uncaught error was detected outside of a test (failed).png


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✖  my-lib.cy.tsx                            252ms        1        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✖  1 of 1 failed (100%)                     252ms        1        -        1        -        -

Warning: command "cypress run --component" exited with non-zero status code
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— 

 NX   Ran target component-test for project my-lib (16s)

   ×  1/1 failed
   √  0/1 succeeded [0 read from cache]

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@astrodomas astrodomas changed the title When generating cypress component tests - monorepo local library imports are not resolved When generating cypress component tests in nx 19.7.3 - monorepo local library imports are not resolved Sep 17, 2024
@astrodomas astrodomas changed the title When generating cypress component tests in nx 19.7.3 - monorepo local library imports are not resolved When generating cypress component tests in nx 19.7.3 - nx library imports are not resolved Sep 17, 2024
@jaysoo jaysoo added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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