
Show HN: Warpdom – drop-in jsdom replacement for Vitest and Jest
A DOM for unit and component tests: your tests get the same results as
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
A DOM for unit and component tests: your tests get the same results as on jsdom, faster. A drop-in environment for Vitest and Jest, written from the WHATWG specifications.
Status: pre-release. Numbers, method and raw data: docs/research/README.md, measured with dom-api-tracer.
Node 22.12 or later. Vitest 2 or later (tested with 2, 3, 4 and 5) or Jest 27 or later (tested with 27 and 30). Fast mode needs Vitest 3.2 or later.
npm install --save-dev warpdom
Vitest. Vitest takes a path (or a vitest-environment-<name> package) as test.environment; warpdom exports the path:
// vitest.config.js import { defineConfig } from 'vitest/config'; import { environment } from 'warpdom/vitest/environment';
export default defineConfig({ test: { environment }, });
Or install the small companion package vitest-environment-warpdom too, and use the name: test: { environment: 'warpdom' }.
With test.projects, set it on the projects that use jsdom today.
// jest.config.js module.exports = { testEnvironment: 'warpdom/jest', };
Or install the small companion package jest-environment-warpdom too, and use the name, as with jsdom: testEnvironment: 'warpdom', and /** @jest-environment warpdom */ in test files (Jest 27 to 30).
Test files that choose jsdom with a comment (/** @vitest-environment jsdom */, @jest-environment jsdom) keep using jsdom; change the comment to switch them.
Switch those comments too, even if the files pass on jsdom. Vitest groups test files by environment name and runs each group on its own workers, so files whose comment names another environment than the config run apart from the others. In a suite whose files share module state (isolate: false), that changes which files run before which in a worker, and with it the result of order-dependent tests: one of solid's tests passes or fails by that order alone, on jsdom and on warpdom alike. Use the same name in the config and in the comments (environment: 'warpdom' with vitest-environment-warpdom, and /** @vitest-environment warpdom */), or remove the comments.
Test suites encode the behavior of the jsdom version they were written against (for example, getComputedStyle returned empty strings for most properties before jsdom 29, and initial values since). warpdom detects the jsdom your project installs (and, for jsdom 26 and earlier, the cssstyle version it loads) and follows that version's observable behavior. With jsdom alone, another jsdom version changed test results in 13 of 23 projects we measured (Version dependence). To set it yourself:
// Vitest test: { environment, environmentOptions: { warpdom: { jsdom: '26.1.0' } } } // Jest testEnvironmentOptions: { jsdom: '26.1.0' }
Check your suite first: warpdom compare
npx warpdom compare # one round: results and an indicative speedup npx warpdom compare --rounds 3 # numbers worth quoting npx warpdom compare --correctness # results only (for CI)
Run it where you run vitest or jest. It runs your suite on jsdom (or happy-dom, whichever you use) and on warpdom, and reports every test whose status changes, grouped by error, and the speedup. Nothing in your project is edited. It exits 1 if any test that passes on jsdom fails on warpdom. The report's summary contains no file or test names, so it can be shared. Monorepos with Vitest projects or workspaces and Jest projects are supported. Details: docs/compare.md.
One caveat: on the warpdom side, compare switches Vitest test files that pin jsdom with a comment to another environment name than the config's, so they run in a separate group (see Setup). In a suite with isolate: false and order-dependent tests, that alone can change a result; check such a difference with the comments switched.
Fast mode (Vitest). Vitest isolates every test file, and reloading modules per file is a large part of a component suite's time. Fast mode runs files without isolation and resets warpdom's window between them; files that still leak module state are learned and run isolated. How much it gains depends on how much of a suite's time goes into reloading modules per file; measure it on your suite before relying on it.
Measured on GitHub Actions on 16 open-source Vitest suites (up to 5 rounds; warpdom 2606b3d): where sharing pays it is much faster than both jsdom's default and warpdom's drop-in, e.g. VueUse 9.6x over jsdom (5.2x over the drop-in), MUI 6.7x (3.7x), Vuetify 5.6x (3.8x), Radix 4.7x (2.6x), naive-ui 3.4x (3.0x), tanstack-query 2.4x (1.6x). Where sharing does not pay it runs the suite isolated (or splits for a gain within noise) and equals the drop-in (0.98-1.03x on the other suites). Median over the 16: 1.54x over jsdom's default, 1.01x over the drop-in. Against the fastest jsdom configuration that keeps every result (isolate: false, a cleanup, or the VM pool), the median is 1.27x, and it is slower on two suites (naive-ui 0.67x; melt-ui 0.84x). On Vitest older than 3.2, warpdom vitest run is not available and runs Vitest as configured, that is, the drop-in. Four of the 16 suites (melt-ui among them) run an older Vitest and ariakit passes three --project arguments, so those five were measured with our harness's emulation of the same rules.
// vitest.config.js import { withFastMode } from 'warpdom/vitest/fast'; export default withFastMode({ test: { environment: 'warpdom' } });
npx warpdom vitest run
Fast frames (opt-in). requestAnimationFrame normally waits 16.7 ms of real time per frame, in jsdom and warpdom. With fastFrames, frames run as soon as the event loop gets to them; suites whose test helpers wait for frames get much faster (ariakit 1.6x over warpdom's default). A few tests can change result, so it is off by default: check with npx warpdom compare --fast-frames.
// Vitest test: { environment, environmentOptions: { warpdom: { fastFrames: true } } } // Jest testEnvironmentOptions: { fastFrames: true }
Measured
All numbers below are from GitHub Actions runs on one frozen commit, warpdom 8630317 (2026-10-13): hosted Linux runners with 4 cores, pinned project commits, each project's own runner, config and jsdom, 2 workers. In each job the DOMs alternate on the same machine: an untimed warm-up, then 5 rounds with the order rotated. A speedup is the median of the per-round ratios, so it never mixes machines. Raw data, scripts and every derived number: docs/research/ (docs/research/data/ci-2026-10-13-208ad49-*).
Result
Drop-in speed, 13 suites, 3 independent runs median 1.28x / 1.27x / 1.26x faster than jsdom; every suite faster in every run (1.03x to 1.89x)
handsontable (jsdom 16.7, outside the medians) 8.0-8.9x (593 s to 69 s); 2.5x on the first run after install
Held-out suites (8) median 1.36x (1.01x to 1.96x)
Applications Excalidraw 1.21x, Wire 1.03x, 0 tests changed
Same results 17 of 25 suites: no test changed in any round; the other 45 tests are each explained below
happy-dom, for comparison median 1.25-1.28x faster than jsdom, but changes results in 12 of 13 suites
Fast mode, 16 Vitest suites up to 9.6x over jsdom (VueUse); median 1.54x over jsdom, 1.01x over the drop-in
Version dependence (jsdom alone) another jsdom version changes results in 13 of 23 projects
Web Platform Tests 87.4% of subtests (jsdom: 80.5%)
Drop-in speed and results
The first of three identical runs (run 38426985620), sorted by jsdom time. Times are the median of 5 rounds. The range is the suite's speedup in each of the three runs.
¹ Tests that fail on jsdom and pass on warpdom. ² CopilotKit is fast on happy-dom because 4,681 of its tests break there. ³ Tests that fail on jsdom and pass on warpdom, and one that is flaky on jsdom too (2 without it). ⁴ A deliberate difference (DOMException, below). ⁵ An order-dependent test of solid's, not a DOM difference (below).
Reported apart from the medians because its core, React and Vue packages run jsdom 16.7.0, older than the jsdom 20 the medians require. With a warm Jest cache the whole suite ran 8.62x faster in the run above (593.2 s on jsdom, 69.2 s on warpdom) and 7.97x to 8.87x in the three runs; the core package alone 11.2x to 12.5x, the Angular wrapper (jsdom 20.0.3) 1.86x to 1.98x. On the first run after install, when both DOMs pay for a cold transform cache and the Angular wrapper's compile, it was about 2.5x (2.53x to 2.55x). 3 tests differ, all deliberately (below). happy-dom completed no timed round.
Held-out. Nine projects warpdom was not tuned on (naive-ui, taiga-ui, melt-ui, dom-testing-library, tanstack-query, solid-primitives, VueUse, react-router, downshift; about 13,500 tests). At first contact 58 tests (0.43%) differed; fixing their causes means the set is no longer unseen. Drop-in, 5 rounds: a median of 1.36x (95% two-level bootstrap 1.05x to 1.69x) over the 8 projects with valid jsdom rounds, from 1.01x (taiga-ui) to 1.96x (VueUse); solid-primitives 1.14x from its raw rounds (its jsdom runs report 901 or 922 tests, so the broken-round rule drops them). In the 17 CI rounds that ran each of them, only these tests changed result: tanstack-query 1 (the ownerNode difference below), melt-ui 1 (speed-sensitive, below) and solid-primitives 4 (an order dependence of the project's own, below), plus flaky tests.
Web applications. Excalidraw ran 1.21x faster (1.20x to 1.23x) and the Wire web app 1.03x (1.00x to 1.03x, about equal), with no test that changed result. happy-dom changed 44 and 63 of their tests and ran Wire at 0.54x of jsdom's speed. Both apps drove fixes when they were first tried (2 and 141 tests differed then), so this is a migration case study, not held-out evidence.
Suites encode the jsdom version they were written against. Measured with jsdom alone, no warpdom: running each project on jsdom 20.0.3, 26.1.0 or 30.1.2 instead of its own version changed the status of tests in 13 of 23 projects (counting tests that ran; files that fail to load under a forced version are left out). It is concentrated: ariakit 258 tests (13.9%) on jsdom 20, React Spectrum 138 on jsdom 30, svelte 38, the others 1 to 16. Even a minor update of cssstyle, the CSS library jsdom 26 and earlier load (4.1.0 to 4.6.0), changed 12 svelte tests. warpdom therefore follows the jsdom (and cssstyle) each project installs. Given the latest jsdom's behavior instead of their own, warpdom would differ from jsdom in more tests in 7 of 23 suites: React Spectrum 0 → 146, svelte 1 → 25, handsontable 3 → 23, downshift 0 → 7, ark-ui 2–3 → 6, CopilotKit 0 → 1, dom-testing-library 0 → 1.
On WPT's dom, domparsing, html/dom and css/cssom (963 files), warpdom passes 87.4% of subtests (jsdom 30.1.2: 80.5%), with a per-file score of 75.7% (jsdom: 71.0%). warpdom was worked on against these tests, so they are not an independent check. The runner is in wpt/.
Full tables, method, profiles and caveats: docs/research/README.md.
warpdom matches jsdom's observable behavior where tests depend on it, and otherwise follows the standards. Deliberate differences, each with a test (full list in PLAN.md, "Deliberate deviations from jsdom"). Those that changed a test in the 25 measured suites:
Not implemented (jsdom lacks these too): layout (sizes and positions are 0, as in jsdom), inert, loading external style sheets, scripts or pages, navigation to other documents.
Not implemented, unlike jsdom: XMLHttpRequest. In 4,151 test files of 20 projects we traced, no test used it; HTTP libraries that feature-detect it (axios) fall back to Node's HTTP client, which request mocking (nock, msw) intercepts as well. If your suite tests XHR itself, warpdom compare will show it; please report it.
import { createWindow } from 'warpdom';
const window = createWindow({ url: 'http://localhost/', jsdom: '30.1.2', fastFrames: false }); window.document.body.innerHTML = '<p>hello</p>';
warpdom/compare exports compare(options), the API behind the CLI.
npm test # unit and parity tests (node:test; parity tests run jsdom side by side) npm run bench:load # cold load and window creation npm run bench:hot # hot DOM members against jsdom and hap
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。
