How to disable jsdom in jest — make jest run twice as fast

Jest is a awesome test runner, a lot of features works great out of the box like watcher, code coverage, status screen and much more, however jest is a little bit slower than other test runners simply because it does more. It is generally not a problem when you run in watch mode. One reason jest is slower is that it ensures encapsulation between tests so they don’t leak and make other tests fail. Another reason is jsdom is attached to each test file and jsdom is a whole browser DOM emulated in javascript, you can imagine that is not a small code footprint! So if you are only making something for node.js and don’t have any tests for React.js as example, then you can with benefit disable that feature!

Do that by adding a key called “jest” in your package.json and write it like this:

"jest": {
"testEnvironment": "node"

That will make your test run about 2X faster when you do a full test suite run and that can be a benefit if you have a lot of tests!

Now however will document be undefined, so any test that depend on the DOM will be null or have a reference error.

You can read more about the settings of jest here and other cool settings like notify