-
-
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 cache of transformed files with multiple projects #7186
Conversation
7706ba8
to
20db7ec
Compare
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 way better!
|
||
it('does not reuse the in-memory cache between different projects', () => { | ||
const scriptTransformer = new ScriptTransformer({ | ||
...config, |
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 is safe for older versions of node unfortunately
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.
Ohh, I thought jest
tests were also transformed 😅 I'm gonna use Object.assign
then
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.
Yeah I forget this every time 😸
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.
Btw, this works now that we've migrated to babel 7 - as part of that we went with @babel/preset-env
instead of manually listing the transforms
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.
👍
Nice! This may fix some issues @gaearon ran into a while back. |
A couple of |
I think it doesn't happen usually |
One thing that's relatively new is that we now time out your synchronous test if it's slower than the timeout. Previously we only timed out async tests. So tests that passed previously might now be reported as timing out |
4c3095b
to
8727d0a
Compare
I was not able to reproduce the timeouts locally, so I just retriggered the tests in AppVeyor and now they pass 🤷♂️ |
Codecov Report
@@ Coverage Diff @@
## master #7186 +/- ##
=======================================
Coverage 67.31% 67.31%
=======================================
Files 248 248
Lines 9615 9615
Branches 3 3
=======================================
Hits 6472 6472
Misses 3142 3142
Partials 1 1
Continue to review full report at Codecov.
|
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
jest-runtime
uses an in-memory cache system (a simple "global"Map
) to avoid reading a file when it gets required multiple times by separate tests.This cache system uses the filename, the modified time and the
instrumented
boolean as the key (see thegetScriptCacheKey()
method), and it's used across different projects. This causes incorrect transformations when tests from two separate projects that have different transformers require the same file.To fix this issue I've decided to refactor a bit the global objects that are defined in
script_transformer.js
: instead of having multiple of them (configToJsonMap
,cache
andignoreCache
, each of them with different keys), I've merged them into a singleProjectCache
object that gets initialized whenScriptTransformer
is constructed. This way we can be sure that each cached value is completely isolated between projects (and it's easier to add new things to cache).An alternative way to change it would have been to just add a new param to
getScriptCacheKey()
(the project config) and then useconfigToJsonMap
to serialize it and include it in the key. That alternative solution would have resulted in a smaller PR, but IMHO this one is more robust.Test plan
I've added both a unit test and end to end test to verify the correct behaviour (both tests would fail with current master).