cypress-io / code-coverage

Saves the code coverage collected during Cypress tests
MIT License
430 stars 108 forks source link

Unable to generate Code Coverage report - 'Cannot find coverage file' #756

Open nathan5x opened 10 months ago

nathan5x commented 10 months ago

I recently upgraded the Cypress version to 13.6.1 from 9.6.x and the coverage reports stopped working. Followed all the steps mentioned in this guide https://docs.cypress.io/guides/tooling/code-coverage#E2E-code-coverage

Debug Log

code-coverage combined NYC options { 'report-dir': './cypress/coverage/ui', reporter: [ 'lcov', 'clover', 'json', 'json-summary' ], extension: [ '.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx' ], excludeAfterRemap: false, 'temp-dir': './cypress/coverage/temp' } +0ms

Coverage failure message

Cannot find coverage file /ui-workspace/cypress/coverage/temp/out.json
Skipping coverage report

Versions

Here is some additional information cypress.config.ts file

....
e2e: {
    setupNodeEvents(on, config) {
      require('./cypress/plugins/index.js')(on, config);
      return config;
    },
  }]
...

cypress/plugins/index.js file

const cypressTypeScriptPreprocessor = require('./cy-ts-preprocessor');

module.exports = (on, config) => {
  if (config && config.env && config.env.recordCodeCoverage) {
    on('file:preprocessor', cypressTypeScriptPreprocessor);

    // enable code coverage collection
    require('@cypress/code-coverage/task')(on, config);
  }

  // IMPORTANT to return the config object
  // with the any changed environment variables
  return config;
};

cypress/support/e2e.ts file

import '@cypress/code-coverage/support';

Any help is appreciated.

Thanks, Nathan

tamitai-sovrn commented 10 months ago

I am also having this issue when using the github action v6 with chrome in CI and when using cypress run with chrome locally. cypress open does generate .nyc_output as well as electron in an environment.

chrome 120 cypress 13.6.2 cypress/code-coverage 3.12.15

gigaSproule commented 9 months ago

I got the same issue when I migrated from @cypress/code-coverage 3.12.11 to 3.12.15 via renovate bot. I tried 3.12.12 and it also had the same issue, so the last ok version seems to be 3.12.11. Interestingly, it is only in docker for me that is an issue. If I run it outside of docker on Mac OS, it works perfectly fine.

I don't currently have a non-Mac setup to try this on anything else, so I have no idea if this is a Mac specific issue or something wider. It is worth noting that the same issue appears on both an M1 Mac and an Intel Mac. It does pass on our GitLab CI/CD, which is running docker images on a kubernetes cluster, so it does seem to suggest it is more Mac specific that is an issue, or at least something to do with Docker Desktop.

Edit: Noticed there is 3.12.18 which seems to work fine for me, so maybe worth upgrading?

MBernardAdobe commented 6 months ago

For me the answer was this, https://github.com/cypress-io/code-coverage/issues/361#issuecomment-1682684837

Might not be the answer for everyone, but if coverage is being skipped only in one place but works fine in others, possibly the one place is not on a path that gets Istanbul instrumentation in your app?

daniel-koudouna commented 5 months ago

I got the same issue when I migrated from @cypress/code-coverage 3.12.11 to 3.12.15 via renovate bot. I tried 3.12.12 and it also had the same issue, so the last ok version seems to be 3.12.11. Interestingly, it is only in docker for me that is an issue. If I run it outside of docker on Mac OS, it works perfectly fine.

I don't currently have a non-Mac setup to try this on anything else, so I have no idea if this is a Mac specific issue or something wider. It is worth noting that the same issue appears on both an M1 Mac and an Intel Mac. It does pass on our GitLab CI/CD, which is running docker images on a kubernetes cluster, so it does seem to suggest it is more Mac specific that is an issue, or at least something to do with Docker Desktop.

Edit: Noticed there is 3.12.18 which seems to work fine for me, so maybe worth upgrading?

I was facing the same issue. In addition to downgrading to action v5, I was also using a custom image (cypress:browsers) When I switched to ubuntu-latest (this is in github CI), the code coverage was generated fine.

Baluditor commented 1 month ago

I'm also facing the same issue. The code gets instrumented when I run the E2E test locally, but not in the GitHub CI. Tried all solutions mentioned above, no dice. Any ide when this will be fixed or how to get around it?