question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider disabling JSDOM by default

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:29 (14 by maintainers)

github_iconTop GitHub Comments

7reactions
SimenBcommented, Mar 28, 2020

^ landed, let’s swap default for 26

6reactions
SimenBcommented, May 27, 2018

@cpojer @aaronabramov @thymikee thoughts on this?

It’s easier to google document is not defined than it is to discover your tests are a bit slower than they need to.

We could also potentially special case errors like document is not defined, window is not defined etc and provide a nice error message about setting environment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

disable CORS checking in jsdom on nodejs - Stack Overflow
I'm using JSDOM for my Mocha test environment and AFAIK there are no server settings to speak of. My Nginx configs for example...
Read more >
Testing with Node, Jest, and JSDOM - Manning Publications
In this version, jsdom is the default value for Jest's testEnvironment , so you don't necessarily need to specify it. If you don't...
Read more >
Configuring Jest
The default environment in Jest is a Node.js environment. If you are building a web app, you can use a browser-like environment through...
Read more >
jest-environment-jsdom | Yarn - Package Manager
main. Features. Fixes. Chore & Maintenance. Performance. 29.3.1. Fixes. [jest-config] Do not warn about preset in ProjectConfig #13583 ...
Read more >
JSDom Improper Loading of Local Resources - Tenable
From documentation, JSDom does not, by default, load any subresources. ... Tenable and the JSDom maintainers recommend disabling resource ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found