@rind-ui/testing 0.2.0 → 0.3.0
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/dist/{adapter-UPhu17S6.d.mts → adapter-B05M46SW.d.mts} +18 -1
- package/dist/{compose-DPLnCCnJ.mjs → compose-BpR_PG11.mjs} +34 -2
- package/dist/{dom-DZtl6G1E.mjs → dom-Bnnr_fg-.mjs} +377 -15
- package/dist/{dom-BxnIjEBk.d.mts → dom-Ur_VPlTe.d.mts} +12 -3
- package/dist/dom.d.mts +1 -1
- package/dist/dom.mjs +1 -1
- package/dist/index.d.mts +9487 -930
- package/dist/index.mjs +2745 -47
- package/dist/inpage.iife.js +7 -4
- package/dist/{playwright-CtIxjMKr.d.mts → playwright-By15MZsN.d.mts} +6 -3
- package/dist/{playwright-C2LKzGS_.mjs → playwright-C3Ue38p3.mjs} +300 -7
- package/dist/playwright.d.mts +1 -1
- package/dist/playwright.mjs +1 -1
- package/dist/setup.mjs +1 -1
- package/package.json +4 -3
|
@@ -17,8 +17,10 @@ interface ElementInfo {
|
|
|
17
17
|
readonly inAriaHidden: boolean;
|
|
18
18
|
readonly inInert: boolean;
|
|
19
19
|
readonly focusable: boolean;
|
|
20
|
-
/** Finite animations running on the element
|
|
20
|
+
/** Finite animations running (or held) on the element: exit animations presence waits for. */
|
|
21
21
|
readonly animations: number;
|
|
22
|
+
/** Its computed style animates (a transition or animation duration above zero). */
|
|
23
|
+
readonly motion: boolean;
|
|
22
24
|
/** The element's identity across snapshots of one page (same node, same number). */
|
|
23
25
|
readonly node: number;
|
|
24
26
|
/** Its border box in viewport coordinates (all zero without layout). */
|
|
@@ -120,6 +122,17 @@ interface AdapterEnv extends Env {
|
|
|
120
122
|
announcements(): Promise<readonly Announcement[]>;
|
|
121
123
|
/** Uncaught errors and `console.error` calls since the last call. */
|
|
122
124
|
takeErrors(): Promise<readonly string[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Pauses every running animation in the document and returns their resume: holds an exit
|
|
127
|
+
* animation while the runner reopens during it, however slow the run (CI Linux).
|
|
128
|
+
*/
|
|
129
|
+
holdAnimations?(): Promise<() => Promise<void>>;
|
|
130
|
+
/**
|
|
131
|
+
* Called before a step that closes a presence layer, so its exit cannot end before
|
|
132
|
+
* `holdAnimations` runs (a slow round trip outlasts a 150 ms exit): animations starting
|
|
133
|
+
* now stay at their start until the hold, which ends this.
|
|
134
|
+
*/
|
|
135
|
+
armHold?(): Promise<void>;
|
|
123
136
|
/**
|
|
124
137
|
* Chromium accessibility-tree checks for the instance (Playwright in Chromium only):
|
|
125
138
|
* problems found, or "unavailable" elsewhere.
|
|
@@ -138,6 +151,10 @@ interface AdapterEnv extends Env {
|
|
|
138
151
|
}
|
|
139
152
|
interface EnvOptions {
|
|
140
153
|
readonly scope: string;
|
|
154
|
+
/** A hosted component's part names (the contract's `partName`): a part's `data-part`. */
|
|
155
|
+
readonly partName?: ((part: string) => string) | undefined;
|
|
156
|
+
/** The inverse: a hosted `data-part` read from the DOM, as the contract names the part. */
|
|
157
|
+
readonly anatomyName?: ((part: string) => string) | undefined;
|
|
141
158
|
readonly anchor: By;
|
|
142
159
|
readonly modality: Modality;
|
|
143
160
|
/** The platform the test runs as: decides the `mod` key (Meta on Apple, Control elsewhere). */
|
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
//#region src/adapter.ts
|
|
2
|
+
/**
|
|
3
|
+
* A contract's `partName` for the adapters: applied to its anatomy names only, so a name read
|
|
4
|
+
* back from the DOM (already the host's) is used as it is.
|
|
5
|
+
*/
|
|
6
|
+
function hostedPartName(contract) {
|
|
7
|
+
const map = contract.partName;
|
|
8
|
+
if (!map) return {};
|
|
9
|
+
const anatomy = new Set(contract.anatomy);
|
|
10
|
+
const back = new Map(contract.anatomy.map((part) => [map(part), part]));
|
|
11
|
+
return {
|
|
12
|
+
partName: (part) => anatomy.has(part) ? map(part) : part,
|
|
13
|
+
anatomyName: (part) => back.get(part) ?? part
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** A snapshot with its parts named as the contract names them (a hosted component's parts). */
|
|
17
|
+
function renamedSnapshot(snapshot, anatomyName) {
|
|
18
|
+
if (!anatomyName) return snapshot;
|
|
19
|
+
const rename = (el) => el.part === null ? el : {
|
|
20
|
+
...el,
|
|
21
|
+
part: anatomyName(el.part)
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
...snapshot,
|
|
25
|
+
parts: snapshot.parts.map(rename),
|
|
26
|
+
elements: snapshot.elements.map(rename),
|
|
27
|
+
focus: {
|
|
28
|
+
...snapshot.focus,
|
|
29
|
+
part: snapshot.focus.part === null ? null : anatomyName(snapshot.focus.part),
|
|
30
|
+
element: snapshot.focus.element === null ? null : rename(snapshot.focus.element)
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
2
34
|
const isEnvFactory = (value) => typeof value === "object" && value !== null && "~rindEnvFactory" in value;
|
|
3
35
|
/**
|
|
4
36
|
* Shared `until` loop with a deadline. Elapsed time is the larger of the wall clock and the
|
|
@@ -35,7 +67,7 @@ var UntilTimeout = class extends Error {
|
|
|
35
67
|
};
|
|
36
68
|
/** Mirrors horizontal arrows for right-to-left runs; everything else is unchanged. */
|
|
37
69
|
const mirror = (key, direction) => direction === "ltr" ? key : key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
|
|
38
|
-
const describeBy = (by) => "role" in by ? `role "${by.role}"${by.name === void 0 ? "" : ` named ${JSON.stringify(String(by.name))}`}` : "part" in by ? `part "${by.part}"` : `text ${JSON.stringify(String(by.text))}`;
|
|
70
|
+
const describeBy = (by) => "role" in by ? `role "${by.role}"${by.name === void 0 ? "" : ` named ${JSON.stringify(String(by.name))}`}` : "label" in by ? `control labelled ${JSON.stringify(String(by.label))}` : "part" in by ? `part "${by.part}"` : `text ${JSON.stringify(String(by.text))}`;
|
|
39
71
|
//#endregion
|
|
40
72
|
//#region src/adapters/compose.ts
|
|
41
73
|
/**
|
|
@@ -108,4 +140,4 @@ function composeInPage(el, { updates, commit }) {
|
|
|
108
140
|
}));
|
|
109
141
|
}
|
|
110
142
|
//#endregion
|
|
111
|
-
export {
|
|
143
|
+
export { isEnvFactory as a, renamedSnapshot as c, hostedPartName as i, UntilTimeout as n, mirror as o, describeBy as r, poll as s, composeInPage as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ANNOUNCEMENTS, KEY_DEBOUNCE_MS, PENDING_ANNOUNCEMENTS, isKeptVisible } from "@rind-ui/core";
|
|
1
|
+
import { c as renamedSnapshot, r as describeBy, s as poll, t as composeInPage } from "./compose-BpR_PG11.mjs";
|
|
2
|
+
import { ANNOUNCEMENTS, KEY_DEBOUNCE_MS, PENDING_ANNOUNCEMENTS, isKeptVisible, tabbables } from "@rind-ui/core";
|
|
3
3
|
import { computeAccessibleDescription, computeAccessibleName } from "dom-accessibility-api";
|
|
4
4
|
//#region src/announcements.ts
|
|
5
5
|
/** An announcer that only records (for machine tests in Node, or as an env override). */
|
|
@@ -52,6 +52,14 @@ const norm = (s) => (s ?? "").replace(/\s+/g, " ").trim();
|
|
|
52
52
|
* `hidden` (including `until-found`), `inert` or `display: none`, and it is not
|
|
53
53
|
* `visibility: hidden`. `display: contents` counts as visible: its children render.
|
|
54
54
|
*/
|
|
55
|
+
/** Any transition or animation duration above zero in the computed style. */
|
|
56
|
+
function hasMotion(el) {
|
|
57
|
+
const view = el.ownerDocument.defaultView;
|
|
58
|
+
if (!view) return false;
|
|
59
|
+
const cs = view.getComputedStyle(el);
|
|
60
|
+
const positive = (list) => list.split(",").some((d) => Number.parseFloat(d) > 0);
|
|
61
|
+
return positive(cs.transitionDuration || "0s") || positive(cs.animationDuration || "0s");
|
|
62
|
+
}
|
|
55
63
|
function isVisible(el) {
|
|
56
64
|
if (!el.isConnected) return false;
|
|
57
65
|
const view = el.ownerDocument.defaultView;
|
|
@@ -184,7 +192,8 @@ function collectDom(arg) {
|
|
|
184
192
|
inAriaHidden: el.closest("[aria-hidden=true]") !== null,
|
|
185
193
|
inInert: el.closest("[inert]") !== null,
|
|
186
194
|
focusable: focusable(el),
|
|
187
|
-
animations: typeof el.getAnimations === "function" ? el.getAnimations().filter((a) => a.playState === "running" && a.effect?.getComputedTiming().endTime !== Number.POSITIVE_INFINITY).length : 0,
|
|
195
|
+
animations: typeof el.getAnimations === "function" ? el.getAnimations().filter((a) => (a.playState === "running" || a.playState === "paused") && a.effect?.getComputedTiming().endTime !== Number.POSITIVE_INFINITY).length : 0,
|
|
196
|
+
motion: hasMotion(el),
|
|
188
197
|
group: groupOf(el),
|
|
189
198
|
within: ancestorIds(el)
|
|
190
199
|
});
|
|
@@ -223,6 +232,7 @@ function collectDom(arg) {
|
|
|
223
232
|
const v = sibling.getAttribute(name);
|
|
224
233
|
if (v !== null) picked[name] = v;
|
|
225
234
|
}
|
|
235
|
+
if (picked["inert"] === void 0 && sibling.parentElement?.closest("[inert]")) picked["inert"] = "";
|
|
226
236
|
if (isKeptVisible(sibling)) picked["data-rind-kept"] = "";
|
|
227
237
|
if ([
|
|
228
238
|
"SCRIPT",
|
|
@@ -413,6 +423,34 @@ const nextCoords = (el) => {
|
|
|
413
423
|
};
|
|
414
424
|
};
|
|
415
425
|
/**
|
|
426
|
+
* A point on the page itself, inside the viewport's client area (dismissal treats a press
|
|
427
|
+
* past it as a scrollbar press): the step's coordinates when they qualify, else the first
|
|
428
|
+
* viewport corner that hits only the page. Without layout (jsdom) every point is the page.
|
|
429
|
+
*/
|
|
430
|
+
const outsideCoords = () => {
|
|
431
|
+
const c = nextCoords();
|
|
432
|
+
const root = document.documentElement;
|
|
433
|
+
const page = (x, y) => {
|
|
434
|
+
if (root.clientWidth > 0 && (x >= root.clientWidth || y >= root.clientHeight)) return false;
|
|
435
|
+
const hit = document.elementFromPoint?.(x, y);
|
|
436
|
+
return !hit || hit === document.body || hit === root;
|
|
437
|
+
};
|
|
438
|
+
if (page(c.clientX, c.clientY)) return c;
|
|
439
|
+
const w = root.clientWidth;
|
|
440
|
+
const h = root.clientHeight;
|
|
441
|
+
for (const [x, y] of [
|
|
442
|
+
[w - 2, h - 2],
|
|
443
|
+
[w - 2, 2],
|
|
444
|
+
[2, h - 2]
|
|
445
|
+
]) if (page(x, y)) return {
|
|
446
|
+
clientX: x,
|
|
447
|
+
clientY: y,
|
|
448
|
+
pageX: x + window.scrollX,
|
|
449
|
+
pageY: y + window.scrollY
|
|
450
|
+
};
|
|
451
|
+
return c;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
416
454
|
* Resolves once no finite transition or animation is running in the document (or after `max`
|
|
417
455
|
* ms). A sibling panel opening shifts the target's box for a while, and a press aimed at
|
|
418
456
|
* coordinates read before the shift releases outside it (the press is then not a press).
|
|
@@ -442,6 +480,7 @@ const KEY_NAMES = {
|
|
|
442
480
|
ArrowRight: "{ArrowRight}",
|
|
443
481
|
Backspace: "{Backspace}",
|
|
444
482
|
Delete: "{Delete}",
|
|
483
|
+
F6: "{F6}",
|
|
445
484
|
F10: "{F10}",
|
|
446
485
|
ContextMenu: "{ContextMenu}",
|
|
447
486
|
A: "a"
|
|
@@ -484,9 +523,10 @@ function installErrorLog(win = globalThis.window ?? null) {
|
|
|
484
523
|
}
|
|
485
524
|
return log;
|
|
486
525
|
}
|
|
526
|
+
const isJsdom = () => (globalThis.navigator?.userAgent ?? "").includes("jsdom");
|
|
487
527
|
/** The Testing Library adapter. */
|
|
488
528
|
function domEnv(options = {}) {
|
|
489
|
-
const timeout = options.timeout ?? 1e3;
|
|
529
|
+
const timeout = options.timeout ?? (isJsdom() ? 1e3 : 3e3);
|
|
490
530
|
const doc = options.root?.ownerDocument ?? globalThis.document;
|
|
491
531
|
const errors = installErrorLog(doc?.defaultView ?? null);
|
|
492
532
|
if (doc?.defaultView) interceptNativeNavigation(doc.defaultView);
|
|
@@ -507,7 +547,7 @@ function domEnv(options = {}) {
|
|
|
507
547
|
const ACT_ENV = "IS_REACT_ACT_ENVIRONMENT";
|
|
508
548
|
/** The `key` value a native event carries for a contract key. */
|
|
509
549
|
const NATIVE_KEY = { Space: " " };
|
|
510
|
-
function createDomEnv({ scope, anchor, modality, platform }, options, getUser, errors) {
|
|
550
|
+
function createDomEnv({ scope, anchor, modality, platform, partName, anatomyName }, options, getUser, errors) {
|
|
511
551
|
const doc = () => options.root?.ownerDocument ?? document;
|
|
512
552
|
const apple = platform?.apple === true;
|
|
513
553
|
/** The navigation log's length when the current action began. */
|
|
@@ -558,7 +598,12 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
558
598
|
const name = by.name;
|
|
559
599
|
return queryAllByRole(within, by.role, { ...name === void 0 ? {} : { name: typeof name === "string" ? (n) => normalize(n) === name : name } });
|
|
560
600
|
}
|
|
561
|
-
if ("
|
|
601
|
+
if ("label" in by) {
|
|
602
|
+
const { queryAllByLabelText } = await loadTL();
|
|
603
|
+
const { label } = by;
|
|
604
|
+
return queryAllByLabelText(within, typeof label === "string" ? (n) => normalize(n) === label : label);
|
|
605
|
+
}
|
|
606
|
+
if ("part" in by) return Array.from(within.querySelectorAll(`[data-scope="${CSS.escape(scope)}"][data-part="${CSS.escape(partName?.(by.part) ?? by.part)}"]`));
|
|
562
607
|
const { text } = by;
|
|
563
608
|
const matches = (el) => {
|
|
564
609
|
const own = normalize(el.textContent);
|
|
@@ -698,6 +743,17 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
698
743
|
const el = await waitFor();
|
|
699
744
|
await act(() => el.focus());
|
|
700
745
|
},
|
|
746
|
+
async focusWithTab() {
|
|
747
|
+
const el = await waitFor();
|
|
748
|
+
const stops = tabbables(doc().body);
|
|
749
|
+
const before = stops[stops.indexOf(el) - 1];
|
|
750
|
+
await act(() => {
|
|
751
|
+
if (before) before.focus();
|
|
752
|
+
else doc().activeElement?.blur?.();
|
|
753
|
+
});
|
|
754
|
+
const u = await getUser();
|
|
755
|
+
await act(() => u.keyboard("{Tab}"));
|
|
756
|
+
},
|
|
701
757
|
async press(key, keyOptions) {
|
|
702
758
|
const el = await waitFor();
|
|
703
759
|
if (doc().activeElement !== el) await act(() => el.focus());
|
|
@@ -720,11 +776,11 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
720
776
|
commit
|
|
721
777
|
}));
|
|
722
778
|
},
|
|
723
|
-
async pressAtPosition() {
|
|
779
|
+
async pressAtPosition(at) {
|
|
724
780
|
const el = await waitFor();
|
|
725
781
|
const rect = el.getBoundingClientRect();
|
|
726
|
-
const x = rect.left + rect.width / 2;
|
|
727
|
-
const y = rect.top + rect.height / 2;
|
|
782
|
+
const x = at?.corner ? rect.left + 2 : rect.left + rect.width / 2;
|
|
783
|
+
const y = at?.corner ? rect.top + 2 : rect.top + rect.height / 2;
|
|
728
784
|
const hit = (rect.width > 0 ? doc().elementFromPoint(x, y) : null) ?? el;
|
|
729
785
|
const u = await getUser();
|
|
730
786
|
if (u.pointer) await act(() => u.pointer?.([{
|
|
@@ -737,6 +793,260 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
737
793
|
}]));
|
|
738
794
|
else await act(() => u.click(hit));
|
|
739
795
|
},
|
|
796
|
+
async longPress(hold) {
|
|
797
|
+
const el = await waitFor();
|
|
798
|
+
const rect = el.getBoundingClientRect();
|
|
799
|
+
const clientX = rect.left + rect.width * (hold?.at?.x ?? .5);
|
|
800
|
+
const clientY = rect.top + rect.height * (hold?.at?.y ?? .5);
|
|
801
|
+
const hit = (rect.width > 0 ? doc().elementFromPoint(clientX, clientY) : null) ?? el;
|
|
802
|
+
const init = {
|
|
803
|
+
bubbles: true,
|
|
804
|
+
cancelable: true,
|
|
805
|
+
composed: true,
|
|
806
|
+
clientX,
|
|
807
|
+
clientY,
|
|
808
|
+
pointerId: 7,
|
|
809
|
+
pointerType: hold?.pointerType ?? "touch",
|
|
810
|
+
isPrimary: true,
|
|
811
|
+
pressure: .5,
|
|
812
|
+
width: 20,
|
|
813
|
+
height: 20,
|
|
814
|
+
detail: 1
|
|
815
|
+
};
|
|
816
|
+
await act(async () => {
|
|
817
|
+
hit.dispatchEvent(new PointerEvent("pointerdown", {
|
|
818
|
+
...init,
|
|
819
|
+
buttons: 1
|
|
820
|
+
}));
|
|
821
|
+
});
|
|
822
|
+
const ms = hold?.ms ?? 520;
|
|
823
|
+
const advance = options.advanceClock ?? options.advanceTimers;
|
|
824
|
+
if (advance) await act(() => advance(ms));
|
|
825
|
+
else await act(() => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
826
|
+
await act(async () => {
|
|
827
|
+
hit.dispatchEvent(new PointerEvent("pointerup", {
|
|
828
|
+
...init,
|
|
829
|
+
buttons: 0
|
|
830
|
+
}));
|
|
831
|
+
});
|
|
832
|
+
},
|
|
833
|
+
async drag(vector, dragOptions) {
|
|
834
|
+
const el = await waitFor();
|
|
835
|
+
const rect = el.getBoundingClientRect();
|
|
836
|
+
const x0 = rect.left + rect.width / 2;
|
|
837
|
+
const y0 = rect.top + rect.height / 2;
|
|
838
|
+
const hit = (rect.width > 0 ? doc().elementFromPoint(x0, y0) : null) ?? el;
|
|
839
|
+
const type = dragOptions?.pointerType ?? "mouse";
|
|
840
|
+
const steps = Math.max(1, dragOptions?.steps ?? 10);
|
|
841
|
+
const stepMs = (dragOptions?.durationMs ?? 300) / steps;
|
|
842
|
+
const advance = options.advanceClock ?? options.advanceTimers;
|
|
843
|
+
const wait = async () => {
|
|
844
|
+
if (advance) await act(() => advance(stepMs));
|
|
845
|
+
else await act(() => new Promise((resolve) => setTimeout(resolve, stepMs)));
|
|
846
|
+
};
|
|
847
|
+
const at = (i) => ({
|
|
848
|
+
x: x0 + vector.x * i / steps,
|
|
849
|
+
y: y0 + vector.y * i / steps
|
|
850
|
+
});
|
|
851
|
+
const fire = (type, p, extra) => act(async () => {
|
|
852
|
+
hit.dispatchEvent(dragEvent(type, p, extra, hit));
|
|
853
|
+
});
|
|
854
|
+
const press = {
|
|
855
|
+
isPrimary: true,
|
|
856
|
+
pressure: .5,
|
|
857
|
+
width: 20,
|
|
858
|
+
height: 20,
|
|
859
|
+
detail: 1
|
|
860
|
+
};
|
|
861
|
+
if (type === "touch") {
|
|
862
|
+
await fire("pointerdown", at(0), {
|
|
863
|
+
...press,
|
|
864
|
+
pointerId: 10,
|
|
865
|
+
pointerType: "touch",
|
|
866
|
+
buttons: 1
|
|
867
|
+
});
|
|
868
|
+
await fire("touchstart", at(0), { touching: true });
|
|
869
|
+
for (let i = 1; i <= steps; i++) {
|
|
870
|
+
await wait();
|
|
871
|
+
await fire("touchmove", at(i), { touching: true });
|
|
872
|
+
}
|
|
873
|
+
await fire("touchend", at(steps), { touching: false });
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
const base = {
|
|
877
|
+
...press,
|
|
878
|
+
pointerId: 9,
|
|
879
|
+
pointerType: type,
|
|
880
|
+
button: 0
|
|
881
|
+
};
|
|
882
|
+
await fire("pointerdown", at(0), {
|
|
883
|
+
...base,
|
|
884
|
+
buttons: 1
|
|
885
|
+
});
|
|
886
|
+
for (let i = 1; i <= steps; i++) {
|
|
887
|
+
await wait();
|
|
888
|
+
await fire("pointermove", at(i), {
|
|
889
|
+
...base,
|
|
890
|
+
buttons: 1
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
await fire("pointerup", at(steps), {
|
|
894
|
+
...base,
|
|
895
|
+
buttons: 0
|
|
896
|
+
});
|
|
897
|
+
},
|
|
898
|
+
async contextMenu(options) {
|
|
899
|
+
const el = await waitFor();
|
|
900
|
+
const rect = el.getBoundingClientRect();
|
|
901
|
+
const fx = options?.at?.x ?? .5;
|
|
902
|
+
const fy = options?.at?.y ?? .5;
|
|
903
|
+
const clientX = rect.left + rect.width * fx;
|
|
904
|
+
const clientY = rect.top + rect.height * fy;
|
|
905
|
+
const hit = (rect.width > 0 ? doc().elementFromPoint(clientX, clientY) : null) ?? el;
|
|
906
|
+
const init = {
|
|
907
|
+
bubbles: true,
|
|
908
|
+
cancelable: true,
|
|
909
|
+
composed: true,
|
|
910
|
+
clientX,
|
|
911
|
+
clientY
|
|
912
|
+
};
|
|
913
|
+
await act(async () => {
|
|
914
|
+
if (modality !== "virtual") {
|
|
915
|
+
const button = {
|
|
916
|
+
...init,
|
|
917
|
+
button: 2,
|
|
918
|
+
buttons: 2,
|
|
919
|
+
pointerId: 1,
|
|
920
|
+
pointerType: "mouse",
|
|
921
|
+
pressure: .5,
|
|
922
|
+
detail: 1
|
|
923
|
+
};
|
|
924
|
+
hit.dispatchEvent(new PointerEvent("pointerdown", button));
|
|
925
|
+
const down = new MouseEvent("mousedown", button);
|
|
926
|
+
hit.dispatchEvent(down);
|
|
927
|
+
if (!down.defaultPrevented) hit.closest("button, a[href], input, select, textarea, [tabindex]")?.focus();
|
|
928
|
+
hit.dispatchEvent(new PointerEvent("pointerup", {
|
|
929
|
+
...button,
|
|
930
|
+
buttons: 0
|
|
931
|
+
}));
|
|
932
|
+
hit.dispatchEvent(new MouseEvent("mouseup", {
|
|
933
|
+
...button,
|
|
934
|
+
buttons: 0
|
|
935
|
+
}));
|
|
936
|
+
}
|
|
937
|
+
hit.dispatchEvent(new PointerEvent("contextmenu", {
|
|
938
|
+
...init,
|
|
939
|
+
button: 2,
|
|
940
|
+
pointerType: "mouse"
|
|
941
|
+
}));
|
|
942
|
+
});
|
|
943
|
+
},
|
|
944
|
+
box: async () => {
|
|
945
|
+
const r = (await now()).getBoundingClientRect();
|
|
946
|
+
return r.width === 0 && r.height === 0 ? null : {
|
|
947
|
+
x: r.x,
|
|
948
|
+
y: r.y,
|
|
949
|
+
width: r.width,
|
|
950
|
+
height: r.height
|
|
951
|
+
};
|
|
952
|
+
},
|
|
953
|
+
async pointer(phase, pointerOptions) {
|
|
954
|
+
const el = await waitFor();
|
|
955
|
+
const r = el.getBoundingClientRect();
|
|
956
|
+
if (r.width === 0 && r.height === 0) throw new Error(`${label}: pointer("${phase}") needs layout, which this environment does not have`);
|
|
957
|
+
const clientX = r.left + pointerOptions.at.x * r.width;
|
|
958
|
+
const clientY = r.top + pointerOptions.at.y * r.height;
|
|
959
|
+
const pointerType = pointerOptions.pointerType ?? "mouse";
|
|
960
|
+
const target = (phase === "down" ? doc().elementFromPoint(clientX, clientY) : null) ?? el;
|
|
961
|
+
const pressing = phase === "down" || phase === "move";
|
|
962
|
+
const type = {
|
|
963
|
+
down: "pointerdown",
|
|
964
|
+
move: "pointermove",
|
|
965
|
+
up: "pointerup",
|
|
966
|
+
cancel: "pointercancel"
|
|
967
|
+
}[phase];
|
|
968
|
+
await act(() => {
|
|
969
|
+
const init = {
|
|
970
|
+
bubbles: true,
|
|
971
|
+
cancelable: phase !== "cancel",
|
|
972
|
+
composed: true,
|
|
973
|
+
pointerId: pointerType === "mouse" ? 1 : 2,
|
|
974
|
+
pointerType,
|
|
975
|
+
isPrimary: true,
|
|
976
|
+
clientX,
|
|
977
|
+
clientY,
|
|
978
|
+
button: phase === "move" ? -1 : 0,
|
|
979
|
+
buttons: pressing ? 1 : 0,
|
|
980
|
+
pressure: pressing ? .5 : 0
|
|
981
|
+
};
|
|
982
|
+
const event = new PointerEvent(type, init);
|
|
983
|
+
target.dispatchEvent(event);
|
|
984
|
+
if (pointerType === "mouse" && phase !== "cancel" && !event.defaultPrevented) {
|
|
985
|
+
const mouse = {
|
|
986
|
+
down: "mousedown",
|
|
987
|
+
move: "mousemove",
|
|
988
|
+
up: "mouseup"
|
|
989
|
+
}[phase];
|
|
990
|
+
target.dispatchEvent(new MouseEvent(mouse, {
|
|
991
|
+
...init,
|
|
992
|
+
detail: phase === "move" ? 0 : 1
|
|
993
|
+
}));
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
},
|
|
997
|
+
async fill(value) {
|
|
998
|
+
const el = await waitFor();
|
|
999
|
+
await act(() => {
|
|
1000
|
+
const input = el;
|
|
1001
|
+
const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), "value")?.set;
|
|
1002
|
+
if (setter) setter.call(input, value);
|
|
1003
|
+
else input.value = value;
|
|
1004
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
1005
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
1006
|
+
});
|
|
1007
|
+
},
|
|
1008
|
+
async paste(text) {
|
|
1009
|
+
const el = await waitFor();
|
|
1010
|
+
await act(() => {
|
|
1011
|
+
const input = el;
|
|
1012
|
+
const start = input.selectionStart ?? input.value.length;
|
|
1013
|
+
const end = input.selectionEnd ?? start;
|
|
1014
|
+
let paste;
|
|
1015
|
+
if (typeof DataTransfer === "function" && typeof ClipboardEvent === "function") {
|
|
1016
|
+
const clipboardData = new DataTransfer();
|
|
1017
|
+
clipboardData.setData("text/plain", text);
|
|
1018
|
+
paste = new ClipboardEvent("paste", {
|
|
1019
|
+
clipboardData,
|
|
1020
|
+
bubbles: true,
|
|
1021
|
+
cancelable: true
|
|
1022
|
+
});
|
|
1023
|
+
if (!paste.clipboardData?.getData("text/plain")) Object.defineProperty(paste, "clipboardData", { value: clipboardData });
|
|
1024
|
+
} else {
|
|
1025
|
+
paste = new Event("paste", {
|
|
1026
|
+
bubbles: true,
|
|
1027
|
+
cancelable: true
|
|
1028
|
+
});
|
|
1029
|
+
Object.defineProperty(paste, "clipboardData", { value: { getData: (type) => /^text(\/plain)?$/.test(type) ? text : "" } });
|
|
1030
|
+
}
|
|
1031
|
+
if (!input.dispatchEvent(paste)) return;
|
|
1032
|
+
const init = {
|
|
1033
|
+
inputType: "insertFromPaste",
|
|
1034
|
+
data: text,
|
|
1035
|
+
bubbles: true
|
|
1036
|
+
};
|
|
1037
|
+
const before = new InputEvent("beforeinput", {
|
|
1038
|
+
...init,
|
|
1039
|
+
cancelable: true
|
|
1040
|
+
});
|
|
1041
|
+
if (!input.dispatchEvent(before)) return;
|
|
1042
|
+
const next = input.value.slice(0, start) + text + input.value.slice(end);
|
|
1043
|
+
const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), "value")?.set;
|
|
1044
|
+
if (setter) setter.call(input, next);
|
|
1045
|
+
else input.value = next;
|
|
1046
|
+
input.setSelectionRange(start + text.length, start + text.length);
|
|
1047
|
+
input.dispatchEvent(new InputEvent("input", init));
|
|
1048
|
+
});
|
|
1049
|
+
},
|
|
740
1050
|
waitForDetach: async () => {
|
|
741
1051
|
await until(async () => (await resolve()).length, (n) => n === 0);
|
|
742
1052
|
},
|
|
@@ -787,7 +1097,8 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
787
1097
|
};
|
|
788
1098
|
const partEls = async (name, by) => {
|
|
789
1099
|
const id = await instance();
|
|
790
|
-
const
|
|
1100
|
+
const part = partName?.(name) ?? name;
|
|
1101
|
+
const sel = `[data-scope="${CSS.escape(scope)}"][data-part="${CSS.escape(part)}"][data-instance="${CSS.escape(id)}"]`;
|
|
791
1102
|
const parts = Array.from(doc().querySelectorAll(sel));
|
|
792
1103
|
if (!by) return parts;
|
|
793
1104
|
const matching = new Set(await queryBy(by, doc()));
|
|
@@ -811,24 +1122,33 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
811
1122
|
const u = await getUser();
|
|
812
1123
|
const body = doc().body;
|
|
813
1124
|
if (!u.pointer) return act(() => u.click(body));
|
|
814
|
-
const coords = nextCoords();
|
|
815
1125
|
await act(() => u.pointer?.([{
|
|
816
1126
|
keys: "[MouseLeft]",
|
|
817
1127
|
target: body,
|
|
818
|
-
coords
|
|
1128
|
+
coords: outsideCoords()
|
|
819
1129
|
}]));
|
|
820
1130
|
},
|
|
1131
|
+
async pointerAway() {
|
|
1132
|
+
const u = await getUser();
|
|
1133
|
+
const body = doc().body;
|
|
1134
|
+
if (!u.pointer) return act(() => u.hover(body));
|
|
1135
|
+
await act(() => u.pointer?.({
|
|
1136
|
+
target: body,
|
|
1137
|
+
coords: outsideCoords()
|
|
1138
|
+
}));
|
|
1139
|
+
},
|
|
821
1140
|
until,
|
|
822
1141
|
advance: async (ms) => {
|
|
823
|
-
|
|
1142
|
+
const advance = options.advanceClock ?? options.advanceTimers;
|
|
1143
|
+
if (advance) await act(() => advance(ms));
|
|
824
1144
|
else await act(() => new Promise((resolve) => setTimeout(resolve, Math.max(ms, 16))));
|
|
825
1145
|
},
|
|
826
1146
|
instance,
|
|
827
1147
|
anchorCount: async () => (await anchorEls()).length,
|
|
828
|
-
collect: async () => collectDom({
|
|
1148
|
+
collect: async () => renamedSnapshot(collectDom({
|
|
829
1149
|
scope,
|
|
830
1150
|
instance: await instance()
|
|
831
|
-
}),
|
|
1151
|
+
}), anatomyName),
|
|
832
1152
|
collectDocument: async () => collectDom({
|
|
833
1153
|
scope,
|
|
834
1154
|
instance: "\0unmounted"
|
|
@@ -838,6 +1158,13 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
838
1158
|
return [...installAnnouncementLog()];
|
|
839
1159
|
},
|
|
840
1160
|
takeErrors: async () => errors().splice(0),
|
|
1161
|
+
holdAnimations: async () => {
|
|
1162
|
+
const running = doc().getAnimations?.().filter((a) => a.playState === "running") ?? [];
|
|
1163
|
+
for (const a of running) a.pause();
|
|
1164
|
+
return async () => {
|
|
1165
|
+
for (const a of running) if (a.playState === "paused") a.play();
|
|
1166
|
+
};
|
|
1167
|
+
},
|
|
841
1168
|
selectedText: async () => doc().getSelection()?.toString() ?? "",
|
|
842
1169
|
markNavigations: async () => {
|
|
843
1170
|
navigationsFrom = navigationLog().length;
|
|
@@ -850,5 +1177,40 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
|
|
|
850
1177
|
}
|
|
851
1178
|
};
|
|
852
1179
|
}
|
|
1180
|
+
/**
|
|
1181
|
+
* A drag's event: a PointerEvent, or a touch event carrying one touch point (`touching`:
|
|
1182
|
+
* in `touches`; a touchend has none). Touch points are plain objects with the fields a
|
|
1183
|
+
* gesture reads, so it works where `Touch` cannot be constructed (jsdom).
|
|
1184
|
+
*/
|
|
1185
|
+
function dragEvent(type, p, extra, target) {
|
|
1186
|
+
if (!type.startsWith("touch")) return new PointerEvent(type, {
|
|
1187
|
+
bubbles: true,
|
|
1188
|
+
cancelable: true,
|
|
1189
|
+
composed: true,
|
|
1190
|
+
clientX: p.x,
|
|
1191
|
+
clientY: p.y,
|
|
1192
|
+
...extra
|
|
1193
|
+
});
|
|
1194
|
+
const e = new Event(type, {
|
|
1195
|
+
bubbles: true,
|
|
1196
|
+
cancelable: true,
|
|
1197
|
+
composed: true
|
|
1198
|
+
});
|
|
1199
|
+
const point = {
|
|
1200
|
+
identifier: 1,
|
|
1201
|
+
target,
|
|
1202
|
+
clientX: p.x,
|
|
1203
|
+
clientY: p.y,
|
|
1204
|
+
pageX: p.x,
|
|
1205
|
+
pageY: p.y
|
|
1206
|
+
};
|
|
1207
|
+
const touches = extra.touching ? [point] : [];
|
|
1208
|
+
Object.defineProperties(e, {
|
|
1209
|
+
touches: { value: touches },
|
|
1210
|
+
targetTouches: { value: touches },
|
|
1211
|
+
changedTouches: { value: [point] }
|
|
1212
|
+
});
|
|
1213
|
+
return e;
|
|
1214
|
+
}
|
|
853
1215
|
//#endregion
|
|
854
1216
|
export { navigationLog as a, interceptNativeNavigation as i, installErrorLog as n, installAnnouncementLog as o, fakeRouter as r, recordingAnnouncer as s, domEnv as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as EnvFactory } from "./adapter-
|
|
1
|
+
import { r as EnvFactory } from "./adapter-B05M46SW.mjs";
|
|
2
2
|
//#region src/adapters/dom.d.ts
|
|
3
3
|
/** The overlap of user-event's API and Vitest browser mode's `userEvent`. */
|
|
4
4
|
interface UserLike {
|
|
@@ -17,9 +17,18 @@ interface DomAdapterOptions {
|
|
|
17
17
|
readonly root?: ParentNode;
|
|
18
18
|
/** user-event by default; pass `userEvent` from "vitest/browser" for real input. */
|
|
19
19
|
readonly user?: UserLike;
|
|
20
|
-
/** Fake-timer advance, e.g. `vi.advanceTimersByTime
|
|
20
|
+
/** Fake-timer advance, e.g. `vi.advanceTimersByTime` (polling advances it too). */
|
|
21
21
|
readonly advanceTimers?: (ms: number) => unknown;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* A virtual clock's advance (`virtualClock().advance`) for the explicit waits only
|
|
24
|
+
* (`advance`, `longPress`): polling stays on real time, so frames keep running.
|
|
25
|
+
*/
|
|
26
|
+
readonly advanceClock?: (ms: number) => unknown;
|
|
27
|
+
/**
|
|
28
|
+
* `until` timeout in ms. Default 1000 in jsdom (Testing Library's waitFor default) and
|
|
29
|
+
* 3000 in a real browser, where a CPU-starved page can deliver its first animation frame
|
|
30
|
+
* after more than a second (an overlay's initial focus waits for one).
|
|
31
|
+
*/
|
|
23
32
|
readonly timeout?: number;
|
|
24
33
|
}
|
|
25
34
|
/** The Testing Library adapter. */
|
package/dist/dom.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as UserLike, r as domEnv, t as DomAdapterOptions } from "./dom-
|
|
1
|
+
import { n as UserLike, r as domEnv, t as DomAdapterOptions } from "./dom-Ur_VPlTe.mjs";
|
|
2
2
|
export { type DomAdapterOptions, type UserLike, domEnv };
|
package/dist/dom.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as domEnv } from "./dom-
|
|
1
|
+
export { t as domEnv } from "./dom-Bnnr_fg-.mjs";
|