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

_ #817

Open ghost opened 7 years ago

ghost commented 7 years ago

_

FezVrasta commented 7 years ago

I have the same problem, my repo is: https://github.com/FezVrasta/popper.js/pull/314

To reproduce just run yarn test

brian-griffin commented 7 years ago

I have the same issue. I did a bit of investigation and it seems to be at this point: https://github.com/gotwarlost/istanbul/blob/master/lib/report/html.js#L288

At the point it errors on my project, structuredText is an array of 60 objects but startLine is 64, so it's returning undefined.

However the coverage report is generating correctly!

I put in a local hack to stop the error from showing: ... && (startLine <= structuredText.length) on the following lines: https://github.com/gotwarlost/istanbul/blob/master/lib/report/html.js#L205 https://github.com/gotwarlost/istanbul/blob/master/lib/report/html.js#L236 https://github.com/gotwarlost/istanbul/blob/master/lib/report/html.js#L283

Not sure what's causing this issue though as I'm not too familiar with the Istanbul source, so would be good to get some suggestions on a fix to the underlying problem?

FYI: This issue started appearing when I updated our project to angular v4.x and angular-cli v1.1.2 with karma-coverage-istanbul-reporter v1.3.0

cenkingunlugu commented 7 years ago

it is solved with: https://github.com/gotwarlost/istanbul/pull/819

arsenslyusarchuk commented 6 years ago

Hello. When it's going to be fixed? I cannot get proper html report

QLaille commented 6 years ago

No news ?

vviikk commented 6 years ago

Dev's on holiday? How long is this going to take?

joshuabyler commented 6 years ago

Reverting istanbul to 0.4.4 worked for me.

vegetabill commented 6 years ago

I am using gulp-istanbul 1.1.3 which depends on istanbul 0.4.x and I encountered this issue (when it was using istanbul 0.4.5). Manually forcing gulp-istanbul to use istanbul 0.4.4 resulted in the same error.

@heronblade Is it possible another change helped you fix this or was it just the downgrade?

Also, this issue seems to be stuck without any updates or progress. Is there anything users can provide to help the project maintainers root cause this? It seems related to source maps but my mocha test setup doesn't really do anything with source maps so I'm not sure where to try to fiddle with things to get around this error.

binomialstew commented 6 years ago

Reverting to istanbul 0.4.4 did not solve the issue for me, either.

vegetabill commented 6 years ago

Bump. So this issue is an unsolved blocker? Any other workaround suggestions. Istanbul seems like the only game in time for modern js coverage so I'm a bit lost where to go from here.

vegetabill commented 6 years ago

FWIW, I gave up using gulp to drive my mocha test run. When I instead invoked nyc via an npm script, it worked fine. I think that means using this package by itself is no longer supported.

toddpi314 commented 6 years ago

Check out https://github.com/gotwarlost/istanbul/issues/602 for a resolution

anki06 commented 6 years ago

I am using simple istanbul and still recieveing this error. Does anyone know how to solve it? It is generating lcov.info correctly but not index.html

vegetabill commented 6 years ago

FWIW I switched to using nyc via its CLI and it's working. I think this means this package is unmaintained/dead for other use cases.

minimorph223 commented 6 years ago

In my case, i am using protractor + istanbul to get coverage for integration testing. So need to pre-instrument source file before test and get this error in istanbule report. I find if i use origin source file to replace the instrumented source file, then it works.

Checking code, structuredText[startLine].text is undefined due to the instrumented source file text structure is changed and the [startLine] line is invalid.

VladyslavKurmaz commented 5 years ago

I've started seeing this issue a couple days ago. A week ago everything worked smoothly. Looks like our js source code was changed and somehow uncovered this bug.

    "istanbul": "^0.4.5",
    "istanbul-combine": "^0.3.0"

We are combining coverage from a set of files. Looks like calculation is fine, but the report generation is failed

=============================== Coverage summary ===============================
Statements   : 29.37% ( 1614/5496 )
Branches     : 9.96% ( 442/4436 )
Functions    : 28.57% ( 932/3262 )
Lines        : 30.26% ( 1276/4217 )
================================================================================
node_modules/istanbul-combine/node_modules/istanbul/lib/report/html.js:283
                    text = structuredText[startLine].text;

Another possible reason can be that we switched from angulajs-1.7.0 to angularjs-1.7.3 a month ago


fixed: the issue was that our source code and coverage information was not synchronized, we are using karma/istanbul/jasmine for e2e tests coverage calculation

SasanFarrokh commented 5 years ago

Fixed: I remove karma-coverage and used karma-coverage-istanbul-reporter

luwes commented 5 years ago

For rollup-plugin-istanbul users, the babel plugin has to come after istanbul plugin. https://github.com/artberri/rollup-plugin-istanbul#other-usage-options

kushmisra commented 4 years ago

Hi , I am also facing this issue and this https://github.com/gotwarlost/istanbul/pull/819

Solved it for me . Please can this issue be resolved so that we don't have to patch Istanbul ourselves.

flaval commented 3 years ago

The real problem seems not to be in "html" reporter module.

I ran into the same problem and after some investigations, I make a patch myself on the "html" reporter module to skip the error and I realize that the highlighted uncovered lines seems to be shifted with the real code. The reason was that in my bundler (webpack) I set another loader ("imports-loader") before the "babel" one which brings instrumentation in my configuration. So "babel" took an already transformed code before to send it to "istanbul", and all offsets were shifted and wrong. I ordered my bundler loaders to pass by "babel" loader first and all is good now 🙂

Hope this trick can help another desperate code coverage lover, and sorry for my bad english