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

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

Closed
jhpedemonte opened this issue Jul 21, 2020 · 5 comments

Comments

@jhpedemonte
Copy link

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 cypress-io/instrument-cra#135 (comment)).

  • 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
Copy link
Author

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
Copy link

inacior commented Sep 18, 2020

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

image

@cri-us
Copy link

cri-us commented Jun 28, 2022

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
Copy link

is there any solution to this ?

@mike-plummer
Copy link

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 mike-plummer closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants