cypress-io / code-coverage

Saves the code coverage collected during Cypress tests
MIT License
422 stars 105 forks source link

Generated HTML has errors for some files (0% coverage even though showing non-zero items) #279

Closed jhpedemonte closed 1 year ago

jhpedemonte commented 3 years ago

Logs and screenshots

Screen Shot 2020-07-21 at 4 22 37 PM

Screen Shot 2020-07-21 at 4 22 53 PM

Versions

"@cypress/code-coverage": "^3.8.1"

"cypress": "4.10.0"

RHEL

sh

12.14.1 (Using Docker image cypress-included:4.10.0

🤷

Use craco to customize create-react-app's webpack config to add the babel-plugin-instanbul plugin. Similar to what is done by instrument-cra but building instead of running in dev mode (similar to https://github.com/cypress-io/instrument-cra/issues/135#issuecomment-656164839).

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "all": true,
    "exclude": [
      "cypress/**",
      "**/__fixtures__/**",
      "**/__mocks__/**",
      "**/__tests__/**"
    ],
    "report-dir": "./coverage-cypress",
    "temp-dir": "./coverage-cypress/.nyc_output",
    "reporter": [
      "text-summary",
      "json",
      "html"
    ]
  }

Yes, custom image based on cypress-included:4.10.0.

Describe the bug

After building an instrumented build and running Cypress tests, the generated HTML code coverage report shows some files with 0% coverage but actually having some non-zero covered code (see screenshots above).

When viewing one such file in the HTML report, it will show an error instead of file contents:

Cannot read property 'locations' of undefined
TypeError: Cannot read property 'locations' of undefined
    at /Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-reports/lib/html/annotator.js:127:50
    at Array.forEach ()
    at annotateBranches (/Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-reports/lib/html/annotator.js:125:33)
    at annotateSourceCode (/Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-reports/lib/html/annotator.js:233:9)
    at HtmlReport.onDetail (/Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-reports/lib/html/index.js:409:33)
    at Visitor.value (/Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-lib-report/lib/tree.js:38:38)
    at ReportNode.visit (/Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-lib-report/lib/tree.js:88:21)
    at /Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-lib-report/lib/tree.js:92:19
    at Array.forEach ()
    at ReportNode.visit (/Users/pedemonte/projects/watson-discovery/discovery-tooling/node_modules/istanbul-lib-report/lib/tree.js:91:28)
jhpedemonte commented 3 years ago

Removing "all": true from the config makes this work better. Here are the same tests from the screenshot in description:

Screen Shot 2020-07-21 at 5 27 29 PM

But now this is missing a few files (like CollectionMetadata) which were in fact 0%.

inacior commented 3 years ago

I have same problem, where one file is not coverage, and his 0% coverage not impacts on final project coverage

image

cri-us commented 2 years ago

Is there a any solution for this? @jhpedemonte @inacior @bahmutov same problem here, i tried to remove "all": true but its happens to some file missing, which i already use it inside

"nyc": {
    "report-dir": "cypress-coverage",
    "extends": "@istanbuljs/nyc-config-typescript",
    "all": true,
    "include": [
      "frontend/javascripts/react/**/**.{ts,tsx}",
      "frontend/javascripts/spa/**/**.{ts,tsx}"
    ]
  }

Screenshot from 2022-06-28 16-13-18

**

Screenshot from 2022-06-28 16-15-26

VendenIX commented 1 year ago

is there any solution to this ?

mike-plummer commented 1 year ago

Hi @VendenIX . This issue is very old and, unfortunately, the original reproduction case is no longer valid. If you have a complete reproduction of this issue against the latest version of Cypress and this plugin we'd be happy to investigate - please open a new issue with all requested template items filled out and we'll take a look.