code-coverage icon indicating copy to clipboard operation
code-coverage copied to clipboard

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

Open jhpedemonte opened this issue 4 years ago • 3 comments

Logs and screenshots

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

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

Versions

  • What is this plugin's version? If this is NOT the latest released version can you try the latest version, please?

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

  • If the plugin worked before in version X, but stopped after upgrading to version Y, please try the released versions between X and Y to see where the breaking change was.
  • What is Cypress version?

"cypress": "4.10.0"

  • What is your operating system?

RHEL

  • What is the shell?

sh

  • What is the Node version?

12.14.1 (Using Docker image cypress-included:4.10.0

  • What is the NPM version?

🤷

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).

  • When running tests, if you open the web application in regular browser, and open DevTools, do you see window.__coverage__ object? Can you paste a screenshot?
  • Is there .nyc_output folder? Is there .nyc_output/out.json file. Is it empty? Can you paste at least part of it so we can see the keys and file paths?
  • Do you have any custom NYC settings in package.json (nyc object) or in other NYC config files
  "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"
    ]
  }
  • Do you run Cypress tests in a Docker container?

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 avatar Jul 21 '20 21:07 jhpedemonte

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%.

jhpedemonte avatar Jul 21 '20 22:07 jhpedemonte

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

image

inacior avatar Sep 18 '20 23:09 inacior

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

cri-us avatar Jun 28 '22 13:06 cri-us

is there any solution to this ?

VendenIX avatar Jun 28 '23 10:06 VendenIX

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.

mike-plummer avatar Jun 28 '23 16:06 mike-plummer