-
-
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
Make jest small #6266
Comments
It's reporting differently for |
Happy to trim deps if anyone is willing to figure out which we can drop without feature or performance regressions 🙂 Or if our |
There's not that much can be done on |
The 46 mb jump was rough, but seems like a bug in counting. It's back to the level of 22, so maybe close this? |
I updated the table in the original post above. It looks like jest is still the largest so I think the issue is still relevant. Update: also see jest dependency graph which might help identify unnecessary dependencies |
@styfle how do I add the package size badge in a github comment? Would like to use that elsewhere. ( facebook/create-react-app#3880 ) Also, when I just try to add the [email protected] it shows up as 61MB on my system.
|
@bugzpodder If you click on the badge from the result page, it will display the markdown.
Package Phobia is actually counting the raw bytes so it will be the smallest possible install size in a real world scenario. When you run For example, Windows default is 4 KB so a file smaller than 4 KB will take up 4 KB like this image. Update: I created facebook/create-react-app#4534 so you can see the difference between that PR and this PR |
I think Jest does more out of the box than the others listed, so is this is a fair expectation? |
@rickhanlonii Good question! I haven't used jest besides going through the first few sections of the docs which appears to be pretty common among these frameworks: asserts, matching, async, setup/teardown. I think the mocking feature and snapshot feature are the only additional parts that are shipped with jest that are not shipped with other test frameworks. Were those features added in [email protected] when the size spiked? |
We've got built-in support for babel transpilation, code coverage, fake timers, parallelisation across CPUs and really powerful VCS integration which combined with the dependency tree only runs the test related to files changed from a given commit, instead of the entire suite. That last one (in addition to clear errors) is probably my favorite. (and that's not even mentioning the watch mode (see https://github.com/jest-community/jest-watch-typeahead), and custom runners, allowing you to run e.g. eslint in the same watch process) |
We also ship JSDOM by default. |
Very cool! I didn't see VCS integration listed in the docs, it sounds glorious 🙌 Back to my original comment...
I see now that the CHANGELOG.md shows that this is the first version published to npm so I image the versions prior are another package with the same name. That being said I still think there's room for improvement. But for now I will continue to use the competition to test micro services. |
I came to the issues page to say something similar: it's okay with me if Jest is huge-by-default, but couldn't there be a dramatically smaller Or, if the Jest core APIs are designed to be drop-in compatible with some other API, I would be more comfortable using that other API until such time as I have a project even remotely close to 1MB of source code, which might justify having a 44MB "on disk" test framework with 418 non-jest dependencies. |
If you want to have mocking through |
Maybe it makes sense to make that configurable with |
We need babel for code coverage as well. I honestly don't understand why people are so averse to large dependencies in a server side dev only dependency |
I don't think this issue is actionable as it is. I do not care for the absolute size of Jest compared to other test runners. If we can provide a neat solution for people that's slightly bigger, I'm ok with that. It won't bloat production apps. If we can find low-hanging fruit and are able to remove a large chunk of our largest deps (20%+), I'm on board with that. I'm not willing to make any product changes in Jest to save a few bytes here and there though. |
Maybe "retain source-level compatibility with a much smaller test library" (jasmine?) is an actionable item? Let the other library be the Preact to your React. |
You're gonna run into a lot of these things even if you go to another test framework. If you pull in
Complex dependency trees can present some problems other than just size. For example, all the work that went into getting Also, it just makes me mad. |
To continue with what @wtgtybhertgeghgtwtg said, it also has a lot to do with transitive dependencies, any conflicting versions, and possible stale/outdated versions. Large deps exacerbate this issue a lot of the time. |
@wtgtybhertgeghg I question the assumptions that (1) everyone wants a code coverage tool regardless of its cost and (2) that the tool should be installed per-repo rather than globally. (Ideally (2) could be fixed in npm itself by having some sort of "recommended global dependency" feature where a project.json can ask for a big tool to be installed globally so that when you have many small repos they can share the same large tool, without completely losing dependency information as occurs today where |
IMO, I think the best approach would be to split jest up into a few more packages. Like Also has the added benefit of reducing size as consumers pick and choose what they want. |
Judging by this thread, I think it's clear that Jest is primarily a frontend test library with everything baked in. For frontend, an integrated transpiler makes sense I guess (I really try to avoid it for my own projects, but every company I worked for uses one, I guess it is fashionable), but when you're trying to test some small model library in Node.js for the backend, suddenly all those things that are baked in for the frontend don't really make sense. Call me paranoid, but from a security perspective, I worry when I see a seemingly unconstrained dependency tree I got to wade though in order to use a library (and in this case, the dependency tree is not really analytically tractable I'm afraid). Overall, seems like a really nice full featured batteries-included frontend testing library though (just not really for me). |
@Magnitus- Good point! Check out this spiderweb https://npm.anvaka.com/#/view/2d/jest/ |
Test transpilation actually doesn't account for that much of the dependency tree. A good chunk of the |
I agree that big dependency tree makes node running slow. In some cases it's good to bundle dependencies like rollup does to achieve as fast as it possible start. /cc @jonschlinkert |
The problem with bundling is that it creates duplication. While it'll be smaller and less to require and parse if that library and only that library is using those bundled dependencies, it'll be larger and more to parse if something else that's being used does. While it may be an option for CLI's ( |
Disclaimer: I know that flat mode of organizing dependencies is most used, To check that I have added only
Did quick comparison to other packages we use (sorted):
Total number of dependencies before de-duplication we have in ui projects is over 10,000 (and similar number of added packages is reported by [email protected] after successful npm install).
Unfortunately we can't change package manager, but even if yarn/pnpm is able to manage such dependency graphs much faster, even then complexity of keeping de-duplicated tree of dependencies is still there. |
@ibezkrovnyi Thanks for the idea regarding I've just checked the latest version and seems like situation improved in jest@26 but not drastically # jest v25.5.0
npm init --yes
npm i -D [email protected]
du -sh ./node_modules
+ [email protected]
added 506 packages from 346 contributors and audited 506 packages in 18.644s
found 0 vulnerabilities
53M ./node_modules
----------------
# jest v26.0.1
npm init --yes
npm i -D [email protected]
du -sh ./node_modules/
+ [email protected]
added 504 packages from 346 contributors and audited 504 packages in 20.415s
found 0 vulnerabilities
50M ./node_modules/ Here is the list of "leaders":
|
Let's remove node-notifier and make it an optional plugin. I don't know of anyone who uses it, and the people who do can install a separate package to hook it in. Does anyone want to work on a PR to make it its own package that will be used only when installed (and explicitly enabled)? Note it is already an optional dependency (and at FB we blackhole it to an empty package). |
Yeah, it should just be a matter of moving it from |
Here is approx. files count per dependency (top 10): $ du -a | cut -d/ -f2 | sort | uniq -c | sort -nr | head -10
1051 lodash
528 @babel
485 jsdom
217 @jest
144 resolve
144 @types
126 cssstyle
100 ajv
99 node-notifier
86 jest-snapshot BTW, can't |
@probil JSDOM will become optional in Jest 28: https://jestjs.io/blog/2020/05/05/jest-26 Right now it's the default, so Jest 27 will make the node env the default, and then 28 will stop shipping it. Note that for the monorepo at Facebook where we develop React Native, we blackhole |
@cpojer Cool! Thanks for update |
27 took so much time. How long to live with bloated node_modules and deprecation warnings until 28 is out? Maybe just kill jsdom in 27? Shouldn't be a big deal to add dependency for users. |
28 will come quite quick as I wanna drop node 10 and 15 as well. 27 should be just around the corner |
Jest 27 has knocked off a further ~10 MB compared to 26 🎉
|
Removing jsdom in jest 28 will cut another 10 |
Hey all! I might be misunderstanding the exact reason, but it seems like installing Jest gets |
Confirmed, Jest 28 reduced install size by 34%! Great job 🎉
|
@styfle awesome! Looking at the OP, this is the smallest Jest has been in "modern" times (i.e. when FB/Meta took over the FWIW, in the future we'll stop shipping |
@SimenB Looks like If you remove that dependency then I think we can close this issue. For comparison, here are the current competitors:
|
Most of that is from But, most of that seems to come from Drilling down, it's mostly |
I wonder if istanbul can be dropped entirely, since v8 code coveraga was released in nodejs v15.1.0, v14.18.0, v12.22.0. |
I'm in favor of dropping Istanbul. |
I'd think it makes sense for that to be part of dropping out of the box Babel support as we'd still pull in We talked about
I don't think anything has really changed here? V8 coverage is probably more viable, but ESM is still just as blocked as ever (although the mocks is mostly me having zero interest in working on it before ESM is more stable - others are free to jump in!) That said, we can probably flip default coverage provider from EDIT: Oh, and EDIT2: And as mentioned we use babel in inline snapshots, so that would need a refactor as well to yell at people that use inline snapshots to install babel |
@SimenB is making snapshots, say, an optional module (that manually needs to be installed) a possibility? |
we don't need babel for regular snapshots, so that seems overkill. Can do something for inline snapshots, tho. That said, I personally do not care about the install size, so if anything is to happen here, somebody else has to do the work 🙂 |
Is there any reason that we need some for example:
|
Who needs babel when there is esbuild. It won't make installation size much smaller, but at least dependency graph is less crazy that way. |
🚀 Feature Proposal
Make jest small again (less than 30 MB)
Motivation
It appears jest is the largest when comparing other test harnesses.
[email protected]
was small...it looks like[email protected]
is when the size exploded.Now
[email protected]
is even larger.Example
Click a badge above to see a history of the install size.
Pitch
Every repo needs to install jest to run it's own tests.
One repo with 50 MB is maybe not too bad but your app is split into 200 microservices, that's 10 GB of jest!
The text was updated successfully, but these errors were encountered: