istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.62k stars 360 forks source link

Coverage fails when run with OxProject #1035

Open ochikov opened 5 years ago

ochikov commented 5 years ago

Hello everybody, When generating an html coverage report with nyc report --reporter=html I am getting the html files in a folder, but trying to open a specific file, the following error is occured:

Cannot read property 'start' of undefined
TypeError: Cannot read property 'start' of undefined
    at /Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:92:34
    at Array.forEach ()
    at annotateFunctions (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:88:26)
    at Object.annotateSourceCode (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:239:9)
    at HtmlReport.onDetail (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-reports/lib/html/index.js:269:23)
    at Visitor.(anonymous function) [as onDetail] (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:34:30)
    at ReportNode.Node.visit (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:121:17)
    at /Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:114:23
    at Array.forEach ()
    at visitChildren (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:113:32)
    at ReportNode.Node.visit (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:124:5)
    at Tree.visit (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:155:20)
    at reporter.forEach (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/index.js:454:10)
    at Array.forEach ()
    at NYC.report (/Users/ognyanchikov/Etherlime/etherlime/node_modules/nyc/index.js:453:17)
    at showCoverageResults (/Users/ognyanchikov/Etherlime/etherlime/cli-commands/etherlime-test/etherlime-coverage.js:206:13)
    at Timeout.setTimeout (/Users/ognyanchikov/Etherlime/etherlime/cli-commands/etherlime-test/etherlime-coverage.js:73:9)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5

The text table report works and shows results, but the HTML is broken.

coreyfarrell commented 5 years ago

We are unable to provide assistance without a reproduction repository.

ochikov commented 5 years ago

@coreyfarrell This is the repository: https://github.com/ochikov/nyc-report-bug

I already have coverage.json in .nyc_ouput

  1. Please run the following command: nyc report --reporter=html
  2. Check coverage html report in coverage folder.

Thank you.

coreyfarrell commented 5 years ago

How did you create this coverage.json? The fnMap objects are missing decl keys that are produced by nyc.

ochikov commented 5 years ago

I created it with a solidity coverage library: https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-coverage

The output is coverage.json file. I tried with istanbul v. 0.4.5 and the html report is working as expected.

coreyfarrell commented 5 years ago

Please report this to the 0xProject. nyc requires additional fields that were not required by istanbul@0.4.5. I'm leaving this ticket open as we need to publish a JSON schema file to document the required format of coverage files, but any actual fix to your issue would come from the 0xProject correctly imitating the current coverage format produced by NYC.

LunaPg commented 5 years ago

Do you guys have update on this issue ?

HACHIMIam commented 5 years ago

i still have the same issue guys

regevbr commented 5 years ago

I encountered the same issue, and I got it fixed by deleting the Coverage directory and running the nyc command again.

jaapz commented 5 years ago

I get this same error often, but like two out of three times that I run nyc. Every time I run the coverage reporter, I remove .nyc_output and coverage directories. My stack trace is slightly different:

Cannot read property 'start' of undefined
TypeError: Cannot read property 'start' of undefined
    at /.../node_modules/istanbul-reports/lib/html/annotator.js:53:31
    at Array.forEach ()
    at annotateStatements (/.../node_modules/istanbul-reports/lib/html/annotator.js:49:33)
    at Object.annotateSourceCode (/.../node_modules/istanbul-reports/lib/html/annotator.js:239:9)
    at HtmlReport.onDetail (/.../node_modules/istanbul-reports/lib/html/index.js:265:27)
    at Visitor. [as onDetail] (/.../node_modules/istanbul-lib-report/lib/tree.js:34:30)
    at ReportNode.Node.visit (/.../node_modules/istanbul-lib-report/lib/tree.js:114:17)
    at /.../node_modules/istanbul-lib-report/lib/tree.js:118:15
    at Array.forEach ()
    at ReportNode.Node.visit (/.../node_modules/istanbul-lib-report/lib/tree.js:117:24)

This is when I generate coverage for a TypeScript codebase using nyc. I can reliably fix this error by setting all to false in my .nycrc, but I'd rather have that set to true because the reported coverage percentage is slightly more correct.

I have checked the coverage.json files generated by our codebase and the decl fields are not missing.

@coreyfarrell should I create a new issue for this, or is it the same as this one?

coreyfarrell commented 5 years ago

@jaapz you are experiencing a different issue. Run npm i -D nyc@next to upgrade to the pre-release version which fixes this issue with all. If you need further assistance please open a new ticket with all required information.

aminnairi commented 5 years ago

Had the issue with the all property as well. Just followed the recommandations from @coreyfarrell and it totally worked. Installing the next version somehow fixed my issue.