-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
[CSS REWRITE] [BIG UPDATE] Change how to process CSS #252
Comments
Hey @ntt261298, please see my note above on a new approach to handle CSS. It would be great if you can give some of your thoughts. Thanks. |
I think this approach is really promising. (Reduce the test running time, Be able to handle async tasks so we can scale easier in the future,…)
To summarize, I think it’s feasible to implement the new approach and will bring more pros than cons. |
[Just a note] This can fix #260 |
hi, is this on the roadmap? i would like to reduce the runtime in CI or make it only parse css based on some env variable. looks like this rewrite would solve that. |
What is it?
Current approach to process CSS
document.head
ofjsdom
. "Jest Preview server" will servejsdom
as real DOM, so we can see the CSS on the "Jest Preview Dashboard". However, this approach encounters a number of problemsconsole.log
the output the stdout, then reading/ parsing to get the returned value. This is a tricky one and does not scale, and I considered it as a unscale code.jest-preview/src/transform.ts
Lines 21 to 42 in d991e54
Is there any better solution
Yes. But first, let me describe how I come up with that idea.
A few days ago, I was working on #230. The issue is that when a CSS file that contains an
@import
statement,jest-preview
could not load the content of the imported file:If you are curious, I handled this in #248, by inline the imported CSS, using (
postcss-import
). But the thing is, when opening Jest Preview Dashboard myindex.css
will automatically request CSS files that are imported. (It's a CSS standard)Response:
This opens a new horizon for me to resolve all those issues above. What if instead of processing CSS at Jest Code Transformation, the "Jest Preview Dashboard" will process the CSS? I was in the middle of dinner with my family and I had to stop to think and draft the solution.
An HTTP-based approach
This is briefly how it would work:
jsdom
'sdocument.head
. Like this:relativeCssPath
from "Jest Preview Server"=> User can still see the CSS, the same way it is implemented in Code Transformation.
By doing this, we are moving the computation from
Jest
process to our "Jest Preview Server" process. Let's see the pros and consPros
postinstall
script, after user installs/ updatesjest-preview
, see ImplementgetCacheKey
#51 (comment))postinstall
script, which is considered bad for "security". See https://socket.dev/npm/package/jest-previewCons
jsdom
does not contain CSS anymore. If someone wants to do some kinds of "visual testing" usingjest-preview/transforms/css
. It wouldn't be possible. (Or would it be? Can we reuseprocessCss
?)cache-control
/etag
) sides.Jest
to "Jest Preview Server".Are any caveats?
jest-preview
, despite the re-architecture, the user experience remains the same. I have only one concern that Jest Code Transform does not invalidate. But I personally think we can handle it by taking the code transformed itself into account ingetCacheKey
(ImplementgetCacheKey
#51 (comment)).cssModulesExportedTokens
Describe alternatives you've considered
Do not implement this at all 😂. Even though the current (Jest Transformation) approach might be slow in CI, but it's not too slow and it's cache-able. If implementing this is too hard. We can just leave it AS-IS
Additional context
#241
#247
The text was updated successfully, but these errors were encountered: