@rind-ui/testing 0.1.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.
@@ -1,5 +1,5 @@
1
- import { o as poll, r as describeBy, t as composeInPage } from "./compose-C7RIqRoi.mjs";
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",
@@ -412,6 +422,49 @@ const nextCoords = (el) => {
412
422
  pageY: y + window.scrollY
413
423
  };
414
424
  };
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
+ /**
454
+ * Resolves once no finite transition or animation is running in the document (or after `max`
455
+ * ms). A sibling panel opening shifts the target's box for a while, and a press aimed at
456
+ * coordinates read before the shift releases outside it (the press is then not a press).
457
+ * Without running animations (every jsdom test, most browser ones) it returns at once; fake
458
+ * timers have no frames to wait on.
459
+ */
460
+ const settled = async (el, fake, max = 1e3) => {
461
+ const doc = el.ownerDocument;
462
+ const view = doc.defaultView;
463
+ if (fake || !view?.requestAnimationFrame || !doc.getAnimations) return;
464
+ const running = () => doc.getAnimations().some((a) => a.playState === "running" && a.effect?.getComputedTiming().iterations !== Number.POSITIVE_INFINITY);
465
+ const end = Date.now() + max;
466
+ while (running() && Date.now() < end) await new Promise((done) => view.requestAnimationFrame(() => done()));
467
+ };
415
468
  const KEY_NAMES = {
416
469
  Enter: "{Enter}",
417
470
  Escape: "{Escape}",
@@ -427,6 +480,7 @@ const KEY_NAMES = {
427
480
  ArrowRight: "{ArrowRight}",
428
481
  Backspace: "{Backspace}",
429
482
  Delete: "{Delete}",
483
+ F6: "{F6}",
430
484
  F10: "{F10}",
431
485
  ContextMenu: "{ContextMenu}",
432
486
  A: "a"
@@ -457,8 +511,10 @@ function installErrorLog(win = globalThis.window ?? null) {
457
511
  const entries = [];
458
512
  const { console } = win;
459
513
  const original = console.error.bind(console);
514
+ const realBrowser = !(win.navigator?.userAgent ?? "").includes("jsdom");
460
515
  console.error = (...args) => {
461
- entries.push(args.map(String).join(" "));
516
+ const message = args.map(String).join(" ");
517
+ if (!(realBrowser && message.includes("not wrapped in act("))) entries.push(message);
462
518
  original(...args);
463
519
  };
464
520
  win.addEventListener("error", (e) => entries.push(String(e.error ?? e.message)));
@@ -467,9 +523,10 @@ function installErrorLog(win = globalThis.window ?? null) {
467
523
  }
468
524
  return log;
469
525
  }
526
+ const isJsdom = () => (globalThis.navigator?.userAgent ?? "").includes("jsdom");
470
527
  /** The Testing Library adapter. */
471
528
  function domEnv(options = {}) {
472
- const timeout = options.timeout ?? 1e3;
529
+ const timeout = options.timeout ?? (isJsdom() ? 1e3 : 3e3);
473
530
  const doc = options.root?.ownerDocument ?? globalThis.document;
474
531
  const errors = installErrorLog(doc?.defaultView ?? null);
475
532
  if (doc?.defaultView) interceptNativeNavigation(doc.defaultView);
@@ -490,7 +547,7 @@ function domEnv(options = {}) {
490
547
  const ACT_ENV = "IS_REACT_ACT_ENVIRONMENT";
491
548
  /** The `key` value a native event carries for a contract key. */
492
549
  const NATIVE_KEY = { Space: " " };
493
- function createDomEnv({ scope, anchor, modality, platform }, options, getUser, errors) {
550
+ function createDomEnv({ scope, anchor, modality, platform, partName, anatomyName }, options, getUser, errors) {
494
551
  const doc = () => options.root?.ownerDocument ?? document;
495
552
  const apple = platform?.apple === true;
496
553
  /** The navigation log's length when the current action began. */
@@ -541,6 +598,12 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
541
598
  const name = by.name;
542
599
  return queryAllByRole(within, by.role, { ...name === void 0 ? {} : { name: typeof name === "string" ? (n) => normalize(n) === name : name } });
543
600
  }
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)}"]`));
544
607
  const { text } = by;
545
608
  const matches = (el) => {
546
609
  const own = normalize(el.textContent);
@@ -632,6 +695,7 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
632
695
  const press = async (el, touch) => {
633
696
  const u = await getUser();
634
697
  if (!u.pointer) return act(() => u.click(el));
698
+ await settled(el, options.advanceTimers !== void 0);
635
699
  const coords = nextCoords(el);
636
700
  const steps = touch ? [{
637
701
  keys: "[TouchA]",
@@ -679,6 +743,17 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
679
743
  const el = await waitFor();
680
744
  await act(() => el.focus());
681
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
+ },
682
757
  async press(key, keyOptions) {
683
758
  const el = await waitFor();
684
759
  if (doc().activeElement !== el) await act(() => el.focus());
@@ -701,11 +776,11 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
701
776
  commit
702
777
  }));
703
778
  },
704
- async pressAtPosition() {
779
+ async pressAtPosition(at) {
705
780
  const el = await waitFor();
706
781
  const rect = el.getBoundingClientRect();
707
- const x = rect.left + rect.width / 2;
708
- 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;
709
784
  const hit = (rect.width > 0 ? doc().elementFromPoint(x, y) : null) ?? el;
710
785
  const u = await getUser();
711
786
  if (u.pointer) await act(() => u.pointer?.([{
@@ -718,6 +793,260 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
718
793
  }]));
719
794
  else await act(() => u.click(hit));
720
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
+ },
721
1050
  waitForDetach: async () => {
722
1051
  await until(async () => (await resolve()).length, (n) => n === 0);
723
1052
  },
@@ -725,6 +1054,7 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
725
1054
  attr: async (name) => (await now()).getAttribute(name),
726
1055
  tagName: async () => (await now()).tagName.toLowerCase(),
727
1056
  scoped: (scope, partName) => handle(`${scope}.${partName} in ${label}`, async () => Array.from((await now()).querySelectorAll(`[data-scope="${scope}"][data-part="${partName}"]`))),
1057
+ withAttr: (name, value) => handle(`[${name}] in ${label}`, async () => Array.from((await now()).querySelectorAll(value === void 0 ? `[${name}]` : `[${name}="${CSS.escape(value)}"]`))),
728
1058
  text: async () => normalize((await now()).textContent),
729
1059
  value: async () => (await now()).value ?? "",
730
1060
  checked: async () => (await now()).checked === true,
@@ -767,7 +1097,8 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
767
1097
  };
768
1098
  const partEls = async (name, by) => {
769
1099
  const id = await instance();
770
- const sel = `[data-scope="${CSS.escape(scope)}"][data-part="${CSS.escape(name)}"][data-instance="${CSS.escape(id)}"]`;
1100
+ const part = partName?.(name) ?? name;
1101
+ const sel = `[data-scope="${CSS.escape(scope)}"][data-part="${CSS.escape(part)}"][data-instance="${CSS.escape(id)}"]`;
771
1102
  const parts = Array.from(doc().querySelectorAll(sel));
772
1103
  if (!by) return parts;
773
1104
  const matching = new Set(await queryBy(by, doc()));
@@ -791,24 +1122,33 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
791
1122
  const u = await getUser();
792
1123
  const body = doc().body;
793
1124
  if (!u.pointer) return act(() => u.click(body));
794
- const coords = nextCoords();
795
1125
  await act(() => u.pointer?.([{
796
1126
  keys: "[MouseLeft]",
797
1127
  target: body,
798
- coords
1128
+ coords: outsideCoords()
799
1129
  }]));
800
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
+ },
801
1140
  until,
802
1141
  advance: async (ms) => {
803
- if (options.advanceTimers) await act(() => options.advanceTimers?.(ms));
1142
+ const advance = options.advanceClock ?? options.advanceTimers;
1143
+ if (advance) await act(() => advance(ms));
804
1144
  else await act(() => new Promise((resolve) => setTimeout(resolve, Math.max(ms, 16))));
805
1145
  },
806
1146
  instance,
807
1147
  anchorCount: async () => (await anchorEls()).length,
808
- collect: async () => collectDom({
1148
+ collect: async () => renamedSnapshot(collectDom({
809
1149
  scope,
810
1150
  instance: await instance()
811
- }),
1151
+ }), anatomyName),
812
1152
  collectDocument: async () => collectDom({
813
1153
  scope,
814
1154
  instance: "\0unmounted"
@@ -818,6 +1158,13 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
818
1158
  return [...installAnnouncementLog()];
819
1159
  },
820
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
+ },
821
1168
  selectedText: async () => doc().getSelection()?.toString() ?? "",
822
1169
  markNavigations: async () => {
823
1170
  navigationsFrom = navigationLog().length;
@@ -830,5 +1177,40 @@ function createDomEnv({ scope, anchor, modality, platform }, options, getUser, e
830
1177
  }
831
1178
  };
832
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
+ }
833
1215
  //#endregion
834
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-UPhu17S6.mjs";
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
- /** `until` timeout in ms (default 1000, Testing Library's waitFor default). */
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-BxnIjEBk.mjs";
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-Ds2Cv9wy.mjs";
1
+ export { t as domEnv } from "./dom-Bnnr_fg-.mjs";