gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 785 forks source link

Fix TypeError during HTML coverage report when "text" is undefined #881

Open bennycode opened 6 years ago

bennycode commented 6 years ago

When using the reporter of type "html", then I am getting the following error when creating a code coverage report:

ERROR [coverage]: TypeError: Cannot read property 'text' of undefined
    at D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:288:54
    at Array.forEach (<anonymous>)
    at annotateBranches (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:255:30)
    at HtmlReport.writeDetailPage (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:426:9)
    at D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:489:26
    at SyncFileWriter.writeFile (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\util\file-writer.js:57:9)
    at FileWriter.writeFile (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\util\file-writer.js:147:23)
    at D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:488:24
    at Array.forEach (<anonymous>)
    at HtmlReport.writeFiles (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:482:23)
    at D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:484:22
    at Array.forEach (<anonymous>)
    at HtmlReport.writeFiles (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:482:23)
    at HtmlReport.writeReport (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:566:14)
    at writeReport (D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\lib\reporter.js:68:16)
    at D:\dev\projects\bennyn\test-coverage\node_modules\karma-coverage\lib\reporter.js:297:11
Done in 2.93s.

Although the error above is fired, istanbul still creates a HTML report with index files. I can open them but I cannot click on links like this:

http://localhost:63342/test-coverage/coverage/browser/HeadlessChrome%200.0.0%20(Windows%2010%200.0.0)/main/MyClass.ts.html

When checking for the existence of structuredText[startLine], then I mitigate the error and istanbul creates a HTML report for me where I can see details of classes.

I don't know if that is a proper fix because I guess we should find out why structuredText[startLine] is not defined but I wanted to create awareness for this problem. At least this fix creates a coverage report in HTML for me.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.001%) to 97.524% when pulling 60a1fed523c65e188f7400b3eceb8cbdf42db457 on bennyn:patch-1 into bc84c315271a5dd4d39bcefc5925cfb61a3d174a on gotwarlost:master.

motin commented 6 years ago

This was already proposed to be fixed in https://github.com/gotwarlost/istanbul/pull/819 https://github.com/gotwarlost/istanbul/pull/816 and https://github.com/gotwarlost/istanbul/commit/4a5e92c1261bd08ce5118d01c8a05ae54fc7458b

(None of them merged)

keenaudio commented 5 years ago

Appears to be a conflict with karma-coverage, which will be loaded automatically by karma if it exists under node_modules.

npm uninstall karma-coverage and removing karma-coverage from package.json fixed the issue for me.