Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bennycode
Copy link

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

Coverage Status

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

@motin
Copy link

motin commented May 19, 2018

This was already proposed to be fixed in
#819
#816
and
4a5e92c

(None of them merged)

@keenaudio
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants