-
-
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
Consider disabling JSDOM by default #5815
Comments
I think this could also go a long way to shed the perception that Jest is only for testing React components or that it is in any way tied to testing for web code. As surprising as it is this perception does still exist (at least people don't think it still mocks everything by default). |
I understand this is a potentially controversial and breaking change, would it help if I started a PR or should I wait for a discussion with more collaborators? |
The change should be pretty straightforward so I wouldn't recommend submitting it until we decide this is the direction we want to go I agree that defaulting to node would be better, but I'm not sure when the timing would be right. This will be a breaking change for the majority of Jest users |
@cpojer @aaronabramov @thymikee thoughts on this? It's easier to google We could also potentially special case errors like |
I wonder if it possible to "detect" whether the code needs JSDOM or not?
You could have the default Not so sure on the idea myself, but worth considering? |
we'd have to scan the entire dependency tree before we'd be able to start the test then. The dependency tree we have today is built up by looking at the sourcecode of every single file, and extracting |
Auto seems too magical. I think we can just switch the default. CRA can keep setting it to jsdom. We can, however, add the error messages that you pointed out @SimenB. Known DOM globals (document, window, etc.) should trigger the error and ask people to update their config. Bonus points for a |
I like |
yeah makes sense. |
Node is the simplest built in env, right? Out of curiosity is there a third env? |
@nickmccurdy Jest only provides implementations for |
So in summary: Jest 23.x
Jest 24.0.0
|
We can do that now - it'd be a pretty useful error regardless of defaults |
Good point, updated |
Let me know if I can help with PRs. |
PR very much welcomed for all except switching the default (we'll do that closer to next major)! |
@rickhanlonii I'd prefer not to have any warnings or force people to choose a test environment. Can we make it so we use the same warning/error message that recommends people to use @jsdom to put |
Changing the default is a breaking change, but what we can do in the meantime is add the warning ( |
Hi, is it okay if I give this a shot ? |
Yeah! Just update |
Look for |
I've opened up #8245 as an attempt to give a nicer error if the wrong environment is used. Once we land it (or something like it), we can switch default environment in Jest 25 to |
^ landed, let's swap default for 26 |
Wow huge |
FYI this is planned for Jest 27 (source) |
Indeed, I've added the linked PR to the 27 milestone, after we mentioned it in the last blog post :) |
It'll be bundled in 27 to ease migration and removed in 28 (probably) Mentioned in the blog post: https://jestjs.io/blog/2020/05/05/jest-26 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Default change proposal (semver breaking)
What is the current behavior?
Jest's default testEnvironment is jsdom. I understand the intention of Jest is to follow convention over configuration and make things like DOM testing very easy for beginners with minimal configuration, but there is a large overhead to having jsdom enabled by default (often 3 times as slow to boot per test suite in my experience) and I don't think most users even realize this is configuration.
What is the expected behavior?
I think swapping the default to node would be nicer (of course, not without deprecation warnings, semver major breaking changes, and possibly a helpful error message when the DOM is accessed in the Node env). While I tend to disable jsdom because I never need it, I often forget and I'd rather have the default settings optimize for performance in this case. I think this would keep the testEnvironment settings more consistent with Jest's other performance first defaults, like disabling coverage. It's also worth mentioning that many usages of Jest even in web code don't need jsdom, as shown in Jest's own documentation on react-test-renderer.
The text was updated successfully, but these errors were encountered: