-
-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad application of source maps to coverage reports for ternary expressions #198
Comments
@skozin does the percentage of coverage seem correct, but the highlighting off? This is most likely a problem with how we remap from the sourcemap to the coverage files used by Istanbul; @novemberborn is a subject matter expert on this part of the codebase. |
@bcoe unfortunately no,
|
It reports 75% Branches (33/44) and 66.67% Functions (4/6), although almost all functions have been executed, and almost all branches inside them were taken. Specifically, I can see 12 functions, and 9 of them were executed, which means 75%:
|
I've simplified the case a little. Now nyc reports 73.68% Branches (28/38) and 66.67% Functions (4/6). The function coverage I expect to see is 80% (8/10):
|
Also, If I move from ES6 classes to plain functions, the functions coverage numbers start to match the expected ones: 80% (8/10). See the no-class branch. So the issue with incorrect functions stats has something to do with how Babel transpiles ES2015 classes (any maybe other constructs). Also note that the reported total number of functions differs when comparing master (6 functions incorrectly reported) with no-class (10 functions correctly reported), though these branches differ only in the presence of However, highlighting remains wrong in both cases. |
@skozin I'll try and have a look at this tomorrow. |
@novemberborn Thanks a lot! |
@skozin finally got round to this. First I compiled I then looked more closely at the locations in your original code where the coverage report goes wrong. These are ternary expressions. When I reformat them the report matches that of the Babel build output: The conclusion then is that we're having trouble converting coverage reports for certain ternary expressions. I haven't investigated whether this is an issue with the coverage reports from Istanbul or our conversion logic. I suppose you could reformat your code a little until this gets fixed properly. Thanks for finding this! |
For future reference, using braces in the arrow function also breaks the source map application. The repo with the original test case and a workaround is at https://github.com/novemberborn/nyc-babel-issue-repro. |
@novemberborn, great, thanks for your help! I'll reformat my trenaries as a temporary solution. And what do you think about incorrect Funcs coverage numbers I described in previous comments?
Should I open another issue for this? |
@skozin if I take your |
@novemberborn, I guess there is some misunderstanding here. See, I run coverage on
HTML report shows Now I run the coverage on
HTML report shows I guess this is not what one would expect. Note that highlighting in HTML report is correct in both branches (as they both have the workaround applied), as well as line execution counts. |
I've updated the branches to match more closely. Actually, now it's enough to see the diff, which now also contains coverage numbers: skozin/nyc-babel-issue-repro@workaround...no-class-workaround. |
I'm not actually sure these incorrect functions numbers are caused by nyc, maybe this is an issue/feature in istanbul. |
@skozin yea I'm starting to think applying the source maps to Istanbul's coverage report is wrong. We need raw execution info, map that back to the original source, and then determine coverage. Will keep your cases in mind when I/someone gets round to improving the behavior here. |
@skozin apparently this may be solved in future Istanbul versions, though I don't know how compatible those will be with nyc. See gotwarlost/istanbul#582 (comment) |
@novemberborn, thanks for considering my cases, and for the link. Hope it will be compatible) |
@novemberborn I tried to forcefully install I guess here is the only related commit in And here is the source map support lib, which usage is introduced in that commit: https://github.com/istanbuljs/istanbul-lib-source-maps. |
I don't know for sure where I should report this issue, so sorry if it doesn't belong here.
When I generate coverage report with
nyc ava && nyc report --reporter=html
, the resulting report shows incorrect highlighting of the source code. And, the most critically, overall coverage numbers for branches and functions look incorrect (much less than expected).I have prepared the repo with the reproduction case.
Also, I've uploaded the report to this GH pages site.
Here is a screenshot that shows incorrect highlighting:
Annotations on the left suggest that
_takeFromWaitingPublisher()
function has been executed multiple times, and that's indeed the case as the test code is crafted to ensure this. Yet it is highlighted as not being covered.The
_take()
function also has a similar problem, although its code is highlighted in yellow, which means "branch not covered". However, the highlighted code has clearly been executed multiple times.Also, the highlighting sometimes starts and ends at positions that make no sense, e.g. between "t" and "h" letters inside
this
keyword.The text was updated successfully, but these errors were encountered: