code-coverage
code-coverage copied to clipboard
Generated HTML has errors for some files (0% coverage even though showing non-zero items)
Logs and screenshots
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?
🤷
- How do you instrument your application? Cypress does not instrument web application code, so you need to do it yourself.
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)
Removing "all": true
from the config makes this work better. Here are the same tests from the screenshot in description:
But now this is missing a few files (like CollectionMetadata
) which were in fact 0%.
I have same problem, where one file is not coverage, and his 0% coverage not impacts on final project coverage
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}"
]
}
******************************************************
is there any solution to this ?
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.