@dloizides/game-e2e 1.6.1 → 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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  All notable changes to `@dloizides/game-e2e` are documented here.
4
4
 
5
+ ## 1.7.1
6
+
7
+ D-BTV-E2E-3 "nav1 under 180 s by speeding up the walker" (tag v1.7.0 was pushed before the version bump and never published):
8
+
9
+ - `walkMenus` / `expectMenuWalkable` stop the breadth-first walk once every control is reached; the remaining presses
10
+ could not change the result, so no assertion is dropped (slider, dialog focus and back checks run as before).
11
+ - A pad walk step (focus, press, read focus) is one page round trip: new `PadDriver.move(button, { attr, id })`.
12
+ Profiled on a BeyondTheVoid title walk, pad presses were 75% of the walk time.
13
+
5
14
  ## 1.6.1
6
15
 
7
16
  GAME-INPUT-PROMPTS-1 "Every action bound, with device labels", D-GIP-9 "Widen AC-GIP-5":
package/dist/index.d.mts CHANGED
@@ -248,8 +248,14 @@ declare function walkMenus(page: Page, screens: readonly WalkScreen[], options?:
248
248
  /** NAV-1 gate: throws, listing every unreached control and problem, unless every screen walks by keys and pad. */
249
249
  declare function expectMenuWalkable(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<void>;
250
250
 
251
+ interface WalkFocus {
252
+ attr: string;
253
+ id: number;
254
+ }
251
255
  interface PadDriver {
252
256
  press(button: number): Promise<void>;
257
+ /** Focuses walk control `focus.id`, presses `button` and returns the walk id focused after it, in one page round trip. */
258
+ move(button: number, focus: WalkFocus): Promise<number | null>;
253
259
  hold(axis: number, value: number): Promise<void>;
254
260
  }
255
261
  declare const STUB_FRAMES = 1;
package/dist/index.d.ts CHANGED
@@ -248,8 +248,14 @@ declare function walkMenus(page: Page, screens: readonly WalkScreen[], options?:
248
248
  /** NAV-1 gate: throws, listing every unreached control and problem, unless every screen walks by keys and pad. */
249
249
  declare function expectMenuWalkable(page: Page, screens: readonly WalkScreen[], options?: WalkOptions): Promise<void>;
250
250
 
251
+ interface WalkFocus {
252
+ attr: string;
253
+ id: number;
254
+ }
251
255
  interface PadDriver {
252
256
  press(button: number): Promise<void>;
257
+ /** Focuses walk control `focus.id`, presses `button` and returns the walk id focused after it, in one page round trip. */
258
+ move(button: number, focus: WalkFocus): Promise<number | null>;
253
259
  hold(axis: number, value: number): Promise<void>;
254
260
  }
255
261
  declare const STUB_FRAMES = 1;
package/dist/index.js CHANGED
@@ -496,11 +496,18 @@ function installStub([buttons, axes]) {
496
496
  Object.defineProperty(navigator, "getGamepads", { configurable: true, value: sample });
497
497
  window.addEventListener("load", () => window.dispatchEvent(Object.assign(new Event("gamepadconnected"), { gamepad: pad })));
498
498
  }
499
- async function pressInPage([button, maxFrames, idleFrames]) {
499
+ async function pressInPage([button, maxFrames, idleFrames, focus]) {
500
500
  const { __navPad: pad, __navPress: latch } = window;
501
+ const focused = () => {
502
+ const v = focus === null ? null : document.activeElement?.getAttribute(focus.attr) ?? null;
503
+ return v === null ? null : Number(v);
504
+ };
505
+ if (focus !== null) {
506
+ document.querySelector(`[${focus.attr}="${focus.id}"]`)?.focus();
507
+ }
501
508
  const target = pad.buttons[button];
502
509
  if (target === void 0) {
503
- return;
510
+ return focused();
504
511
  }
505
512
  target.pressed = true;
506
513
  target.value = 1;
@@ -522,17 +529,63 @@ async function pressInPage([button, maxFrames, idleFrames]) {
522
529
  };
523
530
  requestAnimationFrame(() => step(maxFrames));
524
531
  });
532
+ return focused();
525
533
  }
526
534
  async function stubGamepad(page) {
527
535
  await page.addInitScript(installStub, [STANDARD_BUTTON_COUNT, AXIS_COUNT]);
528
536
  return {
529
- press: (button) => page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES, IDLE_RELEASE_FRAMES]),
537
+ press: async (button) => {
538
+ await page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES, IDLE_RELEASE_FRAMES, null]);
539
+ },
540
+ move: (button, focus) => page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES, IDLE_RELEASE_FRAMES, focus]),
530
541
  hold: (axis, value) => page.evaluate(([a, v]) => {
531
542
  window.__navPad.axes[a] = v;
532
543
  }, [axis, value])
533
544
  };
534
545
  }
535
546
 
547
+ // src/menu-walk-page.ts
548
+ var WALK_ATTR = "data-walk-id";
549
+ function scanScreen(a) {
550
+ const shown = (el) => el.getClientRects().length > 0 && el.closest('[hidden], [inert], [aria-hidden="true"]') === null && getComputedStyle(el).visibility !== "hidden";
551
+ const dialogs = Array.from(document.querySelectorAll(a.dialogSel)).filter(shown);
552
+ const modal = dialogs.filter((d) => d.getAttribute("aria-modal") === "true");
553
+ const root = (modal.length > 0 ? modal : dialogs).pop() ?? document.body;
554
+ document.querySelectorAll(`[${a.attr}], [${a.rootAttr}]`).forEach((el) => {
555
+ el.removeAttribute(a.attr);
556
+ el.removeAttribute(a.rootAttr);
557
+ });
558
+ root.setAttribute(a.rootAttr, "");
559
+ const list = Array.from(root.querySelectorAll(`${a.focusSel}, [onclick]`)).filter((el) => shown(el) && el.disabled !== true && !a.exempt.some((s) => el.matches(s)));
560
+ list.forEach((el, i) => el.setAttribute(a.attr, String(i)));
561
+ const nonText = ["range", "checkbox", "radio", "button", "submit", "reset", "color", "file", "image"];
562
+ const isText = (el) => el.tagName === "TEXTAREA" || el instanceof HTMLInputElement && !nonText.includes(el.type);
563
+ const isSlider = (el) => el instanceof HTMLInputElement && el.type === "range" || el.getAttribute("role") === "slider";
564
+ const active2 = document.activeElement;
565
+ return {
566
+ identities: list.map((el) => ({ tag: el.tagName, id: el.id, className: el.getAttribute("class") ?? "", text: el.textContent ?? "" })),
567
+ isDialog: root !== document.body,
568
+ focusedInRoot: active2 instanceof HTMLElement && active2 !== root && root.contains(active2),
569
+ sliders: list.flatMap((el, i) => isSlider(el) ? [i] : []),
570
+ textFields: list.flatMap((el, i) => isText(el) ? [i] : [])
571
+ };
572
+ }
573
+ function activeWalkId(attr) {
574
+ const v = document.activeElement?.getAttribute(attr) ?? null;
575
+ return v === null ? null : Number(v);
576
+ }
577
+ function focusWalkId([attr, id]) {
578
+ document.querySelector(`[${attr}="${id}"]`)?.focus();
579
+ }
580
+ function controlValue([attr, id]) {
581
+ const el = document.querySelector(`[${attr}="${id}"]`);
582
+ return el instanceof HTMLInputElement ? el.value : el?.getAttribute("aria-valuenow") ?? "";
583
+ }
584
+ function rootOpen(rootAttr) {
585
+ const r = document.querySelector(`[${rootAttr}]`);
586
+ return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
587
+ }
588
+
536
589
  // src/menu-walk-report.ts
537
590
  var WALK_INPUTS = { keys: "keys", pad: "pad" };
538
591
  var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
@@ -552,9 +605,14 @@ var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowR
552
605
  var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
553
606
  function driverFor(page, via, pad) {
554
607
  if (via === WALK_INPUTS.pad && pad !== null) {
555
- return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east), activate: () => pad.press(gameInput.STANDARD_BUTTON.south) };
608
+ return { dir: (d) => pad.press(PAD_BUTTONS[d]), move: (from, d) => pad.move(PAD_BUTTONS[d], { attr: WALK_ATTR, id: from }), back: () => pad.press(gameInput.STANDARD_BUTTON.east), activate: () => pad.press(gameInput.STANDARD_BUTTON.south) };
556
609
  }
557
- return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape"), activate: () => page.keyboard.press("Enter") };
610
+ const move = async (from, d) => {
611
+ await page.evaluate(focusWalkId, [WALK_ATTR, from]);
612
+ await page.keyboard.press(KEYS[d]);
613
+ return page.evaluate(activeWalkId, WALK_ATTR);
614
+ };
615
+ return { dir: (d) => page.keyboard.press(KEYS[d]), move, back: () => page.keyboard.press("Escape"), activate: () => page.keyboard.press("Enter") };
558
616
  }
559
617
 
560
618
  // src/menu-walk-listeners.ts
@@ -595,49 +653,7 @@ async function pointerOnlyControls(page, cdp, args, start) {
595
653
  return { identities, notes: cdp === null ? [NO_CDP_NOTE] : [] };
596
654
  }
597
655
 
598
- // src/menu-walk-page.ts
599
- function scanScreen(a) {
600
- const shown = (el) => el.getClientRects().length > 0 && el.closest('[hidden], [inert], [aria-hidden="true"]') === null && getComputedStyle(el).visibility !== "hidden";
601
- const dialogs = Array.from(document.querySelectorAll(a.dialogSel)).filter(shown);
602
- const modal = dialogs.filter((d) => d.getAttribute("aria-modal") === "true");
603
- const root = (modal.length > 0 ? modal : dialogs).pop() ?? document.body;
604
- document.querySelectorAll(`[${a.attr}], [${a.rootAttr}]`).forEach((el) => {
605
- el.removeAttribute(a.attr);
606
- el.removeAttribute(a.rootAttr);
607
- });
608
- root.setAttribute(a.rootAttr, "");
609
- const list = Array.from(root.querySelectorAll(`${a.focusSel}, [onclick]`)).filter((el) => shown(el) && el.disabled !== true && !a.exempt.some((s) => el.matches(s)));
610
- list.forEach((el, i) => el.setAttribute(a.attr, String(i)));
611
- const nonText = ["range", "checkbox", "radio", "button", "submit", "reset", "color", "file", "image"];
612
- const isText = (el) => el.tagName === "TEXTAREA" || el instanceof HTMLInputElement && !nonText.includes(el.type);
613
- const isSlider = (el) => el instanceof HTMLInputElement && el.type === "range" || el.getAttribute("role") === "slider";
614
- const active2 = document.activeElement;
615
- return {
616
- identities: list.map((el) => ({ tag: el.tagName, id: el.id, className: el.getAttribute("class") ?? "", text: el.textContent ?? "" })),
617
- isDialog: root !== document.body,
618
- focusedInRoot: active2 instanceof HTMLElement && active2 !== root && root.contains(active2),
619
- sliders: list.flatMap((el, i) => isSlider(el) ? [i] : []),
620
- textFields: list.flatMap((el, i) => isText(el) ? [i] : [])
621
- };
622
- }
623
- function activeWalkId(attr) {
624
- const v = document.activeElement?.getAttribute(attr) ?? null;
625
- return v === null ? null : Number(v);
626
- }
627
- function focusWalkId([attr, id]) {
628
- document.querySelector(`[${attr}="${id}"]`)?.focus();
629
- }
630
- function controlValue([attr, id]) {
631
- const el = document.querySelector(`[${attr}="${id}"]`);
632
- return el instanceof HTMLInputElement ? el.value : el?.getAttribute("aria-valuenow") ?? "";
633
- }
634
- function rootOpen(rootAttr) {
635
- const r = document.querySelector(`[${rootAttr}]`);
636
- return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
637
- }
638
-
639
656
  // src/menu-walk.ts
640
- var WALK_ATTR = "data-walk-id";
641
657
  var ROOT_ATTR = "data-walk-root";
642
658
  var PROBE_ATTR = "data-walk-probe";
643
659
  var PRESSES_PER_CONTROL = 4;
@@ -656,13 +672,12 @@ async function bfs(page, driver, total) {
656
672
  reached.add(start);
657
673
  const queue = [start];
658
674
  let presses = 0;
659
- while (queue.length > 0 && presses < PRESSES_PER_CONTROL * total) {
675
+ const open = () => reached.size < total && presses < PRESSES_PER_CONTROL * total;
676
+ while (queue.length > 0 && open()) {
660
677
  const from = queue.shift();
661
- for (const d of DIRS) {
662
- await focusId(page, from);
663
- await driver.dir(d);
678
+ for (const d of DIRS.filter(open)) {
679
+ const at2 = await driver.move(from, d);
664
680
  presses += 1;
665
- const at2 = await active(page);
666
681
  if (at2 !== null && !reached.has(at2)) {
667
682
  reached.add(at2);
668
683
  queue.push(at2);