nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.53k stars 2.35k forks source link

cypress e2e can not generate coverage report #17587

Closed nnsay closed 1 year ago

nnsay commented 1 year ago

Current Behavior

cypress e2e test can generate the coverage report files

Expected Behavior

cypress e2e test can not generate the coverage report files

GitHub Repo

https://github.com/nnsay/nx-example

Steps to Reproduce

git clone https://github.com/nnsay/nx-example

yarn install

yarn nx run tools:e2e

I add the e2e in the existing Nx project which name is tools.

Nx Report

Node   : 16.20.0
   OS     : darwin arm64
   yarn   : 1.22.19
   Hasher : Native

   nx                 : 16.3.2
   @nx/js             : 16.3.2
   @nx/jest           : 16.3.2
   @nx/linter         : 16.3.2
   @nx/workspace      : 16.3.2
   @nx/cypress        : 16.3.2
   @nx/devkit         : 16.3.2
   @nx/esbuild        : 16.3.2
   @nx/eslint-plugin  : 16.3.2
   @nx/node           : 16.3.2
   @nx/storybook      : 16.3.2
   @nrwl/tao          : 16.3.2
   @nx/vite           : 16.3.2
   typescript         : 5.0.4
   ---------------------------------------
   Local workspace plugins:
         @nnsay/tools

Failure Logs

> nx run tools:e2e  [existing outputs match the cache, left as is]

info => Starting manager..
╭────────────────────────────────────────────────╮
│                                                │
│   Storybook 7.0.20 for react-vite started      │
│   99 ms for manager and 3.65 s for preview     │
│                                                │
│    Local:            http://localhost:4400/    │
│    On your network:  http://localhost:4400/    │
│                                                │
╰────────────────────────────────────────────────╯
[17562:0614/154045.352800:ERROR:node_bindings.cc(279)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.

DevTools listening on ws://127.0.0.1:58720/devtools/browser/5b992623-7737-4baf-ad90-4743dba6d284
{
  videosFolder: '../../dist/cypress/libs/tools/videos',
  screenshotsFolder: '../../dist/cypress/libs/tools/screenshots',
  video: true,
  chromeWebSecurity: false,
  fileServerFolder: '.',
  supportFile: 'cypress/support/e2e.ts',
  specPattern: 'cypress/**/*.cy.{js,jsx,ts,tsx}',
  fixturesFolder: 'cypress/fixtures'
}
{
  videosFolder: '../../dist/cypress/libs/tools/videos',
  screenshotsFolder: '../../dist/cypress/libs/tools/screenshots',
  video: true,
  chromeWebSecurity: false,
  fileServerFolder: '.',
  supportFile: 'src/support/e2e.ts',
  specPattern: 'src/**/*.cy.{js,jsx,ts,tsx}',
  fixturesFolder: 'src/fixtures',
  baseUrl: 'http://localhost:4400'
}

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

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        12.14.0                                                                        │
  │ Browser:        Electron 106 (headless)                                                        │
  │ Node Version:   v16.20.0 (/Users/wangjian/.volta/tools/image/node/16.20.0/bin/node)            │
  │ Specs:          1 found (app.cy.ts)                                                            │
  │ Searched:       cypress/**/*.cy.{js,jsx,ts,tsx}                                                │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

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

  Running:  app.cy.ts                                                                       (1 of 1)

  albedo-drawer
Cannot find coverage file /Users/wangjian/github/nnsay/nnsay/libs/tools/.nyc_output/out.json
Skipping coverage report
    ✓ basic (3382ms)

  1 passing (3s)

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        true                                                                             │
  │ Duration:     3 seconds                                                                        │
  │ Spec Ran:     app.cy.ts                                                                        │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

  (Video)

  -  Started compressing: Compressing to 32 CRF                                                     
  -  Finished compressing: 0 seconds                                                 

  -  Video output: /Users/xxx/github/nnsay/nnsay/dist/cypress/libs/tools/videos/app.cy.ts.mp4

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

  (Run Finished)

       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  app.cy.ts                                00:03        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        00:03        1        1        -        -        -  

 ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Successfully ran target e2e for project tools (14ms)

   Nx read the output from the cache instead of running the command for 1 out of 1 tasks.

✨  Done in 0.47s.

Operating System

Additional Information

No response

Coly010 commented 1 year ago

Hey there! :)

There are two problems with your current setup.

  1. As stated in the Cypress Documentation, you need instrument your code yourself for the code coverage to take effect: https://docs.cypress.io/guides/tooling/code-coverage#Instrumenting-code

  2. You use vite to build your cypress and storybook setup. Using istanbul to instrument your code with vite requires using vite-istanbul-plugin but there's an open issue on that plugin with compatibility with nx repos: https://github.com/iFaxity/vite-plugin-istanbul/issues/94

Unfortunately, these are tools that we do not control and the issues lie outside the scope of Nx. Therefore, I'm going to close this issue.

You should raise an issue on the cypress repo and follow along with the issue listed above for vite-istanbul-plugin.

nnsay commented 1 year ago

Trace the reason at: https://github.com/cypress-io/code-coverage/issues/657

github-actions[bot] commented 1 year ago

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.