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

Error running istanbul check-coverage --statements 90 #192

Open leore opened 10 years ago

leore commented 10 years ago

Getting this error:

/Users/bavidar/.nvm/v0.10.26/lib/node_modules/istanbul/lib/object-utils.js:58 var line = statementMap[st].start.line, ^ TypeError: Cannot read property 'start' of undefined

Has anyone solves this problem?

guyellis commented 9 years ago

@leore - Is this still an issue for you? I think that it's an easy fix that I can do an submit a PR for if it's still an issue for you or someone else.

chengyin commented 9 years ago

I hit this problem recently. What solutions do you have in mind if you don't mind me asking, @guyellis?

guyellis commented 9 years ago

https://github.com/gotwarlost/istanbul/blob/master/lib/object-utils.js#L59

@chengyin I was going to skip that section of code if statementMap[st] was falsey. Thought that would be better than having it fail.

Are you hitting this error as well?

gotwarlost commented 9 years ago

This is most probably because it is trying to process a Json file that doesn't have coverage info. The error message is terrible and doesn't indicate which gold had the problem. If you want to submit a pr, you should probably focus on improving the message and / or skipping files that don't look like a coverage json

chengyin commented 9 years ago

I did some investigation and this is what I got for our specific case:

The issue is caused by a mismatch between statements and statementsMap. The length of the two didn’t agree. One recorded more statements than the other for the same file.

I dug deeper and in our codebase, this is because we are using webpack inject-loader for our unit tests. If the injected version and the original version both get required, then there are two files registered to the same filename in Istanbul. The extra code for injection threw Istanbul off and eventually caused the exception.

Now that’s an issue that Istanbul doesn’t and probably shouldn’t deal with. There are multiple places in Istanbul runs into exceptions because of this. I agree better error message would help.

I plan to fork inject-loader and add Istanbul ignore comments for the injection related code. A different inject loader does this.

guyellis commented 9 years ago

@chengyin I agree with @gotwarlost - would be great to also submit a PR for istanbul that did one or more of:

As per my previous "fix" idea my feeling is that istanbul should still try and work and give a partially good result if not complete one while printing out error messages about what it can't do while processing.

i.e. given a choice between:

ianribas commented 8 years ago

Just so it may help others with the same error message, I had the same problem and it was a similar situation as the one reported by @chengyin: the same file with two different coverage information.

As we use broserify, the first was coming from a browserify transform (with browserify-istanbul) and the other from the karma-coverage preprocessor. Turns out, of course, the second is unnecessary and was causing problems when generating the report.

silkentrance commented 6 years ago

@gotwarlost since this is basically a mistake in the build process and also related to an external library, we should close this for good, don't you think?

silkentrance commented 6 years ago

@gotwarlost or create an FAQ from it?