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 788 forks source link

BUG: error on combining reports #731

Open osher opened 8 years ago

osher commented 8 years ago

I think it has to do with one of my files has zero branches.

$ istanbul report --root ./coverage --dir ./coverage/combined --format html

> cwt-oapi-util@0.2.0 cover-combine-reports /home/developer/cwt-oapi-util
> istanbul report --root ./coverage --dir ./coverage/combined --format html

/home/developer/cwt-oapi-util/node_modules/istanbul/lib/object-utils.js:247
            for (i = 0; i < retArray.length; i += 1) {
                                    ^

TypeError: Cannot read property 'length' of undefined
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/object-utils.js:247:37
    at Array.forEach (native)
    at Object.mergeFileCoverage (/home/developer/cwt-oapi-util/node_modules/istanbul/lib/object-utils.js:244:31)
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/collector.js:71:44
    at Array.forEach (native)
    at Object.add (/home/developer/cwt-oapi-util/node_modules/istanbul/lib/collector.js:68:31)
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/command/report.js:111:27
    at Array.forEach (native)
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/command/report.js:109:19
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/util/file-matcher.js:39:20

/home/developer/cwt-oapi-util/node_modules/istanbul/lib/object-utils.js:247:

        Object.keys(second.b).forEach(function (k) {
            var retArray = ret.b[k],
                secondArray = second.b[k];
            for (i = 0; i < retArray.length; i += 1) {   //<---- the line that falls
                retArray[i] += secondArray[i];
            }
        });

So I tried to hack it:

        Object.keys(second.b).forEach(function (k) {
            var retArray = ret.b[k] || [],            // <---- proposed fix
                secondArray = second.b[k];
            for (i = 0; i < retArray.length; i += 1) {   
                retArray[i] += secondArray[i];
            }
        });

then I got:

$ istanbul report --root ./coverage --dir ./coverage/combined --format html

/home/developer/cwt-oapi-util/node_modules/istanbul/lib/object-utils.js:59
                var line = statementMap[st].start.line,
                                           ^

TypeError: Cannot read property 'start' of undefined
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/object-utils.js:59:44
    at Array.forEach (native)
    at Object.addDerivedInfoForFile (/home/developer/cwt-oapi-util/node_modules/istanbul/lib/object-utils.js:58:37)
    at Object.fileCoverageFor (/home/developer/cwt-oapi-util/node_modules/istanbul/lib/collector.js:94:15)
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/report/html.js:558:90
    at Array.forEach (native)
    at HtmlReport.writeReport (/home/developer/cwt-oapi-util/node_modules/istanbul/lib/report/html.js:557:27)
    at /home/developer/cwt-oapi-util/node_modules/istanbul/lib/reporter.js:93:20
    at Array.forEach (native)
    at Object.write (/home/developer/cwt-oapi-util/node_modules/istanbul/lib/reporter.js:87:30)

that's a little too much for me ATM... Can anybody help?

fgaleano commented 7 years ago

@osher Were you able to ever figure this out? I'm having a similar problem now. Basically statementMap is empty so it's failing at the same line it was failing for you. How did you move forward?

osher commented 7 years ago

sorry, guys, I moved on to a different place. I don't even remember what was the work around 😛

MikeyBurkman commented 7 years ago

I just randomly ran into this on Google. For me, deleting the coverage folder and re-running seems to work pretty well.