Open the test configuration of almost any front-end project and you’ll find one line that decides more about your CI bill than most of the code around it: environment: 'jsdom'.
Unit and component tests for React, Vue, Angular, Svelte, and Solid apps rarely run in a real browser. They run in Node.js, on top of a JavaScript implementation of the browser’s Document Object Model. Your test renders a button, clicks it, and asserts on the text that appears. The document, the click(), and the text all come from a library that pretends to be a browser.
For most teams that library is jsdom, the long-standing, standards-minded default. A growing number use happy-dom, which is faster but less faithful. Few teams think about the choice again after the first npm install. They should, because the test DOM is often where a component suite spends a large share of its time, and because the two popular options force a trade that most teams don’t know they’re making.
Over the past months I measured this on real projects. Here is what I found, and what I built as a result.
A component test does very little work of its own. It creates elements, sets attributes, dispatches events, and reads back state. Every one of those steps is a call into the DOM implementation, and DOM APIs are chatty: a single high-level call can fan out into hundreds of internal ones.
To see how chatty, I built an open-source tracer, dom-api-tracer, that records which DOM APIs a test suite calls and how often. One example from those traces: a single getComputedStyle() call in jsdom triggered about 1,000 reads of Node and Element properties inside the library, because resolving styles means matching selectors against the tree. Testing libraries call getComputedStyle() constantly, for instance to decide whether an element is visible.
Multiply that by tens of thousands of tests and the DOM is no longer a detail. On Ant Design’s suite of React components, swapping the DOM implementation alone took a CI run from about 30 minutes to 6.7 minutes. Nothing else changed: same tests, same runner, same machine.
There’s a second cost that has nothing to do with DOM calls. Test runners such as Vitest isolate every test file by default, which means the framework, the component library, and the DOM environment are set up again for each file. In a large component suite, that reloading can take more time than the tests themselves.
If jsdom is slow, why not switch to happy-dom? Many projects have, and on speed alone it delivers. In my measurements happy-dom ran a median of about 1.25x to 1.28x faster than jsdom across 13 open-source suites.
But it changed test results in 12 of those 13 suites. Tests that passed on jsdom failed on happy-dom, and in some cases tests that failed on jsdom passed on happy-dom. One suite had 4,681 tests break, which is also why it “ran faster.”
None of this is a criticism of happy-dom’s engineers. Implementing the DOM is a huge job, and every implementation makes choices about which corners of the specification to cover and how closely. The point is that a test suite encodes the behavior of the DOM it was written against. Change the DOM, and you change what your tests mean. A test that flips from red to green after an environment switch is no better than one that flips from green to red. In both cases you no longer know what your test suite is telling you.
It goes further than jsdom versus happy-dom. Upgrading jsdom alone changed test results in 13 of the 23 projects I measured. For example, before jsdom v29, getComputedStyle() returned empty strings for most CSS properties; since then it returns initial values. Tests that compared against empty strings, sometimes without their authors knowing it, broke on the upgrade. One project had 258 tests change status between jsdom versions.
So teams face three uncomfortable options: stay on jsdom and pay for it in CI minutes, move to happy-dom and audit every changed test, or stay pinned to an old jsdom and hope.
I wanted to know whether that trade was fundamental, or just a consequence of how existing implementations were built. So I wrote warpdom, an open-source DOM for unit and component tests, written from the WHATWG specifications, that ships as a drop-in environment for Vitest and Jest.
Its goal is narrow on purpose: your tests get the same results as on jsdom, only faster. Three design decisions follow from it.
getComputedStyle() keeps behaving the way it did in jsdom v26. Each of those version boundaries was measured black-box against jsdom’s releases.npx warpdom compare runs your suite on jsdom and on warpdom side by side and reports every test whose result differs, plus the speedup. It doesn’t modify your project. If you like what you see, npx warpdom migrate makes the configuration change.All of the following numbers come from GitHub Actions runs on hosted Linux runners, using each project’s own test runner, configuration, and jsdom version, at pinned commits. The DOMs were alternated on the same machine over several rounds, and the raw data and scripts are public.
A drop-in speedup of 1.3x may not sound dramatic. It’s the floor, though, not the ceiling, and it comes without touching a single test.
The larger gains come from the second cost: reloading modules for every test file. Turning off isolation in Vitest is a known trick, but it’s risky, because tests start sharing state and order-dependent failures appear.
warpdom has an optional fast mode for Vitest that runs files without isolation and resets the DOM window between them. Files that still leak module state are detected and run isolated. On 16 open-source Vitest suites, fast mode was 9.6x faster than jsdom’s default on VueUse, 6.7x on MUI, 5.6x on Vuetify, and 4.7x on Radix.
Those gains come with a caveat. How much fast mode helps depends entirely on how much of a suite’s time goes into reloading modules. The median across all 16 suites was 1.54x over jsdom’s default, and essentially no gain over warpdom’s own drop-in mode on the suites where sharing doesn’t pay. Against the fastest jsdom configuration that still kept every result correct, fast mode was slower on two suites. Measure it on your own suite before you rely on it.
Whether or not you try warpdom, four questions are worth asking about your test DOM:
warpdom is young. It’s pre-1.0 and has far less mileage than jsdom, which has served the JavaScript ecosystem for well over a decade and on whose observable behavior warpdom deliberately builds. Like jsdom, warpdom has no layout engine, and some APIs are still missing. Each gap is tracked as a public issue. APIs that jsdom doesn’t have will come as opt-in features, so that default results stay identical to jsdom’s.
The broader lesson goes beyond any one library. The test DOM is infrastructure, and we’ve been treating it as a detail. Choosing one shouldn’t mean choosing between fast tests and tests you can trust. With measurement instead of guesswork, it doesn’t have to.