karma-runner / karma-coverage

A Karma plugin. Generate code coverage.
MIT License
770 stars 247 forks source link

TypeError: Cannot read property 'text' of undefined #341

Open andrewl-telnyx opened 7 years ago

andrewl-telnyx commented 7 years ago

not entirely sure if this is an issue with istanbul directly or karma-coverage, but i think it's an istanbul thing so i created this issue with them but you may want to look into it too:

04 10 2017 09:34:48.018:ERROR [coverage]: TypeError: Cannot read property 'text' of undefined
    at project/node_modules/istanbul/lib/report/html.js:288:53
    at Array.forEach (native)
    at annotateBranches (project/node_modules/istanbul/lib/report/html.js:255:30)
    at HtmlReport.writeDetailPage (project/node_modules/istanbul/lib/report/html.js:426:9)
    at project/node_modules/istanbul/lib/report/html.js:489:26
    at SyncFileWriter.writeFile (project/node_modules/istanbul/lib/util/file-writer.js:57:9)
    at FileWriter.writeFile (project/node_modules/istanbul/lib/util/file-writer.js:147:23)
    at project/node_modules/istanbul/lib/report/html.js:488:24
    at Array.forEach (native)
    at HtmlReport.writeFiles (project/node_modules/istanbul/lib/report/html.js:482:23)
    at project/node_modules/istanbul/lib/report/html.js:484:22
    at Array.forEach (native)
    at HtmlReport.writeFiles (project/node_modules/istanbul/lib/report/html.js:482:23)
    at HtmlReport.writeReport (project/node_modules/istanbul/lib/report/html.js:566:14)
    at writeReport (project/node_modules/karma-coverage/lib/reporter.js:68:16)
    at project/node_modules/karma-coverage/lib/reporter.js:296:11

the problem is:

text = structuredText[startLine].text;

i guess it assumes structuredText[startLine] is always going to be a thing, and apparently at least once it is not a thing? I don't know how you can reproduce it; just let me know what you need that i can provide and i'll provide it.

johnjbarton commented 7 years ago

Presumably karma-coverage is giving istanbul html reporter bad data and istanbul has poor error recovery for that case.

Please add logging to your copy of karma-reporter to dump the collector for reporter.writeReport(collector, true). Then see if you can sort out what input leads to the error.

chrisgbaker commented 6 years ago

Not sure of a solution, but this is happening to my repo as well, and I've traced it back to one location. I am testing a redux action that fires off an async request. In that action, there is an if/else:

 if (request.ok) {
                const data= await request.json();
                dispatch(update({id: data.id, name: data.name}));
            } else {
                throw new Error(request.status + "- " + request.statusText);
            }

For whatever reason, if I comment out the entire else block, there is no error. Strangely enough, I have to include else { ... }, not just the throw statement.

renanvalentin commented 6 years ago

I'm having a similar problem with flow and closure:

this will throw an error:

const test = (arg : string) : Function => (arg2 : string) => false;

this works fine

const test = (arg : string) : Function => {
    return (arg2 : string) => {
        return false;
    };
};

Should I open a new issue?

johnjbarton commented 6 years ago

These issues cannot be fixed in karma-coverage except by updating it to newer versions of the tools that compile your code.

ffesseler commented 6 years ago

a workaround is to use lcov reporter. It generates both lcov & html output but won't fail with the html.

vort3xxx commented 6 years ago

@ffesseler, what's the npmjs package for that called?

ffesseler commented 6 years ago

Not a npm package, juste a reporter config.