@ctrl/dom 0.1.4 → 0.1.6

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.
Files changed (59) hide show
  1. package/dist/aria/_chunks/roles-list-BXCvPLJT.cjs +4 -0
  2. package/dist/aria/_chunks/roles-list-rVVxaIPs.js +4 -0
  3. package/dist/aria/index.cjs +1 -232
  4. package/dist/aria/index.js +1 -198
  5. package/dist/aria/internal.cjs +1 -69
  6. package/dist/aria/internal.js +1 -30
  7. package/dist/cli/_chunks/report-z52LF7nA.js +12 -0
  8. package/dist/cli/_chunks/rolldown-runtime-H3fMLYWS.js +1 -0
  9. package/dist/cli/ctrl-dom.js +2 -181
  10. package/dist/cli/jest-reporter.js +2 -54
  11. package/dist/cli/vitest-reporter.js +2 -81
  12. package/dist/dom/_chunks/src-sZY6a2LC.js +49 -0
  13. package/dist/dom/index.js +1 -3
  14. package/dist/dom/internal.js +1 -434
  15. package/dist/dom/types/window/clock.d.ts +2 -2
  16. package/dist/jest-dom/_chunks/matchers-CGTk9GX9.cjs +31 -0
  17. package/dist/jest-dom/_chunks/matchers-Chf0yHoo.js +31 -0
  18. package/dist/jest-dom/index.cjs +1 -5
  19. package/dist/jest-dom/index.js +1 -6
  20. package/dist/jest-dom/jest-globals.cjs +1 -6
  21. package/dist/jest-dom/jest-globals.js +1 -7
  22. package/dist/jest-dom/matchers.cjs +1 -53
  23. package/dist/jest-dom/matchers.js +1 -3
  24. package/dist/jest-dom/vitest.cjs +1 -6
  25. package/dist/jest-dom/vitest.js +1 -7
  26. package/dist/react/_chunks/pure-CCeTO5Mk.js +1 -0
  27. package/dist/react/_chunks/pure-DQzwul4s.cjs +1 -0
  28. package/dist/react/dont-cleanup-after-each.cjs +1 -3
  29. package/dist/react/dont-cleanup-after-each.js +1 -4
  30. package/dist/react/index.cjs +1 -47
  31. package/dist/react/index.js +1 -35
  32. package/dist/react/pure.cjs +1 -17
  33. package/dist/react/pure.js +1 -5
  34. package/dist/register/index.js +1 -11
  35. package/dist/register/pure.js +1 -147
  36. package/dist/testing-library/_chunks/aria-snapshot-diff--o7AL030.cjs +14 -0
  37. package/dist/testing-library/_chunks/aria-snapshot-diff-BV9IkeNc.js +14 -0
  38. package/dist/testing-library/agent.cjs +10 -720
  39. package/dist/testing-library/agent.js +10 -712
  40. package/dist/testing-library/index.cjs +19 -2459
  41. package/dist/testing-library/index.js +19 -2380
  42. package/dist/user-event/index.cjs +33 -3924
  43. package/dist/user-event/index.js +33 -3899
  44. package/dist/user-event/types/ctrl-dom.d.ts +1 -1
  45. package/dist/vitest-environment/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
  46. package/dist/vitest-environment/failure-snapshot.js +1 -42
  47. package/dist/vitest-environment/index.js +1 -185
  48. package/dist/vitest-environment/plugin.js +1 -90
  49. package/package.json +6 -6
  50. package/dist/aria/_chunks/roles-list-CYZF-l9K.js +0 -1503
  51. package/dist/aria/_chunks/roles-list-D4WCyRO_.cjs +0 -1754
  52. package/dist/cli/_chunks/report-DdncYfuJ.js +0 -93
  53. package/dist/dom/_chunks/src-Cp3oLry4.js +0 -47610
  54. package/dist/jest-dom/_chunks/matchers-CDnnXUfG.js +0 -2211
  55. package/dist/jest-dom/_chunks/matchers-D988Ducb.cjs +0 -2516
  56. package/dist/react/_chunks/pure-DZ97z2oT.cjs +0 -498
  57. package/dist/react/_chunks/pure-PtE2hivW.js +0 -420
  58. package/dist/testing-library/_chunks/aria-snapshot-diff-D7PzpXew.cjs +0 -1170
  59. package/dist/testing-library/_chunks/aria-snapshot-diff-Q8Wj33K0.js +0 -985
@@ -1,420 +0,0 @@
1
- import * as React from "react";
2
- import * as ReactDOMClient from "react-dom/client";
3
- import { traceSync, tracing } from "@ctrl/dom/internal";
4
-
5
- // \0rolldown/runtime.js
6
- var __defProp = Object.defineProperty;
7
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
- var __getOwnPropNames = Object.getOwnPropertyNames;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __exportAll = (all, no_symbols) => {
11
- let target = {};
12
- for (var name in all) {
13
- __defProp(target, name, {
14
- get: all[name],
15
- enumerable: true
16
- });
17
- }
18
- if (!no_symbols) {
19
- __defProp(target, Symbol.toStringTag, { value: "Module" });
20
- }
21
- return target;
22
- };
23
- var __copyProps = (to, from, except, desc) => {
24
- if (from && typeof from === "object" || typeof from === "function") {
25
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
26
- key = keys[i];
27
- if (!__hasOwnProp.call(to, key) && key !== except) {
28
- __defProp(to, key, {
29
- get: ((k) => from[k]).bind(null, key),
30
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
31
- });
32
- }
33
- }
34
- }
35
- return to;
36
- };
37
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
38
-
39
- // src/act-compat.ts
40
- const reactAct = React.act;
41
- function setReactActEnvironment(isReactActEnvironment) {
42
- globalThis.IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
43
- }
44
- function getIsReactActEnvironment() {
45
- return globalThis.IS_REACT_ACT_ENVIRONMENT;
46
- }
47
- function isThenable(value) {
48
- return value !== null && typeof value === "object" && typeof value.then === "function";
49
- }
50
- function withGlobalActEnvironment(actImplementation) {
51
- return (callback) => {
52
- const previousActEnvironment = getIsReactActEnvironment();
53
- setReactActEnvironment(true);
54
- try {
55
- let callbackNeedsToBeAwaited = false;
56
- const actResult = actImplementation(() => {
57
- const result = callback();
58
- if (isThenable(result)) callbackNeedsToBeAwaited = true;
59
- return result;
60
- });
61
- if (callbackNeedsToBeAwaited) {
62
- const thenable = actResult;
63
- return { then: (resolve, reject) => {
64
- thenable.then((returnValue) => {
65
- setReactActEnvironment(previousActEnvironment);
66
- resolve(returnValue);
67
- }, (error) => {
68
- setReactActEnvironment(previousActEnvironment);
69
- reject(error);
70
- });
71
- } };
72
- }
73
- setReactActEnvironment(previousActEnvironment);
74
- return actResult;
75
- } catch (error) {
76
- setReactActEnvironment(previousActEnvironment);
77
- throw error;
78
- }
79
- };
80
- }
81
- /** `React.act` with `IS_REACT_ACT_ENVIRONMENT` set to true for its duration. */
82
- const act = withGlobalActEnvironment(reactAct);
83
-
84
- // src/dtl.ts
85
- var dtl_exports = /* @__PURE__ */ __exportAll({});
86
- import * as import__ctrl_dom_testing_library from "@ctrl/dom/testing-library";
87
- __reExport(dtl_exports, import__ctrl_dom_testing_library);
88
-
89
- // src/fire-event.ts
90
- const fireEvent = ((...args) => (0, dtl_exports.fireEvent)(...args));
91
- const fe = fireEvent;
92
- const dtl = dtl_exports.fireEvent;
93
- for (const key of Object.keys(dtl_exports.fireEvent)) fe[key] = (...args) => dtl[key](...args);
94
- const mouseEnter = fe.mouseEnter;
95
- const mouseLeave = fe.mouseLeave;
96
- fe.mouseEnter = (...args) => {
97
- mouseEnter(...args);
98
- return fe.mouseOver(...args);
99
- };
100
- fe.mouseLeave = (...args) => {
101
- mouseLeave(...args);
102
- return fe.mouseOut(...args);
103
- };
104
- const pointerEnter = fe.pointerEnter;
105
- const pointerLeave = fe.pointerLeave;
106
- fe.pointerEnter = (...args) => {
107
- pointerEnter(...args);
108
- return fe.pointerOver(...args);
109
- };
110
- fe.pointerLeave = (...args) => {
111
- pointerLeave(...args);
112
- return fe.pointerOut(...args);
113
- };
114
- const select = fe.select;
115
- fe.select = (node, init) => {
116
- select(node, init);
117
- node.focus();
118
- fe.keyUp(node, init);
119
- };
120
- const blur = fe.blur;
121
- const focus = fe.focus;
122
- fe.blur = (...args) => {
123
- fe.focusOut(...args);
124
- return blur(...args);
125
- };
126
- fe.focus = (...args) => {
127
- fe.focusIn(...args);
128
- return focus(...args);
129
- };
130
-
131
- // src/config.ts
132
- let configForRTL = { reactStrictMode: false };
133
- function getConfig() {
134
- return {
135
- ...(0, dtl_exports.getConfig)(),
136
- ...configForRTL
137
- };
138
- }
139
- function configure(newConfig) {
140
- if (typeof newConfig === "function") newConfig = newConfig(getConfig());
141
- const { reactStrictMode, ...configForDTL } = newConfig;
142
- (0, dtl_exports.configure)(configForDTL);
143
- configForRTL = {
144
- ...configForRTL,
145
- reactStrictMode
146
- };
147
- }
148
-
149
- // src/pure.ts
150
- var pure_exports = /* @__PURE__ */ __exportAll({
151
- act: () => act,
152
- cleanup: () => cleanup,
153
- configure: () => configure,
154
- fireEvent: () => fireEvent,
155
- getConfig: () => getConfig,
156
- render: () => render,
157
- renderHook: () => renderHook
158
- });
159
- __reExport(pure_exports, dtl_exports);
160
- function jestFakeTimersAreEnabled() {
161
- if (typeof jest !== "undefined" && jest !== null) return setTimeout._isMockFunction === true || Object.prototype.hasOwnProperty.call(setTimeout, "clock");
162
- return false;
163
- }
164
- let inEventWrapper = false;
165
- (0, dtl_exports.configure)({
166
- unstable_advanceTimersWrapper: (cb) => {
167
- return act(cb);
168
- },
169
- asyncWrapper: async (cb) => {
170
- const previousActEnvironment = getIsReactActEnvironment();
171
- setReactActEnvironment(false);
172
- try {
173
- const result = await cb();
174
- await new Promise((resolve) => {
175
- setTimeout(() => {
176
- resolve();
177
- }, 0);
178
- if (jestFakeTimersAreEnabled()) jest.advanceTimersByTime(0);
179
- });
180
- return result;
181
- } finally {
182
- setReactActEnvironment(previousActEnvironment);
183
- }
184
- },
185
- eventWrapper: (cb) => {
186
- if (inEventWrapper) return cb();
187
- inEventWrapper = true;
188
- try {
189
- let result;
190
- act(() => {
191
- result = cb();
192
- });
193
- return result;
194
- } finally {
195
- inEventWrapper = false;
196
- }
197
- }
198
- });
199
- const mountedContainers = /* @__PURE__ */ new Set();
200
- const mountedRootEntries = [];
201
- function strictModeIfNeeded(innerElement, reactStrictMode) {
202
- return reactStrictMode ?? getConfig().reactStrictMode ? React.createElement(React.StrictMode, null, innerElement) : innerElement;
203
- }
204
- function wrapUiIfNeeded(innerElement, wrapperComponent) {
205
- return wrapperComponent ? React.createElement(wrapperComponent, null, innerElement) : innerElement;
206
- }
207
- function createConcurrentRoot(container, { hydrate, onCaughtError, onRecoverableError, ui, wrapper: WrapperComponent, reactStrictMode }) {
208
- let root;
209
- if (hydrate) act(() => {
210
- root = ReactDOMClient.hydrateRoot(container, strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent), reactStrictMode), {
211
- onCaughtError,
212
- onRecoverableError
213
- });
214
- });
215
- else root = ReactDOMClient.createRoot(container, {
216
- onCaughtError,
217
- onRecoverableError
218
- });
219
- return {
220
- hydrate() {
221
- if (!hydrate) throw new Error("Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.");
222
- },
223
- render(element) {
224
- root.render(element);
225
- },
226
- unmount() {
227
- root.unmount();
228
- }
229
- };
230
- }
231
- const defaultBoundQueries = /* @__PURE__ */ new WeakMap();
232
- function boundQueriesFor(baseElement, customQueries) {
233
- if (customQueries !== void 0) return (0, dtl_exports.getQueriesForElement)(baseElement, customQueries);
234
- let bound = defaultBoundQueries.get(baseElement);
235
- if (bound === void 0) {
236
- bound = (0, dtl_exports.getQueriesForElement)(baseElement);
237
- defaultBoundQueries.set(baseElement, bound);
238
- }
239
- return bound;
240
- }
241
- function renderRoot(ui, { baseElement, container, hydrate, queries, root, wrapper: WrapperComponent, reactStrictMode }) {
242
- act(() => {
243
- if (hydrate) root.hydrate();
244
- else root.render(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent), reactStrictMode));
245
- });
246
- return {
247
- container,
248
- baseElement,
249
- debug: (el = baseElement, maxLength, options) => Array.isArray(el) ? el.forEach((e) => console.log((0, dtl_exports.prettyDOM)(e, maxLength, options))) : console.log((0, dtl_exports.prettyDOM)(el, maxLength, options)),
250
- unmount: () => {
251
- act(() => {
252
- root.unmount();
253
- });
254
- },
255
- rerender: (rerenderUi) => {
256
- const rerender = () => renderRoot(rerenderUi, {
257
- container,
258
- baseElement,
259
- root,
260
- wrapper: WrapperComponent,
261
- reactStrictMode
262
- });
263
- if (tracing()) traceSync("react.rerender", `rerender(${describeElement(rerenderUi)})`, rerender);
264
- else rerender();
265
- },
266
- asFragment: () => {
267
- if (typeof document.createRange === "function") return document.createRange().createContextualFragment(container.innerHTML);
268
- const template = document.createElement("template");
269
- template.innerHTML = container.innerHTML;
270
- return template.content;
271
- },
272
- ...boundQueriesFor(baseElement, queries)
273
- };
274
- }
275
- function legacyRootError(callee) {
276
- const error = /* @__PURE__ */ new Error("`legacyRoot: true` is not supported in this version of React. If your app runs React 19 or later, you should remove this flag. If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.");
277
- Error.captureStackTrace(error, callee);
278
- return error;
279
- }
280
- function render(ui, options) {
281
- if (!tracing()) return renderUntraced(ui, options);
282
- return traceSync("react.render", `render(${describeElement(ui)})`, () => renderUntraced(ui, options));
283
- }
284
- /**
285
- * `<Signup />` for a React element: the component under test, through wrappers that test helpers
286
- * add (providers, StrictMode, fragments, a data router's route element, as in a
287
- * `render(<RouterProvider router={createMemoryRouter([{ element: <Providers>{ui}</Providers> }])} />)` helper).
288
- */
289
- function describeElement(ui) {
290
- if (!React.isValidElement(ui)) return typeof ui === "string" ? JSON.stringify(ui) : String(ui);
291
- let element = ui;
292
- for (let depth = 0; depth < 10; depth++) {
293
- const inner = isWrapper(element) ? wrappedElement(element) : null;
294
- if (inner === null) break;
295
- element = inner;
296
- }
297
- return describeTree(element, 0);
298
- }
299
- /** `<Signup />`; a host element shows what it holds: `<div><Checkbox /></div>`, `<div>…</div>`. */
300
- function describeTree(element, depth) {
301
- const name = componentName(element.type) || "Component";
302
- if (typeof element.type !== "string") return `<${name} />`;
303
- const children = element.props.children;
304
- if (children === void 0 || children === null || children === false) return `<${name} />`;
305
- const only = onlyElement(children);
306
- return only !== null && depth < 2 ? `<${name}>${describeTree(only, depth + 1)}</${name}>` : `<${name}>…</${name}>`;
307
- }
308
- /** A component's display name, without the `$1` suffix bundlers add when names collide. */
309
- function componentName(type) {
310
- if (typeof type === "string") return type;
311
- if (typeof type === "symbol") return type.description?.replace(/^react\./, "") ?? "";
312
- const t = type;
313
- return (t?.displayName ?? t?.name ?? t?.render?.name ?? t?.type?.name ?? "").replace(/\$\d+$/, "");
314
- }
315
- const WRAPPER = /(?:Providers?|Context|Router|Wrapper|Fragment|StrictMode|Suspense|Profiler)$/;
316
- /**
317
- * Providers, routers and the like, plus anonymous components with a single child element: test
318
- * helpers build their wrappers in factories (`makeAllTheProviders()` returning a function).
319
- */
320
- function isWrapper(element) {
321
- if (typeof element.type === "symbol") return true;
322
- const name = componentName(element.type);
323
- return WRAPPER.test(name) || name === "" && onlyElement(element.props.children) !== null;
324
- }
325
- /** The one element a wrapper renders: its only child, or a data router's first route element. */
326
- function wrappedElement(element) {
327
- const props = element.props;
328
- return onlyElement(props.children) ?? firstRouteElement(props.router?.routes);
329
- }
330
- /** The first route element that is not an `<Outlet />` (a layout route's), depth first. */
331
- function firstRouteElement(routes) {
332
- for (const route of routes ?? []) {
333
- const element = onlyElement(route.element);
334
- if (element !== null && componentName(element.type) !== "Outlet") return element;
335
- const nested = firstRouteElement(route.children);
336
- if (nested !== null) return nested;
337
- }
338
- return null;
339
- }
340
- function onlyElement(node) {
341
- if (React.isValidElement(node)) return node;
342
- if (!Array.isArray(node)) return null;
343
- const elements = node.filter((n) => React.isValidElement(n));
344
- return elements.length === 1 ? elements[0] : null;
345
- }
346
- function renderUntraced(ui, { container, baseElement = container, legacyRoot = false, onCaughtError, onUncaughtError, onRecoverableError, queries, hydrate = false, wrapper, reactStrictMode } = {}) {
347
- if (onUncaughtError !== void 0) throw new Error("onUncaughtError is not supported. The `render` call will already throw on uncaught errors.");
348
- if (legacyRoot) throw legacyRootError(render);
349
- if (!baseElement) baseElement = document.body;
350
- if (!container) container = baseElement.appendChild(document.createElement("div"));
351
- let root;
352
- if (!mountedContainers.has(container)) {
353
- root = createConcurrentRoot(container, {
354
- hydrate,
355
- onCaughtError,
356
- onRecoverableError,
357
- ui,
358
- wrapper,
359
- reactStrictMode
360
- });
361
- mountedRootEntries.push({
362
- container,
363
- root
364
- });
365
- mountedContainers.add(container);
366
- } else for (let i = 0; i < mountedRootEntries.length; i++) {
367
- const rootEntry = mountedRootEntries[i];
368
- if (rootEntry.container === container) root = rootEntry.root;
369
- }
370
- return renderRoot(ui, {
371
- container,
372
- baseElement,
373
- queries,
374
- hydrate,
375
- wrapper,
376
- root,
377
- reactStrictMode
378
- });
379
- }
380
- /**
381
- * Unmounts React trees that were mounted with render.
382
- */
383
- function cleanup() {
384
- for (let i = 0; i < mountedRootEntries.length; i++) {
385
- const { root, container } = mountedRootEntries[i];
386
- act(() => {
387
- root.unmount();
388
- });
389
- if (container.parentNode === document.body) document.body.removeChild(container);
390
- }
391
- mountedRootEntries.length = 0;
392
- mountedContainers.clear();
393
- }
394
- /**
395
- * Allows you to render a hook within a test React component without having to create that
396
- * component yourself.
397
- */
398
- function renderHook(renderCallback, options = {}) {
399
- const { initialProps, ...renderOptions } = options;
400
- if (renderOptions.legacyRoot) throw legacyRootError(renderHook);
401
- const result = React.createRef();
402
- function TestComponent({ renderCallbackProps }) {
403
- const pendingResult = renderCallback(renderCallbackProps);
404
- React.useEffect(() => {
405
- result.current = pendingResult;
406
- });
407
- return null;
408
- }
409
- const { rerender: baseRerender, unmount } = render(React.createElement(TestComponent, { renderCallbackProps: initialProps }), renderOptions);
410
- function rerender(rerenderCallbackProps) {
411
- return baseRerender(React.createElement(TestComponent, { renderCallbackProps: rerenderCallbackProps }));
412
- }
413
- return {
414
- result,
415
- rerender,
416
- unmount
417
- };
418
- }
419
-
420
- export { configure as a, act as c, __exportAll as d, __reExport as f, renderHook as i, getIsReactActEnvironment as l, pure_exports as n, getConfig as o, render as r, fireEvent as s, cleanup as t, setReactActEnvironment as u };