jeffrifwald / babel-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
144 stars 23 forks source link

Uncovered branch in leading multiline comment #79

Closed just-paja closed 7 years ago

just-paja commented 7 years ago

There seems to be some problem when covering code with combination of import, spread operator and multiline comments. Istanbul will report else branch uncovered on the leading multiline comment.

I prepared example repository where the problem is reproducable and also contains examples that are working.

CLI

HTML

jeffrifwald commented 7 years ago

This is likely due to the source map generated by babel. Could you post a screenshot of the code generated by babel for that file?

just-paja commented 7 years ago

@jmcriffey, I added babel output to the example repo.

jeffrifwald commented 7 years ago

This line is definitely the culprit. What usually happens in these cases are a feature gets added and the source map gets broken in some small way. If the source map doesn't reflect the code correctly, then this tool cannot do its job. With that being said, there are three possible solutions:

  1. Use the babel-runtime transform in your babel config. Using this transform will use babel helper function calls instead of injecting all of that logic in every file. I think this is the best solution, as it also optimizes your file size.

  2. Look at babel and figure out how to fix the sourcemap for toConsumableArray. Then open a PR for the fix in their repo.

  3. Try different versions (older and newer) of babel and its presets. This could be a sourcemap issue with the newest versions, or it could be and old issue that is already fixed in a more current version.

just-paja commented 7 years ago

@jmcriffey, thank you for explanation. I think that this could become part of the projects README.

just-paja commented 7 years ago

I tried the proposed solution number 1 and it worked. Thanks. I'll keep the example repository archived for other people to see the problem and the solution.