-
-
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
feat: bundle Jest's modules with webpack #12348
Conversation
scripts/buildUtils.js
Outdated
} | ||
|
||
// inspired by https://framagit.org/Glandos/webpack-ignore-dynamic-require | ||
class IgnoreDynamicRequire { |
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.
getting webpack to to leave require.resolve
alone (as far as I can tell it never behaves like node's builtin one, which is the behavior I want for everything not a local require
) is painful and this is spotty. Seems to work fine, tho
0970771
to
d8231b0
Compare
You might need to enable the |
de5718b
to
610191f
Compare
(just rebased after #12636, I'm not currently planning to work on this) |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
411f4a2
to
562ae92
Compare
89c7c4c
to
e3abe11
Compare
335dc74
to
7cc2322
Compare
Green! 🎉 |
On my machine this shaves off about 10% when running
This PR:
Turning on minification seems to improve the results slightly.
Hard to tell if that's any real improvement or not, tho. And having minification caused quite a bit of tests to fail (I suspect it's due to munging, but not 100% sure) so I'd like to explore that in a separate PR anyways. |
Since we use |
7cc2322
to
090b597
Compare
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
1e37b18
to
4713393
Compare
I was investigating another issue and found that it seems debugging is not working, we are not generating source maps for bundled. To be honest, I'm not sure what I should do. |
Happy to produce sourcemaps, but it breaks some tests with filenames in the snapshots. Probably worth it? |
If we also bundle during development, then just emitting the source map all the time should not break tests. |
But there is still a problem in this case. Maybe we should not let users load the source map by default, which may cause us to test two situations at the same time. |
Yep. Debugging is broken due to using workers, I think. #14085 (comment) |
I just worked with the debugger now while putting together #14578 - breakpoints in jest sources worked fine. I use |
Ah, within the ts file! That probably needs source maps. I always debug in the chrome dev tools, never within the IDE. So haven't noticed 😅 |
Awesome! We have some "absolute path to relative path" stuff for stacktraces, and stripping internal frames. That's where I'd assume any issues would arise - beyond that it should be fine 🙂 |
One regression: nodejs/cjs-module-lexer#88 In practice, this breaks Unfortunate that TS types don't have a |
Fix for the above was to have our own ESM exports, bypassing the lexer entirely: #14661 Released in https://github.com/jestjs/jest/releases/tag/v30.0.0-alpha.1 |
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
Bundling our modules allows us to improve our startup time by avoiding a bunch of extra I/O. Optimized code also should run faster (in theory), but might be worth it to drop that for readable code in
node_modules
?Anyways, there are (at least) 2 outstanding issues.
jest-worker
needs to pass the path to a file tochild_process
so it can be executed. I've been unable to make Webpack split out a separate file on disk, then return an absolute path to it. Might need to do very custom stuff just for jest-worker, not sure (if possible, keep just plain babel run for this module for now, if everything else works. Hard to tell since withoutjest-worker
, we cannot run anything at all)build
on purpose (such as forjest-circus/runner
). We need to do something Clever ™️ here. (I haven't bothered thinking too much about as I've swapped between fightingrollup
andwebpack
the last few days).Any and all help greatly appreciated!
Problem areas: https://github.com/facebook/jest/blob/29534331e2d3d3f70cf153d7e53569d9dd80ecfe/packages/jest-worker/src/workers/NodeThreadsWorker.ts#L61 & https://github.com/facebook/jest/blob/29534331e2d3d3f70cf153d7e53569d9dd80ecfe/packages/jest-worker/src/workers/ChildProcessWorker.ts#L86
Note that
worker_threads
can receive source code as string, so I wondered if just inlining could work (albeit still a separate bundle), butchild_process
does not, so doesn't helpAnother alternative is to inline as bundled string, then write to disk during load. Feels wrong tho
Speaking of
rollup
, I cannot make it understandrequire
, and it also barfs onimport thing = require('thing')
even though babel is supposed to compile it away. Anyways, let's try webpack first.Test plan
Green CI (at some point)