-
-
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
Removing the mapCoverage condition on reading inlineSourceMaps. #5177
Conversation
a821f90
to
364d956
Compare
Codecov Report
@@ Coverage Diff @@
## master #5177 +/- ##
=========================================
- Coverage 61.72% 60.63% -1.1%
=========================================
Files 213 213
Lines 7170 7311 +141
Branches 4 3 -1
=========================================
+ Hits 4426 4433 +7
- Misses 2743 2877 +134
Partials 1 1
Continue to review full report at Codecov.
|
Interesting, nice find! I think we also want to revert the changes in the snapshot in #5117 as well. Adding an integration test showing that the coverage is mapped correctly in a stack would be great. So not just testing the .map file, but the mapping as well |
I think, I might need some pointers adding the integration tests. Is there an example I can look at? PS: I will do this in the morning. It's night time here! :P |
|
Hmm, I wonder if the correct fix is to pass Do you agree? I think I'll have to dig a bit deeper into how sourcemaps work and how they're merged |
But what doesn't make sense is the If we have to stick to it's intended usage mentioned in docs, we should enforce I'm strongly against that, since the coverage remapping will be messed up, the coverage annotations will be all wrong. |
Hi 👋 I implemented the initial source map support for Jest, so I think I can provide some context.
And I think that brings us to this PR. I think the integration test snapshot should definitely stay reverted. It shouldn't have changed in #3458. I haven't checked, but the line/column numbers in that snapshot map directly to the visual alignment of covered code in the HTML report, so if they changed things probably broke. I can't think of a good way to keep that from happening again in the future. The mapCoverage option used to affect more than inline source maps. It used to null out the map property on the transform result when it was false, whether it was populated via a separate map or an inline source map. You can find that in the initial source map PR: https://github.com/facebook/jest/pull/2290/files#diff-7de44d08766eddcf4bca597034b5b4c2R314 To be clear, mapCoverage was added and defaulted to false to prevent silent performance regressions for the case where people with large projects had a transformer set up that happened to return inline source maps. |
"jest": { | ||
"rootDir": "./", | ||
"transform": { | ||
"^.+\\.(js)$": "babel-jest" |
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.
I don't think this test is valuable currently because babel-jest doesn't deal with source maps. It instruments and then transforms, so there's no coverage remapping necessary.
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.
Doesn't it emit inline sourcemaps? Here Which are then read?
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.
I'd also like to better understand this 🙂
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.
FWIW, inline sourcemaps is pretty recent: #3738
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.
Since mapCoverage is not passed in this integration test (which is correct*), no remapping should be performed here. I'm not positive, but I would expect this integration test to pass with the same output on master. Since the main purpose of this PR, as I understand it, is accurate line/col numbers for error stacktraces and codeframes, maybe the integration test should try to cover one of those use cases.
* If a transformer instruments before doing downlevel compilation (as babel-jest does), any sort of source map processing for coverage is probably going to break things. Source map processing for coverage only makes sense when going the other direction (downlevel compilation, then instrumentation)
Edit: I see mapCoverage is being passed after all. I'm curious what the HTML report looks like
transformed.map = inlineSourceMap.toJSON(); | ||
} | ||
if (!transformed.map) { | ||
const inlineSourceMap = convertSourceMap.fromSource(transformed.code); |
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.
This is where performance issues may surface with this unguarded. convertSourceMap.fromSource
looks for inline source maps in code files with a regex (src). For sufficiently huge source files, this can freeze node (ex: babel/babel#5081). It depends on the regex as well as file size, I think.
I don't have a good answer here. Some tests are probably in order; it may not be a problem. Or we may need a new sourceMaps option or something. Or we could kill inline source map support and required a separate code/map pair always.
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.
I hadn't looked into the source code of convert-source-map
. I'm okay with using mapCoverage
to guard against this. But like it was in the original PR, it should be nullifying the explicit sourcemaps emitted from preprocessors.
Also as a user of Jest
, I would want it to come with sensible defaults, IMO defaulting map coverage to true, adding a caveat that this should be set to false in case you are facing some freeze issue is better than defaulting to false. Cuz more often than not, it will work and is incredibly important.
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.
Is mapCoverage
used anymore with this changeset. Also, if we combine this with #5257 at least it wouldn't hit the default babel-jest
configuration
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.
With this change, inline sourceMaps emitted from the default babel-jest
will be read. #5257 may not be necessary.
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.
The point is that inline sourcempas are way slower than just using the returned sourcemap.
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.
Agreed. I'm actually leaning towards removing inline-source-map support. But I don't know the ramifications of it.
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.
Inline source map support helps when debugging tests. VS Code at least tends to behave better when everything it needs is in script it's executing.
@@ -261,7 +259,7 @@ export default class ScriptTransformer { | |||
code = transformed.code; | |||
} | |||
|
|||
if (instrument && mapCoverage && transformed.map) { | |||
if (instrument && transformed.map) { |
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.
For proper stack trace support, the instrument check should probably be killed as well. Test files are (almost) never instrumented, so line numbers in stacktraces for errors won't be fully correct otherwise.
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.
Agreed. If map is there save it, otherwise don't.
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.
Can you remove instrument
?
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.
Done!
Also what do you think about stripping out the inline sourcemaps before caching the actual code file.? I think it's important we do that, we can cut down the amount of cache space we are taking by almost half for inline sourcemaps. 😉 |
Looking forward to this landing! |
@jwbay thanks for chiming in! Are we able to test this against a real project and check that it works correctly? @Aftabnack Please update the changelog as well 🙂 |
@SimenB Updated the changelog. Also added this comment: I don't know of any big projects where this could be tried. |
We can at least test against some of the repros in #5109 |
The repo in that issue, worked out of the box without me having to link my local |
It does now as we have reverted the change which broke them. Does it still work if you link in this? If any of the reproductions have lockfiles, that'd help |
|
If the tests time out with this change, I consider than an issue. I don't think we should increase the timeout, we don't want to make Jest slower |
My guess is because your machine is more powerful. Try running with and without your change 3 times or something, is there a difference in execution time? |
I'll try running on My config is 8GB ram with 256GB SSD running on i5 processor. Wouldn't call it powerful.. 😉 |
This was my mistake. I didn't rebuild the packages. Testcases are actually failing. It is because we have removed the instrument check. I will re-add the instrument check and try to figure out why that is important and what it is needed for. |
24d8228
to
daa9fe7
Compare
@SimenB Why do we save sourcemaps of test files themselves? |
Debugging the tests themselves, including codeframe on assertion errors |
After hours of debugging, I found this: The testcases that were failing, were because the Files that were returned in the coverage collected ( Because this was the case, when it tries to assert which file the sourceMaps belonged to, it throws since coverageCollected from the test run won't have the file in which the tets case was written; here: |
I have modified the Thoughts @SimenB ? |
Upon debugging the timeout issue, I found out that the testcase is timing out when the @SimenB can you help me understand how |
mapCoverage has been deprecated since Jest@22.4.0 https://github.com/facebook/jest/blob/master/CHANGELOG.md#2240 jestjs/jest#5177
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
Test plan
mapCoverage: true
#5117