@dloizides/game-e2e 1.2.1 → 1.4.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/CHANGELOG.md CHANGED
@@ -1,52 +1,72 @@
1
- # Changelog
2
-
3
- All notable changes to `@dloizides/game-e2e` are documented here.
4
-
5
- ## 1.2.1
6
-
7
- - Listener lookup is one `Runtime.evaluate` (DevTools `getEventListeners`) instead of two CDP calls per element. The
8
- per-element calls slowed the walk enough that a screen re-rendering on a late fetch (Surge `stagePreview`) went red.
9
-
10
- ## 1.2.0
11
-
12
- NAV-1 "Every game menu works with arrow keys and controller", walker gap:
13
-
14
- - The walker now finds pointer-only items whose click / pointerdown / pointerup handler is set as a property
15
- (`el.onclick = ...`) or added with `addEventListener`, not only the `[onclick]` attribute. A visible element
16
- with such a handler that is not focusable is reported `unreached`.
17
- - Listeners are read through CDP `DOMDebugger.getEventListeners` (Chromium). Without CDP (Firefox, WebKit) only
18
- the attribute and properties are checked, and each result carries a `notes` line saying so.
19
- - Delegation: an element that contains a walk control, or sits inside one, is never flagged, so a listener on a
20
- menu container does not flag the container or its children. When nested elements are both flagged, only the
21
- innermost is reported.
22
- - `WalkResult.notes` (new, printed as `note:` by `renderWalk`).
23
-
24
- ## 1.1.0
25
-
26
- NAV-1 "Every game menu works with arrow keys and controller", phase 1:
27
-
28
- - `walkMenus()` / `expectMenuWalkable()`: open each screen, walk every focusable control by arrow keys and
29
- by a stubbed gamepad (breadth-first from the focused control), report unreached controls, a dialog that
30
- opens without focus inside it, sliders that ignore Left/Right, and Escape / B that does not close a dialog.
31
- Exemptions take a selector and a printed reason.
32
- - `stubGamepad()`: a `navigator.getGamepads()` stand-in driven from the test (`PadDriver.press`).
33
- - `renderWalk()`, `walkFailed()`, `WALK_INPUTS`.
34
- - Depends on `@dloizides/game-input` ^1.5.1 for the shared focusable and dialog selectors.
35
-
36
- ## 1.0.0
37
-
38
- First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
39
- strictest behaviour of the three:
40
-
41
- - `phone()` / `desktop()` / `gameProjects()`: Galaxy S5 and Desktop Chrome device descriptors (touch,
42
- mobile UA, isMobile on the phone), resized; never a bare viewport.
43
- - `armVisibleHeight()` / `shrinkVisibleHeight()`: a simulated browser toolbar. `relayoutGlobal` waits for
44
- every active Phaser scene to re-create and throws when the global is missing.
45
- - `expectFitTo()`, `expectCanvasHeight()`, `expectCanvasInside()`: game-shell fit assertions with a
46
- configurable canvas selector.
47
- - `domControls()`, `overlaps()`, `findOverlaps()`, `findOverlapsWithin()`, `canvasBoxToPage()`.
48
- - `diffPngs()` / `regionDiff()` / `countDiff()`: exact by default (tolerance 0, sizes must match);
49
- `ANTI_ALIAS_TOLERANCE` (48) and `width`/`height` opt into Surge's tolerant, scaled comparison.
50
- - `auditTouchTargets()` + `expectTouchTargets(AcrossRoutes)()`: the 44x44 hit-box gate.
51
- - `readHorizontalOverflow()` + `expectNoHorizontalOverflow(AcrossRoutes)()`: the no-horizontal-scroll
52
- gate, measured against the narrower of visualViewport width and clientWidth.
1
+ # Changelog
2
+
3
+ All notable changes to `@dloizides/game-e2e` are documented here.
4
+
5
+ ## 1.4.0
6
+
7
+ GAME-E2E-PRESS-1 "Faster pad presses in game-e2e walks":
8
+
9
+ - `stubGamepad().press` holds the button for exactly one sampled frame and resolves once a reader has seen it
10
+ released (`navigator.getGamepads()` calls latched to `document.timeline.currentTime`), instead of 3+3 fixed
11
+ `requestAnimationFrame` ticks. Under CPU load the old hold outlasted the 380 ms pad repeat delay and moved focus
12
+ twice, so the walk skipped rows. `STUB_FRAMES` is now 1; `PRESS_WAIT_FRAMES` (240) caps the wait when no reader polls.
13
+
14
+ ## 1.3.0
15
+
16
+ NAV-1 "Every game menu works with arrow keys and controller", phase 4 (canvas menus):
17
+
18
+ - `expectHookMenuWalkable(page, { screens, open, via?, sizes? })` / `walkHookMenus`: walks menus drawn on a canvas
19
+ (Phaser, Babylon GUI) through the `window.__menuWalk` hook (`MenuWalkHook` from `@dloizides/game-input` 1.6.0).
20
+ Per screen, at phone (360x640) and desktop (1280x720) viewports, by arrow keys and the stubbed pad: learns every
21
+ focus transition until no direction is left untried, fails naming each unreached item. `activates: { item, to }`
22
+ checks Enter / A opens a screen; Escape / B must leave the screen unless `leaves: false`.
23
+ - Arrow/pad driver moved to `menu-walk-driver.ts`, shared by the DOM and hook walkers (adds Enter / A `activate`).
24
+
25
+ ## 1.2.1
26
+
27
+ - Listener lookup is one `Runtime.evaluate` (DevTools `getEventListeners`) instead of two CDP calls per element. The
28
+ per-element calls slowed the walk enough that a screen re-rendering on a late fetch (Surge `stagePreview`) went red.
29
+
30
+ ## 1.2.0
31
+
32
+ NAV-1 "Every game menu works with arrow keys and controller", walker gap:
33
+
34
+ - The walker now finds pointer-only items whose click / pointerdown / pointerup handler is set as a property
35
+ (`el.onclick = ...`) or added with `addEventListener`, not only the `[onclick]` attribute. A visible element
36
+ with such a handler that is not focusable is reported `unreached`.
37
+ - Listeners are read through CDP `DOMDebugger.getEventListeners` (Chromium). Without CDP (Firefox, WebKit) only
38
+ the attribute and properties are checked, and each result carries a `notes` line saying so.
39
+ - Delegation: an element that contains a walk control, or sits inside one, is never flagged, so a listener on a
40
+ menu container does not flag the container or its children. When nested elements are both flagged, only the
41
+ innermost is reported.
42
+ - `WalkResult.notes` (new, printed as `note:` by `renderWalk`).
43
+
44
+ ## 1.1.0
45
+
46
+ NAV-1 "Every game menu works with arrow keys and controller", phase 1:
47
+
48
+ - `walkMenus()` / `expectMenuWalkable()`: open each screen, walk every focusable control by arrow keys and
49
+ by a stubbed gamepad (breadth-first from the focused control), report unreached controls, a dialog that
50
+ opens without focus inside it, sliders that ignore Left/Right, and Escape / B that does not close a dialog.
51
+ Exemptions take a selector and a printed reason.
52
+ - `stubGamepad()`: a `navigator.getGamepads()` stand-in driven from the test (`PadDriver.press`).
53
+ - `renderWalk()`, `walkFailed()`, `WALK_INPUTS`.
54
+ - Depends on `@dloizides/game-input` ^1.5.1 for the shared focusable and dialog selectors.
55
+
56
+ ## 1.0.0
57
+
58
+ First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
59
+ strictest behaviour of the three:
60
+
61
+ - `phone()` / `desktop()` / `gameProjects()`: Galaxy S5 and Desktop Chrome device descriptors (touch,
62
+ mobile UA, isMobile on the phone), resized; never a bare viewport.
63
+ - `armVisibleHeight()` / `shrinkVisibleHeight()`: a simulated browser toolbar. `relayoutGlobal` waits for
64
+ every active Phaser scene to re-create and throws when the global is missing.
65
+ - `expectFitTo()`, `expectCanvasHeight()`, `expectCanvasInside()`: game-shell fit assertions with a
66
+ configurable canvas selector.
67
+ - `domControls()`, `overlaps()`, `findOverlaps()`, `findOverlapsWithin()`, `canvasBoxToPage()`.
68
+ - `diffPngs()` / `regionDiff()` / `countDiff()`: exact by default (tolerance 0, sizes must match);
69
+ `ANTI_ALIAS_TOLERANCE` (48) and `width`/`height` opt into Surge's tolerant, scaled comparison.
70
+ - `auditTouchTargets()` + `expectTouchTargets(AcrossRoutes)()`: the 44x44 hit-box gate.
71
+ - `readHorizontalOverflow()` + `expectNoHorizontalOverflow(AcrossRoutes)()`: the no-horizontal-scroll
72
+ gate, measured against the narrower of visualViewport width and clientWidth.
package/dist/index.d.mts CHANGED
@@ -252,8 +252,36 @@ interface PadDriver {
252
252
  press(button: number): Promise<void>;
253
253
  hold(axis: number, value: number): Promise<void>;
254
254
  }
255
- declare const STUB_FRAMES = 3;
255
+ declare const STUB_FRAMES = 1;
256
256
  /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
257
257
  declare function stubGamepad(page: Page): Promise<PadDriver>;
258
258
 
259
- export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkMenus };
259
+ interface HookScreen {
260
+ name: string;
261
+ /** Items deliberately not walkable, each with a reason (printed in the report). */
262
+ exempt?: ReadonlyArray<{
263
+ item: string;
264
+ reason: string;
265
+ }>;
266
+ /** Escape / B must leave the screen. Default true; false for a root screen with nowhere to go. */
267
+ leaves?: boolean;
268
+ /** Enter / A on `item` must open screen `to`. */
269
+ activates?: {
270
+ item: string;
271
+ to: string;
272
+ };
273
+ }
274
+ interface HookWalkOptions {
275
+ screens: ReadonlyArray<string | HookScreen>;
276
+ /** Loads the page fresh (page.goto, so the pad stub applies) and opens the named screen. */
277
+ open: (page: Page, screen: string) => Promise<void>;
278
+ via?: readonly WalkInput[];
279
+ sizes?: ReadonlyArray<readonly [string, Size]>;
280
+ }
281
+ declare const HOOK_WALK_SIZES: ReadonlyArray<readonly [string, Size]>;
282
+ /** Walks each hook screen at each size by keys and stubbed pad; one result per screen, size and input. */
283
+ declare function walkHookMenus(page: Page, opts: HookWalkOptions): Promise<WalkResult[]>;
284
+ /** NAV-1 gate for canvas menus: throws, naming every unreached item and problem, unless all screens walk. */
285
+ declare function expectHookMenuWalkable(page: Page, opts: HookWalkOptions): Promise<void>;
286
+
287
+ export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, HOOK_WALK_SIZES, type HookScreen, type HookWalkOptions, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
package/dist/index.d.ts CHANGED
@@ -252,8 +252,36 @@ interface PadDriver {
252
252
  press(button: number): Promise<void>;
253
253
  hold(axis: number, value: number): Promise<void>;
254
254
  }
255
- declare const STUB_FRAMES = 3;
255
+ declare const STUB_FRAMES = 1;
256
256
  /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
257
257
  declare function stubGamepad(page: Page): Promise<PadDriver>;
258
258
 
259
- export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkMenus };
259
+ interface HookScreen {
260
+ name: string;
261
+ /** Items deliberately not walkable, each with a reason (printed in the report). */
262
+ exempt?: ReadonlyArray<{
263
+ item: string;
264
+ reason: string;
265
+ }>;
266
+ /** Escape / B must leave the screen. Default true; false for a root screen with nowhere to go. */
267
+ leaves?: boolean;
268
+ /** Enter / A on `item` must open screen `to`. */
269
+ activates?: {
270
+ item: string;
271
+ to: string;
272
+ };
273
+ }
274
+ interface HookWalkOptions {
275
+ screens: ReadonlyArray<string | HookScreen>;
276
+ /** Loads the page fresh (page.goto, so the pad stub applies) and opens the named screen. */
277
+ open: (page: Page, screen: string) => Promise<void>;
278
+ via?: readonly WalkInput[];
279
+ sizes?: ReadonlyArray<readonly [string, Size]>;
280
+ }
281
+ declare const HOOK_WALK_SIZES: ReadonlyArray<readonly [string, Size]>;
282
+ /** Walks each hook screen at each size by keys and stubbed pad; one result per screen, size and input. */
283
+ declare function walkHookMenus(page: Page, opts: HookWalkOptions): Promise<WalkResult[]>;
284
+ /** NAV-1 gate for canvas menus: throws, naming every unreached item and problem, unless all screens walk. */
285
+ declare function expectHookMenuWalkable(page: Page, opts: HookWalkOptions): Promise<void>;
286
+
287
+ export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, HOOK_WALK_SIZES, type HookScreen, type HookWalkOptions, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
package/dist/index.js CHANGED
@@ -468,43 +468,87 @@ async function expectNoHorizontalOverflow(page, where) {
468
468
  }
469
469
 
470
470
  // src/gamepad-stub.ts
471
- var STUB_FRAMES = 3;
471
+ var STUB_FRAMES = 1;
472
+ var PRESS_WAIT_FRAMES = 240;
472
473
  var STANDARD_BUTTON_COUNT = 17;
473
474
  var AXIS_COUNT = 4;
475
+ function installStub([buttons, axes]) {
476
+ const pad = { id: "nav-walk-stub", index: 0, connected: true, mapping: "standard", timestamp: 0, axes: new Array(axes).fill(0), buttons: Array.from({ length: buttons }, () => ({ pressed: false, touched: false, value: 0 })) };
477
+ const latch = { button: -1, frame: null, released: true };
478
+ const sample = () => {
479
+ const now = document.timeline.currentTime;
480
+ const held = pad.buttons[latch.button];
481
+ if (held !== void 0 && latch.frame === null) {
482
+ latch.frame = typeof now === "number" ? now : 0;
483
+ } else if (held !== void 0 && now !== latch.frame) {
484
+ held.pressed = false;
485
+ held.value = 0;
486
+ latch.button = -1;
487
+ latch.released = true;
488
+ }
489
+ return [pad, null, null, null];
490
+ };
491
+ Object.assign(window, { __navPad: pad, __navPress: latch });
492
+ Object.defineProperty(navigator, "getGamepads", { configurable: true, value: sample });
493
+ window.addEventListener("load", () => window.dispatchEvent(Object.assign(new Event("gamepadconnected"), { gamepad: pad })));
494
+ }
495
+ async function pressInPage([button, maxFrames]) {
496
+ const { __navPad: pad, __navPress: latch } = window;
497
+ const target = pad.buttons[button];
498
+ if (target === void 0) {
499
+ return;
500
+ }
501
+ target.pressed = true;
502
+ target.value = 1;
503
+ Object.assign(latch, { button, frame: null, released: false });
504
+ await new Promise((resolve) => {
505
+ const step = (left) => {
506
+ if (latch.released || left === 0) {
507
+ target.pressed = false;
508
+ target.value = 0;
509
+ Object.assign(latch, { button: -1, frame: null, released: true });
510
+ resolve();
511
+ return;
512
+ }
513
+ requestAnimationFrame(() => step(left - 1));
514
+ };
515
+ requestAnimationFrame(() => step(maxFrames));
516
+ });
517
+ }
474
518
  async function stubGamepad(page) {
475
- await page.addInitScript(([buttons, axes]) => {
476
- const pad = { id: "nav-walk-stub", index: 0, connected: true, mapping: "standard", timestamp: 0, axes: new Array(axes).fill(0), buttons: Array.from({ length: buttons }, () => ({ pressed: false, touched: false, value: 0 })) };
477
- Object.assign(window, { __navPad: pad });
478
- Object.defineProperty(navigator, "getGamepads", { configurable: true, value: () => [pad, null, null, null] });
479
- window.addEventListener("load", () => window.dispatchEvent(Object.assign(new Event("gamepadconnected"), { gamepad: pad })));
480
- }, [STANDARD_BUTTON_COUNT, AXIS_COUNT]);
519
+ await page.addInitScript(installStub, [STANDARD_BUTTON_COUNT, AXIS_COUNT]);
481
520
  return {
482
- press: (button) => page.evaluate(async ([b, n]) => {
483
- const pad = window.__navPad;
484
- const frames = (k) => new Promise((resolve) => {
485
- const step = (left) => {
486
- if (left === 0) {
487
- resolve();
488
- return;
489
- }
490
- requestAnimationFrame(() => step(left - 1));
491
- };
492
- step(k);
493
- });
494
- const target = pad.buttons[b] ?? { pressed: false, value: 0 };
495
- target.pressed = true;
496
- target.value = 1;
497
- await frames(n);
498
- target.pressed = false;
499
- target.value = 0;
500
- await frames(n);
501
- }, [button, STUB_FRAMES]),
521
+ press: (button) => page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES]),
502
522
  hold: (axis, value) => page.evaluate(([a, v]) => {
503
523
  window.__navPad.axes[a] = v;
504
524
  }, [axis, value])
505
525
  };
506
526
  }
507
527
 
528
+ // src/menu-walk-report.ts
529
+ var WALK_INPUTS = { keys: "keys", pad: "pad" };
530
+ var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
531
+ function renderWalk(results) {
532
+ return results.map((r) => [
533
+ `${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
534
+ ...r.unreached.map((n) => ` unreached: ${n}`),
535
+ ...r.problems.map((p) => ` problem: ${p}`),
536
+ ...r.exempt.map((e) => ` exempt: ${e}`),
537
+ ...r.notes.map((n) => ` note: ${n}`)
538
+ ].join("\n")).join("\n");
539
+ }
540
+
541
+ // src/menu-walk-driver.ts
542
+ var DIRS = ["up", "down", "left", "right"];
543
+ var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
544
+ var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
545
+ function driverFor(page, via, pad) {
546
+ if (via === WALK_INPUTS.pad && pad !== null) {
547
+ return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east), activate: () => pad.press(gameInput.STANDARD_BUTTON.south) };
548
+ }
549
+ return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape"), activate: () => page.keyboard.press("Enter") };
550
+ }
551
+
508
552
  // src/menu-walk-listeners.ts
509
553
  var POINTER_EVENTS = ["click", "pointerdown", "pointerup"];
510
554
  var NO_CDP_NOTE = "CDP unavailable (not Chromium): click/pointer listeners added with addEventListener were not checked; only [onclick] and handler properties were";
@@ -584,33 +628,11 @@ function rootOpen(rootAttr) {
584
628
  return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
585
629
  }
586
630
 
587
- // src/menu-walk-report.ts
588
- var WALK_INPUTS = { keys: "keys", pad: "pad" };
589
- var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
590
- function renderWalk(results) {
591
- return results.map((r) => [
592
- `${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
593
- ...r.unreached.map((n) => ` unreached: ${n}`),
594
- ...r.problems.map((p) => ` problem: ${p}`),
595
- ...r.exempt.map((e) => ` exempt: ${e}`),
596
- ...r.notes.map((n) => ` note: ${n}`)
597
- ].join("\n")).join("\n");
598
- }
599
-
600
631
  // src/menu-walk.ts
601
632
  var WALK_ATTR = "data-walk-id";
602
633
  var ROOT_ATTR = "data-walk-root";
603
634
  var PROBE_ATTR = "data-walk-probe";
604
635
  var PRESSES_PER_CONTROL = 4;
605
- var DIRS = ["up", "down", "left", "right"];
606
- var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
607
- var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
608
- function driverFor(page, via, pad) {
609
- if (via === WALK_INPUTS.pad && pad !== null) {
610
- return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east) };
611
- }
612
- return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape") };
613
- }
614
636
  var active = (page) => page.evaluate(activeWalkId, WALK_ATTR);
615
637
  var focusId = (page, id) => page.evaluate(focusWalkId, [WALK_ATTR, id]);
616
638
  async function bfs(page, driver, total) {
@@ -695,6 +717,184 @@ ${renderWalk(results)}`);
695
717
  }
696
718
  }
697
719
 
720
+ // src/menu-walk-graph.ts
721
+ var PRESSES_PER_ITEM = 16;
722
+ function shortestPath(edges, from, to) {
723
+ if (from === null) {
724
+ return null;
725
+ }
726
+ const prev = /* @__PURE__ */ new Map([[from, []]]);
727
+ const queue = [from];
728
+ while (queue.length > 0) {
729
+ const at2 = queue.shift();
730
+ const steps = prev.get(at2);
731
+ if (at2 === to) {
732
+ return steps;
733
+ }
734
+ for (const [d, next] of edges.get(at2) ?? []) {
735
+ if (next !== null && !prev.has(next)) {
736
+ prev.set(next, [...steps, d]);
737
+ queue.push(next);
738
+ }
739
+ }
740
+ }
741
+ return null;
742
+ }
743
+ function pendingDir(edges, node) {
744
+ const out = edges.get(node);
745
+ return out === void 0 ? void 0 : DIRS.find((x) => !out.has(x));
746
+ }
747
+ function nextUnexplored(edges, cur) {
748
+ const seen = new Set(cur === null ? [] : [cur]);
749
+ const queue = cur === null ? [] : [cur];
750
+ while (queue.length > 0) {
751
+ const at2 = queue.shift();
752
+ const d = pendingDir(edges, at2);
753
+ if (d !== void 0) {
754
+ return [at2, d];
755
+ }
756
+ for (const next of edges.get(at2)?.values() ?? []) {
757
+ if (next !== null && !seen.has(next)) {
758
+ seen.add(next);
759
+ queue.push(next);
760
+ }
761
+ }
762
+ }
763
+ for (const node of edges.keys()) {
764
+ const d = pendingDir(edges, node);
765
+ if (d !== void 0) {
766
+ return [node, d];
767
+ }
768
+ }
769
+ return null;
770
+ }
771
+ async function travel(m, edges, cur, node) {
772
+ let at2 = cur;
773
+ let steps = shortestPath(edges, at2, node);
774
+ if (steps === null) {
775
+ at2 = await m.reset();
776
+ steps = shortestPath(edges, at2, node) ?? [];
777
+ }
778
+ for (const d of steps) {
779
+ at2 = await m.press(d);
780
+ }
781
+ return at2;
782
+ }
783
+ async function exploreFocus(m, itemCount) {
784
+ const edges = /* @__PURE__ */ new Map();
785
+ let cur = await m.reset();
786
+ if (cur === null) {
787
+ cur = await m.press("down");
788
+ }
789
+ if (cur !== null) {
790
+ edges.set(cur, /* @__PURE__ */ new Map());
791
+ }
792
+ let budget = PRESSES_PER_ITEM * Math.max(itemCount, 1);
793
+ for (let next = nextUnexplored(edges, cur); next !== null && budget > 0; next = nextUnexplored(edges, cur)) {
794
+ const [node, d] = next;
795
+ const out = edges.get(node);
796
+ cur = await travel(m, edges, cur, node);
797
+ budget -= 1;
798
+ if (cur !== node) {
799
+ out.set(d, null);
800
+ continue;
801
+ }
802
+ cur = await m.press(d);
803
+ out.set(d, cur);
804
+ if (cur !== null && !edges.has(cur)) {
805
+ edges.set(cur, /* @__PURE__ */ new Map());
806
+ }
807
+ }
808
+ return { reached: new Set(edges.keys()), path: (from, to) => shortestPath(edges, from, to) };
809
+ }
810
+
811
+ // src/menu-walk-hook.ts
812
+ var HOOK_WALK_SIZES = [["phone", PHONE_SIZE], ["desktop", DESKTOP_SIZE]];
813
+ function readHook(name) {
814
+ const hook = window[name];
815
+ return hook === void 0 ? null : { screen: hook.screen(), items: hook.items(), focused: hook.focused() };
816
+ }
817
+ var read = (page) => page.evaluate(readHook, gameInput.MENU_WALK_HOOK);
818
+ async function reopen(w) {
819
+ await w.opts.open(w.page, w.screen.name);
820
+ return read(w.page);
821
+ }
822
+ function machine(w) {
823
+ return {
824
+ press: async (d) => {
825
+ await w.driver.dir(d);
826
+ return (await read(w.page))?.focused ?? null;
827
+ },
828
+ reset: async () => (await reopen(w))?.focused ?? null
829
+ };
830
+ }
831
+ async function activationProblem(w, graph, target) {
832
+ const steps = graph.path((await reopen(w))?.focused ?? null, target.item);
833
+ if (steps === null) {
834
+ return `cannot reach ${target.item} to activate it`;
835
+ }
836
+ for (const d of steps) {
837
+ await w.driver.dir(d);
838
+ }
839
+ await w.driver.activate();
840
+ const landed = (await read(w.page))?.screen;
841
+ const key = w.via === WALK_INPUTS.pad ? "A" : "Enter";
842
+ return landed === target.to ? null : `${key} on ${target.item} opens "${String(landed)}", expected "${target.to}"`;
843
+ }
844
+ async function actionProblems(w, graph) {
845
+ const problems = [];
846
+ const target = w.screen.activates;
847
+ const activation = target === void 0 ? null : await activationProblem(w, graph, target);
848
+ if (activation !== null) {
849
+ problems.push(activation);
850
+ }
851
+ if (w.screen.leaves !== false) {
852
+ await reopen(w);
853
+ await w.driver.back();
854
+ const key = w.via === WALK_INPUTS.pad ? "B" : "Escape";
855
+ if ((await read(w.page))?.screen === w.screen.name) {
856
+ problems.push(`${key} does not leave ${w.screen.name}`);
857
+ }
858
+ }
859
+ return problems;
860
+ }
861
+ async function walkHookScreen(w, size) {
862
+ const exempt = w.screen.exempt ?? [];
863
+ const base = { screen: `${w.screen.name} @${size}`, via: w.via, exempt: exempt.map((e) => `${e.item}: ${e.reason}`), notes: [] };
864
+ const first = await reopen(w);
865
+ if (first === null) {
866
+ return { ...base, reached: 0, total: 0, unreached: [], problems: [`window.${gameInput.MENU_WALK_HOOK} is not installed`] };
867
+ }
868
+ const problems = first.screen === w.screen.name ? [] : [`open landed on screen "${first.screen}"`];
869
+ const items = first.items.filter((i) => !exempt.some((e) => e.item === i));
870
+ const graph = await exploreFocus(machine(w), first.items.length);
871
+ const unreached = items.filter((i) => !graph.reached.has(i));
872
+ problems.push(...await actionProblems(w, graph));
873
+ return { ...base, reached: items.length - unreached.length, total: items.length, unreached, problems };
874
+ }
875
+ async function walkHookMenus(page, opts) {
876
+ const via = opts.via ?? [WALK_INPUTS.keys, WALK_INPUTS.pad];
877
+ const pad = via.includes(WALK_INPUTS.pad) ? await stubGamepad(page) : null;
878
+ const results = [];
879
+ for (const [label, size] of opts.sizes ?? HOOK_WALK_SIZES) {
880
+ await page.setViewportSize(size);
881
+ for (const s of opts.screens) {
882
+ const screen = typeof s === "string" ? { name: s } : s;
883
+ for (const v of via) {
884
+ results.push(await walkHookScreen({ page, opts, screen, driver: driverFor(page, v, pad), via: v }, label));
885
+ }
886
+ }
887
+ }
888
+ return results;
889
+ }
890
+ async function expectHookMenuWalkable(page, opts) {
891
+ const results = await walkHookMenus(page, opts);
892
+ if (results.some(walkFailed)) {
893
+ throw new Error(`Canvas menus not walkable by arrow keys / pad:
894
+ ${renderWalk(results)}`);
895
+ }
896
+ }
897
+
698
898
  exports.ANTI_ALIAS_TOLERANCE = ANTI_ALIAS_TOLERANCE;
699
899
  exports.CANVAS_TIMEOUT_MS = CANVAS_TIMEOUT_MS;
700
900
  exports.CONTROL_SELECTOR = CONTROL_SELECTOR;
@@ -704,6 +904,7 @@ exports.DESKTOP_SIZE = DESKTOP_SIZE;
704
904
  exports.EXACT = EXACT;
705
905
  exports.FIT_TIMEOUT_MS = FIT_TIMEOUT_MS;
706
906
  exports.GAME_SHELL_HEIGHT_VAR = GAME_SHELL_HEIGHT_VAR;
907
+ exports.HOOK_WALK_SIZES = HOOK_WALK_SIZES;
707
908
  exports.MAX_REPORTED = MAX_REPORTED;
708
909
  exports.MIN_TARGET_PX = MIN_TARGET_PX;
709
910
  exports.PHONE_DEVICE = PHONE_DEVICE;
@@ -724,6 +925,7 @@ exports.domControls = domControls;
724
925
  exports.expectCanvasHeight = expectCanvasHeight;
725
926
  exports.expectCanvasInside = expectCanvasInside;
726
927
  exports.expectFitTo = expectFitTo;
928
+ exports.expectHookMenuWalkable = expectHookMenuWalkable;
727
929
  exports.expectMenuWalkable = expectMenuWalkable;
728
930
  exports.expectNoHorizontalOverflow = expectNoHorizontalOverflow;
729
931
  exports.expectNoHorizontalOverflowAcrossRoutes = expectNoHorizontalOverflowAcrossRoutes;
@@ -749,6 +951,7 @@ exports.summariseOverflow = summariseOverflow;
749
951
  exports.summariseTouchTargets = summariseTouchTargets;
750
952
  exports.toOverflowReading = toOverflowReading;
751
953
  exports.walkFailed = walkFailed;
954
+ exports.walkHookMenus = walkHookMenus;
752
955
  exports.walkMenus = walkMenus;
753
956
  //# sourceMappingURL=index.js.map
754
957
  //# sourceMappingURL=index.js.map