@ctrl/dom 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -105
- package/dist/aria/_chunks/{aria-query.generated-BivoZ-ec.js → aria-query.generated-BG-n1PE9.js} +2 -2
- package/dist/aria/_chunks/{aria-query.generated-CeGmXXFh.cjs → aria-query.generated-BqD80bJk.cjs} +1 -1
- package/dist/aria/index.cjs +1 -1
- package/dist/aria/index.js +1 -1
- package/dist/aria/internal.cjs +1 -1
- package/dist/aria/internal.js +1 -1
- package/dist/aria/types/forms.d.ts +0 -2
- package/dist/bridge/internal.js +1 -1
- package/dist/dom/_chunks/src-B3vkUXY6.js +50 -0
- package/dist/dom/index.js +1 -1
- package/dist/dom/internal.js +1 -1
- package/dist/dom/types/collections/NodeList.d.ts +2 -0
- package/dist/dom/types/css/cascade.d.ts +5 -6
- package/dist/dom/types/css/media.d.ts +0 -2
- package/dist/dom/types/css/parser.d.ts +0 -2
- package/dist/dom/types/css/properties.d.ts +0 -2
- package/dist/dom/types/css/shorthands.d.ts +0 -2
- package/dist/dom/types/css/style-deps.d.ts +18 -4
- package/dist/dom/types/css/stylesheets.d.ts +14 -18
- package/dist/dom/types/css/values.d.ts +0 -1
- package/dist/dom/types/events/DataTransfer.d.ts +3 -2
- package/dist/dom/types/events/handler-names.d.ts +4 -0
- package/dist/dom/types/events/handlers.d.ts +1 -5
- package/dist/dom/types/events/listeners.d.ts +10 -7
- package/dist/dom/types/html/events.d.ts +14 -8
- package/dist/dom/types/html/focus.d.ts +0 -2
- package/dist/dom/types/html/forms/HTMLOptionElement.d.ts +8 -0
- package/dist/dom/types/html/forms/HTMLSelectElement.d.ts +20 -3
- package/dist/dom/types/html/forms/collections.d.ts +14 -2
- package/dist/dom/types/html/forms/control-state.d.ts +5 -0
- package/dist/dom/types/html/forms/face.d.ts +1 -2
- package/dist/dom/types/html/forms/form-associated.d.ts +4 -2
- package/dist/dom/types/html/forms/index.d.ts +1 -2
- package/dist/dom/types/html/forms/microsyntaxes.d.ts +0 -3
- package/dist/dom/types/html/forms/state.d.ts +0 -1
- package/dist/dom/types/html/reflect.d.ts +0 -4
- package/dist/dom/types/html/resources.d.ts +0 -2
- package/dist/dom/types/html/shared.d.ts +0 -2
- package/dist/dom/types/html/template.d.ts +0 -3
- package/dist/dom/types/html/top-layer.d.ts +26 -3
- package/dist/dom/types/keys.d.ts +19 -1
- package/dist/dom/types/nodes/Document.d.ts +11 -3
- package/dist/dom/types/nodes/attributes.d.ts +3 -0
- package/dist/dom/types/nodes/traverse.d.ts +10 -4
- package/dist/dom/types/observers/MutationObserver.d.ts +5 -5
- package/dist/dom/types/observers/MutationRecord.d.ts +2 -1
- package/dist/dom/types/observers/queue.d.ts +19 -20
- package/dist/dom/types/parser/index.d.ts +1 -1
- package/dist/dom/types/parser/tokenizer.d.ts +0 -2
- package/dist/dom/types/selectors/compile.d.ts +2 -2
- package/dist/dom/types/selectors/index.d.ts +2 -6
- package/dist/dom/types/selectors/internal.d.ts +3 -6
- package/dist/dom/types/selectors/parser.d.ts +0 -5
- package/dist/dom/types/selectors/state.d.ts +0 -5
- package/dist/dom/types/serializer/index.d.ts +0 -2
- package/dist/dom/types/traversal/Range.d.ts +1 -3
- package/dist/dom/types/traversal/live.d.ts +8 -4
- package/dist/dom/types/{events/convert.d.ts → webidl-convert.d.ts} +0 -2
- package/dist/dom/types/window/FileReader.d.ts +6 -2
- package/dist/dom/types/window/Storage.d.ts +16 -5
- package/dist/dom/types/window/Window.d.ts +2 -2
- package/dist/dom/types/window/clock.d.ts +21 -14
- package/dist/dom/types/window/devtools-console.d.ts +2 -0
- package/dist/dom/types/window/shared-accessors.d.ts +9 -0
- package/dist/dom/types/window/timers.d.ts +10 -6
- package/dist/jest-dom/_chunks/matchers-DGsBvtWC.js +1 -1
- package/dist/react/_chunks/pure-0apusBJy.cjs +1 -0
- package/dist/react/_chunks/pure-CRYsLxrp.js +1 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/pure.cjs +1 -1
- package/dist/react/pure.js +1 -1
- package/dist/react/types/config.d.ts +3 -1
- package/dist/react/types/fire-event.d.ts +1 -1
- package/dist/react/types/pure.d.ts +2 -2
- package/dist/testing-library/_chunks/aria-snapshot-diff-BSXxnyqJ.js +1 -1
- package/dist/testing-library/agent.js +1 -1
- package/dist/testing-library/index.js +1 -1
- package/dist/user-event/index.cjs +16 -16
- package/dist/user-event/index.js +16 -16
- package/dist/user-event/types/ctrl-dom.d.ts +0 -13
- package/dist/user-event/types/event/selection/selectBoundaries.d.ts +2 -0
- package/dist/user-event/types/pointer/index.d.ts +1 -1
- package/dist/user-event/types/pointer/parseKeyDef.d.ts +2 -5
- package/dist/user-event/types/setup/dtl.d.ts +0 -2
- package/dist/user-event/types/system/index.d.ts +2 -1
- package/dist/user-event/types/system/keyboard.d.ts +1 -1
- package/dist/user-event/types/system/pointer/device.d.ts +5 -4
- package/dist/user-event/types/utility/upload.d.ts +1 -4
- package/dist/user-event/types/utils/keyDef/readNextDescriptor.d.ts +1 -1
- package/dist/vitest-environment/failure-snapshot.js +1 -1
- package/dist/vitest-environment/plugin.js +1 -1
- package/dist/vitest-environment/types/warm-forks.d.ts +0 -7
- package/package.json +2 -3
- package/dist/dom/_chunks/src-DqpTBH8Z.js +0 -50
- package/dist/react/_chunks/pure-C0lYKcec.js +0 -1
- package/dist/react/_chunks/pure-xBh9btvi.cjs +0 -1
- package/dist/react/types/dtl.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# @ctrl/dom
|
|
2
2
|
|
|
3
3
|
A DOM for testing React components. It replaces jsdom or happy-dom, and ships its own Testing
|
|
4
|
-
Library, user-event and jest-dom built on it. A 100-file React suite runs in
|
|
5
|
-
stack against
|
|
4
|
+
Library, user-event and jest-dom built on it. A 100-file React suite runs in 2.4 s with the whole
|
|
5
|
+
stack against 11.6 s on jsdom and 8.6 s on happy-dom, in less memory than either (Vitest, 4
|
|
6
|
+
workers, Apple M4 Max).
|
|
6
7
|
|
|
7
8
|
- **Drop-in.** Same globals as jsdom, and Testing Library implementations with the same
|
|
8
9
|
exports, behavior, error messages and `prettyDOM` output as `@testing-library/dom`, `/react`,
|
|
@@ -71,9 +72,10 @@ matters most for component tests:
|
|
|
71
72
|
is usually starting a worker for every file, not the tests.
|
|
72
73
|
- **[Pool](https://vitest.dev/guide/improving-performance#pool).** With many test files this is
|
|
73
74
|
the setting that matters. `pool: "vmThreads"` reuses workers and gives each file a fresh
|
|
74
|
-
context: 1,000 short React test files went from 18.
|
|
75
|
-
([`vmMemoryLimit`](https://vitest.dev/config/vmmemorylimit)), and
|
|
76
|
-
for values that come from Node (an error from `fs`, a `Buffer`); DOM
|
|
75
|
+
context: 1,000 short React test files went from 18.9 s to 4.2 s on an Apple M4 Max (13 workers).
|
|
76
|
+
It uses more memory ([`vmMemoryLimit`](https://vitest.dev/config/vmmemorylimit)), and
|
|
77
|
+
`instanceof` no longer holds for values that come from Node (an error from `fs`, a `Buffer`); DOM
|
|
78
|
+
objects are unaffected.
|
|
77
79
|
- **[Test isolation](https://vitest.dev/guide/improving-performance#test-isolation).** Rather
|
|
78
80
|
than `isolate: false`, use `ctrlDom({ sharedWorkers: true })`: it sets that and resets the
|
|
79
81
|
window between files, which stock Testing Library's cleanup does not do past a worker's first
|
|
@@ -83,103 +85,6 @@ matters most for component tests:
|
|
|
83
85
|
- **Watch mode while you work.** A one-file `vitest run` is mostly Vitest starting; `vitest` pays
|
|
84
86
|
that once.
|
|
85
87
|
|
|
86
|
-
DOM only (stock Testing Library packages keep working):
|
|
87
|
-
|
|
88
|
-
```ts
|
|
89
|
-
export default defineConfig({ plugins: [ctrlDom({ testingLibrary: false })] });
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Options go to the plugin: `ctrlDom({ url: "http://localhost:3000/", width: 1280 })`. With the
|
|
93
|
-
plugin installed, a file can also pick the environment itself: `// @vitest-environment ctrl-dom`.
|
|
94
|
-
An `environment` you set in the config other than `"ctrl-dom"` stays the project's default.
|
|
95
|
-
|
|
96
|
-
The plugin also looks after Vitest's workers, since the default pool starts one per test file:
|
|
97
|
-
with its Testing Library it turns Node's compile cache on as each worker starts (so Vitest's own
|
|
98
|
-
worker modules load from it too, not only the DOM), and it starts the next files' workers ahead
|
|
99
|
-
of time ([warm workers](#warm-workers)).
|
|
100
|
-
|
|
101
|
-
### Faster runs
|
|
102
|
-
|
|
103
|
-
`ctrlDom()` alone is the safe setup: a new process for every test file, as Vitest does by default,
|
|
104
|
-
with each file's process started ahead of time ([warm workers](#warm-workers)). For a small suite
|
|
105
|
-
that is all you need.
|
|
106
|
-
|
|
107
|
-
For a large suite, change the pool. Most of what a short component test costs is starting its
|
|
108
|
-
worker, not the test, and that cost is per file. The same React test files on each option, with
|
|
109
|
-
Vitest's default of 15 workers on a 16-thread machine:
|
|
110
|
-
|
|
111
|
-
| | 100 files | 1,000 files | Memory, 1,000 files | What changes for your tests |
|
|
112
|
-
| --- | ---: | ---: | --- | --- |
|
|
113
|
-
| `ctrlDom()` (Vitest's default pool) | 2.56 s | 18.7 s | ~100 MB per worker (1.5 GB for 15) | Nothing. A new process for every test file. |
|
|
114
|
-
| `test: { pool: "threads" }` | 2.33 s | 16.7 s | | A new thread per file instead of a process: `process.chdir()` throws, and native addons must be thread-safe. |
|
|
115
|
-
| `test: { pool: "vmThreads" }` | 1.61 s | **7.0 s** | 4.0 GB at peak | Workers are reused, and each file gets a fresh global scope and module graph in them: how Jest isolates. See below. |
|
|
116
|
-
| `test: { pool: "vmForks" }` | 1.64 s | 7.3 s | 273 MB per worker, up to 527 MB | The same, in processes instead of threads. |
|
|
117
|
-
| `ctrlDom({ sharedWorkers: true })` | | | | Files of a worker share one realm; the plugin resets the window and re-evaluates your own modules before each file. Base UI's 9,199 tests: 35 s → 7–8 s. [Shared workers](#shared-workers). |
|
|
118
|
-
|
|
119
|
-
Medians of 3–5 runs, i5-12600K, Node 26.13.1. With 4 workers and 1,000 files: 24.3 s by default,
|
|
120
|
-
11.9 s on `vmThreads`.
|
|
121
|
-
|
|
122
|
-
**`pool: "vmThreads"` is the one to try first on a large suite: 2.7× faster here**, and the gap
|
|
123
|
-
grows with the number of files. Two things to check when you switch:
|
|
124
|
-
|
|
125
|
-
- **Memory.** Reused workers hold on to the modules of every file they have run. Vitest recycles
|
|
126
|
-
a worker when it passes [`vmMemoryLimit`](https://vitest.dev/config/#vmmemorylimit); lower it
|
|
127
|
-
if CI runs out.
|
|
128
|
-
- **`instanceof` on values from Node.** Each file's globals are its own, so an error thrown by
|
|
129
|
-
`fs` or `fetch`, or a `Buffer`, is not an instance of the file's `Error` or `Uint8Array`. DOM
|
|
130
|
-
objects are fine: `@ctrl/dom`'s classes are shared with every file.
|
|
131
|
-
|
|
132
|
-
`sharedWorkers` is the other way to reuse workers. Files then share one set of globals, so
|
|
133
|
-
`instanceof` holds, but they also share module state in dependencies, and memory grows there too.
|
|
134
|
-
Do not set `isolate: false` yourself: stock Testing Library then cleans up after a worker's first
|
|
135
|
-
file only, which `sharedWorkers` handles.
|
|
136
|
-
|
|
137
|
-
While you work, use watch mode: `vitest run` on one file is about 0.9 s for a 0.02 s test, and
|
|
138
|
-
`vitest` pays the start once and keeps a worker ready for the file you just saved.
|
|
139
|
-
|
|
140
|
-
DOM only (stock Testing Library packages keep working):
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
export default defineConfig({ plugins: [ctrlDom({ testingLibrary: false })] });
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Options go to the plugin: `ctrlDom({ url: "http://localhost:3000/", width: 1280 })`. With the
|
|
147
|
-
plugin installed, a file can also pick the environment itself: `// @vitest-environment ctrl-dom`.
|
|
148
|
-
An `environment` you set in the config other than `"ctrl-dom"` stays the project's default.
|
|
149
|
-
|
|
150
|
-
The plugin also looks after Vitest's workers, since the default pool starts one per test file:
|
|
151
|
-
with its Testing Library it turns Node's compile cache on as each worker starts (so Vitest's own
|
|
152
|
-
worker modules load from it too, not only the DOM), and it starts the next files' workers ahead
|
|
153
|
-
of time ([warm workers](#warm-workers)).
|
|
154
|
-
|
|
155
|
-
### Faster runs
|
|
156
|
-
|
|
157
|
-
Most of what a suite of short component tests costs is not the tests: a file that renders a form
|
|
158
|
-
and clicks through it runs in about 20 ms, and starting a worker for it takes several times that.
|
|
159
|
-
Vitest prints the split at the end of a run (`Duration … environment 40%, tests 25%, …`). When
|
|
160
|
-
`tests` is the small share, this section pays.
|
|
161
|
-
|
|
162
|
-
1. **Start with `ctrlDom()` and nothing else.** It already does the safe things: this package's
|
|
163
|
-
Testing Library, the compile cache, warm workers. Prefer it to `environment: "ctrl-dom"` alone,
|
|
164
|
-
which gets you the DOM and none of that.
|
|
165
|
-
2. **Use watch mode while you work.** `vitest run` on one file is about 0.9 s, of which the test
|
|
166
|
-
is 0.02 s; the rest is Vitest starting. `vitest` pays that once and keeps a worker ready, so
|
|
167
|
-
the file you just saved starts immediately.
|
|
168
|
-
3. **Leave `maxWorkers` alone** unless the machine is busy with something else.
|
|
169
|
-
4. **For more, trade isolation for speed deliberately.** The same 100 React test files:
|
|
170
|
-
|
|
171
|
-
| | 4 workers | 15 workers | What changes for your tests |
|
|
172
|
-
| --- | ---: | ---: | --- |
|
|
173
|
-
| `ctrlDom()` (Vitest's default pool) | 2.86 s | 2.56 s | Nothing. A new process for every test file. |
|
|
174
|
-
| `test: { pool: "threads" }` | 3.60 s | 2.33 s | A new thread for every file instead of a process: `process.chdir()` throws, and native addons must be thread-safe. Only ahead when every core is busy. |
|
|
175
|
-
| `test: { pool: "vmThreads" }` | 2.05 s | 1.61 s | Workers are reused; each file gets a fresh global scope and module graph in them, which is how Jest isolates. Objects Node itself creates (an error from `fs` or `fetch`, a `Buffer`) come from outside that scope, so `instanceof Error` on them is false, and memory grows until a worker is recycled (`vmMemoryLimit`). `vmForks` is the same with processes: 2.16 s / 1.64 s. |
|
|
176
|
-
| `ctrlDom({ sharedWorkers: true })` | | | Files of a worker share one realm; the plugin resets the window and re-evaluates your own modules before each file. Module state in dependencies carries over. Base UI's 9,199 tests: 35 s → 7–8 s. [Shared workers](#shared-workers). |
|
|
177
|
-
|
|
178
|
-
Medians of 5 runs, i5-12600K (16 threads), Node 26.13.1. Whether a suite passes on `vmThreads`
|
|
179
|
-
unchanged comes down to those `instanceof` checks on values from Node: run the whole suite on it
|
|
180
|
-
before committing to it. Do not set `isolate: false` yourself: stock Testing Library
|
|
181
|
-
then cleans up after a worker's first file only, which `sharedWorkers` exists to handle.
|
|
182
|
-
|
|
183
88
|
## Jest
|
|
184
89
|
|
|
185
90
|
```sh
|
|
@@ -408,9 +313,11 @@ started.
|
|
|
408
313
|
|
|
409
314
|
| 100 React test files | without | with |
|
|
410
315
|
| --- | ---: | ---: |
|
|
411
|
-
| 4 workers on
|
|
412
|
-
|
|
|
413
|
-
|
|
|
316
|
+
| 4 workers on 14 cores | 3.52 s | 2.29 s |
|
|
317
|
+
| 7 workers on 14 cores (what `vitest` in watch mode uses) | 2.47 s | 2.14 s |
|
|
318
|
+
| 13 workers on 14 cores (what `vitest run` uses) | 2.15 s | 2.07 s |
|
|
319
|
+
|
|
320
|
+
Medians of 5 runs, 2026-11-21, Apple M4 Max, Node 26.13.1.
|
|
414
321
|
|
|
415
322
|
It needs idle cores to boot on, so it helps most where Vitest runs fewer workers than the machine
|
|
416
323
|
has cores: watch mode, a `maxWorkers` setting, CI machines. In watch mode one worker stays ready
|