@dloizides/game-e2e 1.6.0 → 1.7.2

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/index.mjs CHANGED
@@ -494,11 +494,18 @@ function installStub([buttons, axes]) {
494
494
  Object.defineProperty(navigator, "getGamepads", { configurable: true, value: sample });
495
495
  window.addEventListener("load", () => window.dispatchEvent(Object.assign(new Event("gamepadconnected"), { gamepad: pad })));
496
496
  }
497
- async function pressInPage([button, maxFrames, idleFrames]) {
497
+ async function pressInPage([button, maxFrames, idleFrames, focus]) {
498
498
  const { __navPad: pad, __navPress: latch } = window;
499
+ const focused = () => {
500
+ const v = focus === null ? null : document.activeElement?.getAttribute(focus.attr) ?? null;
501
+ return v === null ? null : Number(v);
502
+ };
503
+ if (focus !== null) {
504
+ document.querySelector(`[${focus.attr}="${focus.id}"]`)?.focus();
505
+ }
499
506
  const target = pad.buttons[button];
500
507
  if (target === void 0) {
501
- return;
508
+ return focused();
502
509
  }
503
510
  target.pressed = true;
504
511
  target.value = 1;
@@ -520,17 +527,63 @@ async function pressInPage([button, maxFrames, idleFrames]) {
520
527
  };
521
528
  requestAnimationFrame(() => step(maxFrames));
522
529
  });
530
+ return focused();
523
531
  }
524
532
  async function stubGamepad(page) {
525
533
  await page.addInitScript(installStub, [STANDARD_BUTTON_COUNT, AXIS_COUNT]);
526
534
  return {
527
- press: (button) => page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES, IDLE_RELEASE_FRAMES]),
535
+ press: async (button) => {
536
+ await page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES, IDLE_RELEASE_FRAMES, null]);
537
+ },
538
+ move: (button, focus) => page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES, IDLE_RELEASE_FRAMES, focus]),
528
539
  hold: (axis, value) => page.evaluate(([a, v]) => {
529
540
  window.__navPad.axes[a] = v;
530
541
  }, [axis, value])
531
542
  };
532
543
  }
533
544
 
545
+ // src/menu-walk-page.ts
546
+ var WALK_ATTR = "data-walk-id";
547
+ function scanScreen(a) {
548
+ const shown = (el) => el.getClientRects().length > 0 && el.closest('[hidden], [inert], [aria-hidden="true"]') === null && getComputedStyle(el).visibility !== "hidden";
549
+ const dialogs = Array.from(document.querySelectorAll(a.dialogSel)).filter(shown);
550
+ const modal = dialogs.filter((d) => d.getAttribute("aria-modal") === "true");
551
+ const root = (modal.length > 0 ? modal : dialogs).pop() ?? document.body;
552
+ document.querySelectorAll(`[${a.attr}], [${a.rootAttr}]`).forEach((el) => {
553
+ el.removeAttribute(a.attr);
554
+ el.removeAttribute(a.rootAttr);
555
+ });
556
+ root.setAttribute(a.rootAttr, "");
557
+ const list = Array.from(root.querySelectorAll(`${a.focusSel}, [onclick]`)).filter((el) => shown(el) && el.disabled !== true && !a.exempt.some((s) => el.matches(s)));
558
+ list.forEach((el, i) => el.setAttribute(a.attr, String(i)));
559
+ const nonText = ["range", "checkbox", "radio", "button", "submit", "reset", "color", "file", "image"];
560
+ const isText = (el) => el.tagName === "TEXTAREA" || el instanceof HTMLInputElement && !nonText.includes(el.type);
561
+ const isSlider = (el) => el instanceof HTMLInputElement && el.type === "range" || el.getAttribute("role") === "slider";
562
+ const active2 = document.activeElement;
563
+ return {
564
+ identities: list.map((el) => ({ tag: el.tagName, id: el.id, className: el.getAttribute("class") ?? "", text: el.textContent ?? "" })),
565
+ isDialog: root !== document.body,
566
+ focusedInRoot: active2 instanceof HTMLElement && active2 !== root && root.contains(active2),
567
+ sliders: list.flatMap((el, i) => isSlider(el) ? [i] : []),
568
+ textFields: list.flatMap((el, i) => isText(el) ? [i] : [])
569
+ };
570
+ }
571
+ function activeWalkId(attr) {
572
+ const v = document.activeElement?.getAttribute(attr) ?? null;
573
+ return v === null ? null : Number(v);
574
+ }
575
+ function focusWalkId([attr, id]) {
576
+ document.querySelector(`[${attr}="${id}"]`)?.focus();
577
+ }
578
+ function controlValue([attr, id]) {
579
+ const el = document.querySelector(`[${attr}="${id}"]`);
580
+ return el instanceof HTMLInputElement ? el.value : el?.getAttribute("aria-valuenow") ?? "";
581
+ }
582
+ function rootOpen(rootAttr) {
583
+ const r = document.querySelector(`[${rootAttr}]`);
584
+ return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
585
+ }
586
+
534
587
  // src/menu-walk-report.ts
535
588
  var WALK_INPUTS = { keys: "keys", pad: "pad" };
536
589
  var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
@@ -550,9 +603,14 @@ var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowR
550
603
  var PAD_BUTTONS = { up: STANDARD_BUTTON.dpadUp, down: STANDARD_BUTTON.dpadDown, left: STANDARD_BUTTON.dpadLeft, right: STANDARD_BUTTON.dpadRight };
551
604
  function driverFor(page, via, pad) {
552
605
  if (via === WALK_INPUTS.pad && pad !== null) {
553
- return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(STANDARD_BUTTON.east), activate: () => pad.press(STANDARD_BUTTON.south) };
606
+ return { dir: (d) => pad.press(PAD_BUTTONS[d]), move: (from, d) => pad.move(PAD_BUTTONS[d], { attr: WALK_ATTR, id: from }), back: () => pad.press(STANDARD_BUTTON.east), activate: () => pad.press(STANDARD_BUTTON.south) };
554
607
  }
555
- return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape"), activate: () => page.keyboard.press("Enter") };
608
+ const move = async (from, d) => {
609
+ await page.evaluate(focusWalkId, [WALK_ATTR, from]);
610
+ await page.keyboard.press(KEYS[d]);
611
+ return page.evaluate(activeWalkId, WALK_ATTR);
612
+ };
613
+ return { dir: (d) => page.keyboard.press(KEYS[d]), move, back: () => page.keyboard.press("Escape"), activate: () => page.keyboard.press("Enter") };
556
614
  }
557
615
 
558
616
  // src/menu-walk-listeners.ts
@@ -593,49 +651,7 @@ async function pointerOnlyControls(page, cdp, args, start) {
593
651
  return { identities, notes: cdp === null ? [NO_CDP_NOTE] : [] };
594
652
  }
595
653
 
596
- // src/menu-walk-page.ts
597
- function scanScreen(a) {
598
- const shown = (el) => el.getClientRects().length > 0 && el.closest('[hidden], [inert], [aria-hidden="true"]') === null && getComputedStyle(el).visibility !== "hidden";
599
- const dialogs = Array.from(document.querySelectorAll(a.dialogSel)).filter(shown);
600
- const modal = dialogs.filter((d) => d.getAttribute("aria-modal") === "true");
601
- const root = (modal.length > 0 ? modal : dialogs).pop() ?? document.body;
602
- document.querySelectorAll(`[${a.attr}], [${a.rootAttr}]`).forEach((el) => {
603
- el.removeAttribute(a.attr);
604
- el.removeAttribute(a.rootAttr);
605
- });
606
- root.setAttribute(a.rootAttr, "");
607
- const list = Array.from(root.querySelectorAll(`${a.focusSel}, [onclick]`)).filter((el) => shown(el) && el.disabled !== true && !a.exempt.some((s) => el.matches(s)));
608
- list.forEach((el, i) => el.setAttribute(a.attr, String(i)));
609
- const nonText = ["range", "checkbox", "radio", "button", "submit", "reset", "color", "file", "image"];
610
- const isText = (el) => el.tagName === "TEXTAREA" || el instanceof HTMLInputElement && !nonText.includes(el.type);
611
- const isSlider = (el) => el instanceof HTMLInputElement && el.type === "range" || el.getAttribute("role") === "slider";
612
- const active2 = document.activeElement;
613
- return {
614
- identities: list.map((el) => ({ tag: el.tagName, id: el.id, className: el.getAttribute("class") ?? "", text: el.textContent ?? "" })),
615
- isDialog: root !== document.body,
616
- focusedInRoot: active2 instanceof HTMLElement && active2 !== root && root.contains(active2),
617
- sliders: list.flatMap((el, i) => isSlider(el) ? [i] : []),
618
- textFields: list.flatMap((el, i) => isText(el) ? [i] : [])
619
- };
620
- }
621
- function activeWalkId(attr) {
622
- const v = document.activeElement?.getAttribute(attr) ?? null;
623
- return v === null ? null : Number(v);
624
- }
625
- function focusWalkId([attr, id]) {
626
- document.querySelector(`[${attr}="${id}"]`)?.focus();
627
- }
628
- function controlValue([attr, id]) {
629
- const el = document.querySelector(`[${attr}="${id}"]`);
630
- return el instanceof HTMLInputElement ? el.value : el?.getAttribute("aria-valuenow") ?? "";
631
- }
632
- function rootOpen(rootAttr) {
633
- const r = document.querySelector(`[${rootAttr}]`);
634
- return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
635
- }
636
-
637
654
  // src/menu-walk.ts
638
- var WALK_ATTR = "data-walk-id";
639
655
  var ROOT_ATTR = "data-walk-root";
640
656
  var PROBE_ATTR = "data-walk-probe";
641
657
  var PRESSES_PER_CONTROL = 4;
@@ -654,13 +670,12 @@ async function bfs(page, driver, total) {
654
670
  reached.add(start);
655
671
  const queue = [start];
656
672
  let presses = 0;
657
- while (queue.length > 0 && presses < PRESSES_PER_CONTROL * total) {
673
+ const open = () => reached.size < total && presses < PRESSES_PER_CONTROL * total;
674
+ while (queue.length > 0 && open()) {
658
675
  const from = queue.shift();
659
- for (const d of DIRS) {
660
- await focusId(page, from);
661
- await driver.dir(d);
676
+ for (const d of DIRS.filter(open)) {
677
+ const at2 = await driver.move(from, d);
662
678
  presses += 1;
663
- const at2 = await active(page);
664
679
  if (at2 !== null && !reached.has(at2)) {
665
680
  reached.add(at2);
666
681
  queue.push(at2);
@@ -1025,10 +1040,12 @@ function bindingFindings(r, action) {
1025
1040
  return found;
1026
1041
  }
1027
1042
  function promptFinding(r) {
1028
- const comparable = r.promptText !== null && r.expectedPromptText !== null;
1029
- if (!comparable || r.promptText === r.expectedPromptText) {
1043
+ if (r.expectedPromptText === null || r.promptText === r.expectedPromptText) {
1030
1044
  return null;
1031
1045
  }
1046
+ if (r.promptText === null) {
1047
+ return { name: r.name, why: `prompt missing: the current binding is "${r.expectedPromptText}" but no visible data-gi-prompt shows it` };
1048
+ }
1032
1049
  return { name: r.name, why: `prompt shows "${String(r.promptText)}" but the current binding is "${String(r.expectedPromptText)}"` };
1033
1050
  }
1034
1051
  function actionBindingFindings(r) {