-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Fix coverage test for Babel 7 #7202
Conversation
@@ -17,7 +17,7 @@ const DIR = path.resolve(__dirname, '../coverage-report'); | |||
|
|||
test('outputs coverage report', () => { | |||
const {stdout, status} = runJest(DIR, ['--no-cache', '--coverage']); | |||
const coverageDir = path.resolve(__dirname, '../coverage-report/coverage'); | |||
const coverageDir = path.join(DIR, 'coverage'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore changes in this file, this is just an unrelated quick cleanup
@coreyfarrell @JaKXz thoughts on this one? |
I just copied notRequiredInTestSuite.js to a local folder, ran: This produced the report I expected. It reported 0/5 statements and 0/5 lines covered. The same 2 branches and 1 function not covered as your report. I'm also seeing the expected transformation when I run From grep it looks like jest instruments the source here: If so can you post the value of |
Just want to mention I downloaded PR 7016 when I was looking at the jest sources locally. I notice now that the link I gave to is not that PR's revision but those two lines don't appear to be different. Also when testing your file with nyc I tried removing all options from our call to |
Instrumentation of files not required during the process of the test happens in the code you linked to. Jest instruments other stuff by using the babel plugin: https://github.com/facebook/jest/blob/7be2a8ef3f4d17b3ca139ba1a3dab72134306b50/packages/jest-runtime/src/script_transformer.js#L171-L189 and https://github.com/facebook/jest/blob/7be2a8ef3f4d17b3ca139ba1a3dab72134306b50/packages/babel-jest/src/index.js#L129-L142 |
f15e978
to
9d5ead8
Compare
"use strict";
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
throw new Error(`this error should not be a problem because` + `this file is never required or executed`); // Flow annotations to make sure istanbul can instrument non ES6 source
/* eslint-disable no-unreachable */
module.exports = function (j, d) {
if (j) {
return d;
} else {
return j + d;
}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Y2Vcbi8qIGVzbGludC1kaXNhYmxlIG5vLXVucmVhY2hhYmxlICovXG5tb2R1bGUuZXhwb3J0cyA9IGZ1bmN0aW9uKGo6IHN0cmluZywgZDogc3RyaW5nKTogc3RyaW5nIHtcbiAgaWYgKGopIHtcbiAgICByZXR1cm4gZDtcbiAgfSBlbHNlIHtcbiAgICByZXR1cm4gaiArIGQ7XG4gIH1cbn07XG4iXX0= |
Sorry to ask such a simple question but how can I run One thing I noticed in the code you just linked is |
Interestingly, there are 5 statements being returned in We feed that into a But for some reason only 4 show up in the reports?
Do However, that will spawn jest in a subprocess. To debug the actual test, I do this. $ cd e2e/coverage-report
$ ndb ../../packages/jest/bin/jest.js -i --coverage --watchAll You can also do just
Yeah, sorry, I'm linking to code in master. This is from the babel 7 branch: It has |
It appears the loss occurs in |
To isolate things, I've set up a repository with 3 commits:
Interestingly, the report is correct after step 2, it's only after changing to Babel 7 for the transpilation that we get the error. Could this be a babel bug instead? |
I'll have to take a look at this after I wake up some more (it's 6:30AM here and I'm just starting my coffee). Before reporting to babel I'd like to take a look at the instrumented source and source-map from commits 2 and 3. This way we can see what differences in source & source-map, determine if babel 7 is actually doing something wrong, or simply doing something different that istanbul-lib-source-maps doesn't properly handle. Would probably help to use Interesting thing about your 3 step test, istanbul-lib-instrument@3.0.0 uses babel 7 to translate the source. |
I've collected some additional data though my knowledge of source maps is limited. |
I know nothing about how source-maps work... @loganfsmyth any thoughts or ideas here? The interesting part is probably if you check out https://github.com/SimenB/weird-coverage-babel7, or @coreyfarrell's fork linked above.
|
Hmm, this is the tough part of sourcemaps. I'd consider this an issue with how istanbul takes maps into account. On the first line of JS code, with Babel 7, istanbul is bailing out at https://github.com/gotwarlost/istanbul-lib-source-maps/blob/8c43f14e48baeae6bb461639b4c91fe73c693ce0/lib/transformer.js#L27 because the In this case, Babel maps the single space between |
Oh that's interesting! Thanks for digging into it. Btw, what tool do you use to look at the source maps? Seems useful 🙂 |
That's a screenshot from https://sokra.github.io/source-map-visualization/
The issue in this case is that Babel does map the line with an exactly end location, but the way that istanbul is trying to process those ranges isn't a good way to do it. The reason it's failing is because it is essentially asking where the end of the statements maps back to, and rightly, there is no location, because the mapping ended an exactly the location it is asking about. Think of it like this:
compiled to
Babel essentials says that line 1 column 0 maps to line 0 column 0, and then Babel says line 1 column 4 maps nowhere, and then it says line 1 column 5 maps to line 2 column 0. Instanbul is getting the end location of the statement (line 1 column 4), and saying "where does this map in the original code", and the answer is no-where, because the space between Essentially Istanbul is asking the wrong question, in my opinion, because it is trying to ask "where does Answering the question of where a range maps to is not an easy question to answer with sourcemaps, but I think the way istanbul is doing it here is asking to run into issues like this. Edit: Deleted like 10 duplicate copies of this comment 😬 |
@SimenB @loganfsmyth if there's a reasonable simple fix to the logic to make Istanbul more forgiving, I'd happily fix it on our end -- haven't had a chance to dig yet. |
Wow, sorry my comment got posted so many times. With the Github issue yesterday it kept saying it hadn't gone through. @bcoe Yeah I'd have to dig into it more to see how it might approach it. I'm not realistically sure I'll have time any time soon though, so I'm hesitant to make any promises. I'd probably be field questions from someone else if they wanted to try to tackle it though. |
9d5ead8
to
e43b024
Compare
Rebased this, FWIW. @bcoe @loganfsmyth you wouldn't by any chance have the bandwidth to handle this now? 🙏 @jwbay maybe you know? (see the last few comments, identifying how the current approach in Istanbul is a bit brittle) |
e43b024
to
fa69114
Compare
@SimenB with the long weekend coming up, I can try to carve out some time for this 👍 (have been pretty heads down with my on going scheme to help move coverage to v8 and Node.js core). From your digging @loganfsmyth, it sounds like the problem is in the instrumenter potentially not being permissive enough when remapping lines of code from instrumented code back to the original? @SimenB if we can figure out a reproduction here, it would make it easier or me to turn around a fix quickly. |
@bcoe Awesome, thank you! Regarding a reprodcuction, there is https://github.com/SimenB/weird-coverage-babel7, which is relatively minimal, just using |
2b37b64
to
521cd3a
Compare
@loganfsmyth thank you for the reference implementation; @SimenB I'll see if I can't port it to an actual pull tonight. |
@bcoe did you find some time to take a look? Wonder if there are any blockers |
Opened up istanbuljs/istanbuljs#254 |
@loganfsmyth @SimenB please see istanbuljs/istanbuljs#255 |
521cd3a
to
a9da3a3
Compare
We'll land Babel 7 with the slightly buggy coverage. Hopefully the alpha doesn't break too many people. But I think we should wait for the fix to land in istanbul (especially as it seems it'll be released as a major) before making Jest 24 stable. I updated this branch by manually updating |
a9da3a3
to
192cb64
Compare
Awesome, thanks @bcoe! I updated, and will merge when CI is happy (the coverage tests passed locally, so no reason for it not to be happy). We'll be releasing a new alpha today, hopefully it'll be without issue for folks 🙂 |
Node 8:
I'll restart to see if it's something flaky |
Hmm, we got a failure in our coverage run:
You can reproduce by doing |
Just a typo, I'll send a PR! |
@SimenB @thymikee please give this a shot: Successfully published:
- istanbul-api@2.0.8
- istanbul-lib-coverage@2.0.2
- istanbul-lib-hook@2.0.2
- istanbul-lib-instrument@3.0.1
- istanbul-lib-report@2.0.3
- istanbul-lib-source-maps@3.0.1
- istanbul-reports@2.0.3
- test-exclude@5.0.1 happy holidays, 🎄 🌴 🕎 |
Perfect, thanks @bcoe! |
Oh, and thank you @loganfsmyth and @coreyfarrell! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Opening this up separately to keep it focused. I think this is a bug?
Essentially https://github.com/facebook/jest/blob/ed671678796d4ceb7a6744e36490316ceedff5c2/e2e/coverage-report/notRequiredInTestSuite.js#L8-L11 is not reported as not covered. This is how the generated html report looks:
So the
throw
is no longer counted as a statement, which is wrong. (right?)@bcoe any idea what's going on here? Help would be greatly appreciated 🙂 Background is that we're moving to Babel 7 (dropping 6). I'm not sure if it's a difference in the last versions of the babel istanbul plugin or if we're doing something odd.
Full diff against master can be seen in #7016.
Relevant istanbul dependnecy changes:
Test plan
I'd like for this PR to have 0 diff in the coverage snapshots, while still passing those tests (others will fail). Then I'll merge it into #7016.
The relevant test is
e2e/__tests__/coverage_report.test.js