@dloizides/game-e2e 1.2.0 → 1.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/CHANGELOG.md +63 -47
- package/dist/index.d.mts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +210 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,47 +1,63 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to `@dloizides/game-e2e` are documented here.
|
|
4
|
-
|
|
5
|
-
## 1.
|
|
6
|
-
|
|
7
|
-
NAV-1 "Every game menu works with arrow keys and controller",
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- `
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
- `
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@dloizides/game-e2e` are documented here.
|
|
4
|
+
|
|
5
|
+
## 1.3.0
|
|
6
|
+
|
|
7
|
+
NAV-1 "Every game menu works with arrow keys and controller", phase 4 (canvas menus):
|
|
8
|
+
|
|
9
|
+
- `expectHookMenuWalkable(page, { screens, open, via?, sizes? })` / `walkHookMenus`: walks menus drawn on a canvas
|
|
10
|
+
(Phaser, Babylon GUI) through the `window.__menuWalk` hook (`MenuWalkHook` from `@dloizides/game-input` 1.6.0).
|
|
11
|
+
Per screen, at phone (360x640) and desktop (1280x720) viewports, by arrow keys and the stubbed pad: learns every
|
|
12
|
+
focus transition until no direction is left untried, fails naming each unreached item. `activates: { item, to }`
|
|
13
|
+
checks Enter / A opens a screen; Escape / B must leave the screen unless `leaves: false`.
|
|
14
|
+
- Arrow/pad driver moved to `menu-walk-driver.ts`, shared by the DOM and hook walkers (adds Enter / A `activate`).
|
|
15
|
+
|
|
16
|
+
## 1.2.1
|
|
17
|
+
|
|
18
|
+
- Listener lookup is one `Runtime.evaluate` (DevTools `getEventListeners`) instead of two CDP calls per element. The
|
|
19
|
+
per-element calls slowed the walk enough that a screen re-rendering on a late fetch (Surge `stagePreview`) went red.
|
|
20
|
+
|
|
21
|
+
## 1.2.0
|
|
22
|
+
|
|
23
|
+
NAV-1 "Every game menu works with arrow keys and controller", walker gap:
|
|
24
|
+
|
|
25
|
+
- The walker now finds pointer-only items whose click / pointerdown / pointerup handler is set as a property
|
|
26
|
+
(`el.onclick = ...`) or added with `addEventListener`, not only the `[onclick]` attribute. A visible element
|
|
27
|
+
with such a handler that is not focusable is reported `unreached`.
|
|
28
|
+
- Listeners are read through CDP `DOMDebugger.getEventListeners` (Chromium). Without CDP (Firefox, WebKit) only
|
|
29
|
+
the attribute and properties are checked, and each result carries a `notes` line saying so.
|
|
30
|
+
- Delegation: an element that contains a walk control, or sits inside one, is never flagged, so a listener on a
|
|
31
|
+
menu container does not flag the container or its children. When nested elements are both flagged, only the
|
|
32
|
+
innermost is reported.
|
|
33
|
+
- `WalkResult.notes` (new, printed as `note:` by `renderWalk`).
|
|
34
|
+
|
|
35
|
+
## 1.1.0
|
|
36
|
+
|
|
37
|
+
NAV-1 "Every game menu works with arrow keys and controller", phase 1:
|
|
38
|
+
|
|
39
|
+
- `walkMenus()` / `expectMenuWalkable()`: open each screen, walk every focusable control by arrow keys and
|
|
40
|
+
by a stubbed gamepad (breadth-first from the focused control), report unreached controls, a dialog that
|
|
41
|
+
opens without focus inside it, sliders that ignore Left/Right, and Escape / B that does not close a dialog.
|
|
42
|
+
Exemptions take a selector and a printed reason.
|
|
43
|
+
- `stubGamepad()`: a `navigator.getGamepads()` stand-in driven from the test (`PadDriver.press`).
|
|
44
|
+
- `renderWalk()`, `walkFailed()`, `WALK_INPUTS`.
|
|
45
|
+
- Depends on `@dloizides/game-input` ^1.5.1 for the shared focusable and dialog selectors.
|
|
46
|
+
|
|
47
|
+
## 1.0.0
|
|
48
|
+
|
|
49
|
+
First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
|
|
50
|
+
strictest behaviour of the three:
|
|
51
|
+
|
|
52
|
+
- `phone()` / `desktop()` / `gameProjects()`: Galaxy S5 and Desktop Chrome device descriptors (touch,
|
|
53
|
+
mobile UA, isMobile on the phone), resized; never a bare viewport.
|
|
54
|
+
- `armVisibleHeight()` / `shrinkVisibleHeight()`: a simulated browser toolbar. `relayoutGlobal` waits for
|
|
55
|
+
every active Phaser scene to re-create and throws when the global is missing.
|
|
56
|
+
- `expectFitTo()`, `expectCanvasHeight()`, `expectCanvasInside()`: game-shell fit assertions with a
|
|
57
|
+
configurable canvas selector.
|
|
58
|
+
- `domControls()`, `overlaps()`, `findOverlaps()`, `findOverlapsWithin()`, `canvasBoxToPage()`.
|
|
59
|
+
- `diffPngs()` / `regionDiff()` / `countDiff()`: exact by default (tolerance 0, sizes must match);
|
|
60
|
+
`ANTI_ALIAS_TOLERANCE` (48) and `width`/`height` opt into Surge's tolerant, scaled comparison.
|
|
61
|
+
- `auditTouchTargets()` + `expectTouchTargets(AcrossRoutes)()`: the 44x44 hit-box gate.
|
|
62
|
+
- `readHorizontalOverflow()` + `expectNoHorizontalOverflow(AcrossRoutes)()`: the no-horizontal-scroll
|
|
63
|
+
gate, measured against the narrower of visualViewport width and clientWidth.
|
package/dist/index.d.mts
CHANGED
|
@@ -256,4 +256,32 @@ declare const STUB_FRAMES = 3;
|
|
|
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
|
-
|
|
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
|
@@ -256,4 +256,32 @@ declare const STUB_FRAMES = 3;
|
|
|
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
|
-
|
|
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
|
@@ -505,6 +505,30 @@ async function stubGamepad(page) {
|
|
|
505
505
|
};
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
+
// src/menu-walk-report.ts
|
|
509
|
+
var WALK_INPUTS = { keys: "keys", pad: "pad" };
|
|
510
|
+
var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
|
|
511
|
+
function renderWalk(results) {
|
|
512
|
+
return results.map((r) => [
|
|
513
|
+
`${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
|
|
514
|
+
...r.unreached.map((n) => ` unreached: ${n}`),
|
|
515
|
+
...r.problems.map((p) => ` problem: ${p}`),
|
|
516
|
+
...r.exempt.map((e) => ` exempt: ${e}`),
|
|
517
|
+
...r.notes.map((n) => ` note: ${n}`)
|
|
518
|
+
].join("\n")).join("\n");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/menu-walk-driver.ts
|
|
522
|
+
var DIRS = ["up", "down", "left", "right"];
|
|
523
|
+
var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
|
|
524
|
+
var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
|
|
525
|
+
function driverFor(page, via, pad) {
|
|
526
|
+
if (via === WALK_INPUTS.pad && pad !== null) {
|
|
527
|
+
return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east), activate: () => pad.press(gameInput.STANDARD_BUTTON.south) };
|
|
528
|
+
}
|
|
529
|
+
return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape"), activate: () => page.keyboard.press("Enter") };
|
|
530
|
+
}
|
|
531
|
+
|
|
508
532
|
// src/menu-walk-listeners.ts
|
|
509
533
|
var POINTER_EVENTS = ["click", "pointerdown", "pointerup"];
|
|
510
534
|
var NO_CDP_NOTE = "CDP unavailable (not Chromium): click/pointer listeners added with addEventListener were not checked; only [onclick] and handler properties were";
|
|
@@ -530,24 +554,14 @@ async function openCdp(page) {
|
|
|
530
554
|
return null;
|
|
531
555
|
}
|
|
532
556
|
}
|
|
533
|
-
async function listenerProbes(cdp, probeAttr
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
if (result.objectId === void 0) {
|
|
538
|
-
continue;
|
|
539
|
-
}
|
|
540
|
-
const { listeners } = await cdp.send("DOMDebugger.getEventListeners", { objectId: result.objectId });
|
|
541
|
-
if (listeners.some((l) => POINTER_EVENTS.includes(l.type))) {
|
|
542
|
-
hits.push(i);
|
|
543
|
-
}
|
|
544
|
-
await cdp.send("Runtime.releaseObject", { objectId: result.objectId });
|
|
545
|
-
}
|
|
546
|
-
return hits;
|
|
557
|
+
async function listenerProbes(cdp, probeAttr) {
|
|
558
|
+
const expression = `Array.from(document.querySelectorAll('[${probeAttr}]')).filter((el) => ${JSON.stringify(POINTER_EVENTS)}.some((t) => (getEventListeners(el)[t] ?? []).length > 0)).map((el) => Number(el.getAttribute('${probeAttr}')))`;
|
|
559
|
+
const { result } = await cdp.send("Runtime.evaluate", { expression, includeCommandLineAPI: true, returnByValue: true });
|
|
560
|
+
return Array.isArray(result.value) ? result.value : [];
|
|
547
561
|
}
|
|
548
562
|
async function pointerOnlyControls(page, cdp, args, start) {
|
|
549
563
|
const marks = await page.evaluate(markProbes, args);
|
|
550
|
-
const viaListener = cdp === null ? [] : await listenerProbes(cdp, args.probeAttr
|
|
564
|
+
const viaListener = cdp === null || marks.probes === 0 ? [] : await listenerProbes(cdp, args.probeAttr);
|
|
551
565
|
const ids = [.../* @__PURE__ */ new Set([...marks.withProperty, ...viaListener])];
|
|
552
566
|
const identities = await page.evaluate(flagProbes, [args.attr, args.probeAttr, ids, start]);
|
|
553
567
|
return { identities, notes: cdp === null ? [NO_CDP_NOTE] : [] };
|
|
@@ -594,33 +608,11 @@ function rootOpen(rootAttr) {
|
|
|
594
608
|
return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
|
|
595
609
|
}
|
|
596
610
|
|
|
597
|
-
// src/menu-walk-report.ts
|
|
598
|
-
var WALK_INPUTS = { keys: "keys", pad: "pad" };
|
|
599
|
-
var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
|
|
600
|
-
function renderWalk(results) {
|
|
601
|
-
return results.map((r) => [
|
|
602
|
-
`${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
|
|
603
|
-
...r.unreached.map((n) => ` unreached: ${n}`),
|
|
604
|
-
...r.problems.map((p) => ` problem: ${p}`),
|
|
605
|
-
...r.exempt.map((e) => ` exempt: ${e}`),
|
|
606
|
-
...r.notes.map((n) => ` note: ${n}`)
|
|
607
|
-
].join("\n")).join("\n");
|
|
608
|
-
}
|
|
609
|
-
|
|
610
611
|
// src/menu-walk.ts
|
|
611
612
|
var WALK_ATTR = "data-walk-id";
|
|
612
613
|
var ROOT_ATTR = "data-walk-root";
|
|
613
614
|
var PROBE_ATTR = "data-walk-probe";
|
|
614
615
|
var PRESSES_PER_CONTROL = 4;
|
|
615
|
-
var DIRS = ["up", "down", "left", "right"];
|
|
616
|
-
var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
|
|
617
|
-
var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
|
|
618
|
-
function driverFor(page, via, pad) {
|
|
619
|
-
if (via === WALK_INPUTS.pad && pad !== null) {
|
|
620
|
-
return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east) };
|
|
621
|
-
}
|
|
622
|
-
return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape") };
|
|
623
|
-
}
|
|
624
616
|
var active = (page) => page.evaluate(activeWalkId, WALK_ATTR);
|
|
625
617
|
var focusId = (page, id) => page.evaluate(focusWalkId, [WALK_ATTR, id]);
|
|
626
618
|
async function bfs(page, driver, total) {
|
|
@@ -705,6 +697,184 @@ ${renderWalk(results)}`);
|
|
|
705
697
|
}
|
|
706
698
|
}
|
|
707
699
|
|
|
700
|
+
// src/menu-walk-graph.ts
|
|
701
|
+
var PRESSES_PER_ITEM = 16;
|
|
702
|
+
function shortestPath(edges, from, to) {
|
|
703
|
+
if (from === null) {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
const prev = /* @__PURE__ */ new Map([[from, []]]);
|
|
707
|
+
const queue = [from];
|
|
708
|
+
while (queue.length > 0) {
|
|
709
|
+
const at2 = queue.shift();
|
|
710
|
+
const steps = prev.get(at2);
|
|
711
|
+
if (at2 === to) {
|
|
712
|
+
return steps;
|
|
713
|
+
}
|
|
714
|
+
for (const [d, next] of edges.get(at2) ?? []) {
|
|
715
|
+
if (next !== null && !prev.has(next)) {
|
|
716
|
+
prev.set(next, [...steps, d]);
|
|
717
|
+
queue.push(next);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
function pendingDir(edges, node) {
|
|
724
|
+
const out = edges.get(node);
|
|
725
|
+
return out === void 0 ? void 0 : DIRS.find((x) => !out.has(x));
|
|
726
|
+
}
|
|
727
|
+
function nextUnexplored(edges, cur) {
|
|
728
|
+
const seen = new Set(cur === null ? [] : [cur]);
|
|
729
|
+
const queue = cur === null ? [] : [cur];
|
|
730
|
+
while (queue.length > 0) {
|
|
731
|
+
const at2 = queue.shift();
|
|
732
|
+
const d = pendingDir(edges, at2);
|
|
733
|
+
if (d !== void 0) {
|
|
734
|
+
return [at2, d];
|
|
735
|
+
}
|
|
736
|
+
for (const next of edges.get(at2)?.values() ?? []) {
|
|
737
|
+
if (next !== null && !seen.has(next)) {
|
|
738
|
+
seen.add(next);
|
|
739
|
+
queue.push(next);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
for (const node of edges.keys()) {
|
|
744
|
+
const d = pendingDir(edges, node);
|
|
745
|
+
if (d !== void 0) {
|
|
746
|
+
return [node, d];
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return null;
|
|
750
|
+
}
|
|
751
|
+
async function travel(m, edges, cur, node) {
|
|
752
|
+
let at2 = cur;
|
|
753
|
+
let steps = shortestPath(edges, at2, node);
|
|
754
|
+
if (steps === null) {
|
|
755
|
+
at2 = await m.reset();
|
|
756
|
+
steps = shortestPath(edges, at2, node) ?? [];
|
|
757
|
+
}
|
|
758
|
+
for (const d of steps) {
|
|
759
|
+
at2 = await m.press(d);
|
|
760
|
+
}
|
|
761
|
+
return at2;
|
|
762
|
+
}
|
|
763
|
+
async function exploreFocus(m, itemCount) {
|
|
764
|
+
const edges = /* @__PURE__ */ new Map();
|
|
765
|
+
let cur = await m.reset();
|
|
766
|
+
if (cur === null) {
|
|
767
|
+
cur = await m.press("down");
|
|
768
|
+
}
|
|
769
|
+
if (cur !== null) {
|
|
770
|
+
edges.set(cur, /* @__PURE__ */ new Map());
|
|
771
|
+
}
|
|
772
|
+
let budget = PRESSES_PER_ITEM * Math.max(itemCount, 1);
|
|
773
|
+
for (let next = nextUnexplored(edges, cur); next !== null && budget > 0; next = nextUnexplored(edges, cur)) {
|
|
774
|
+
const [node, d] = next;
|
|
775
|
+
const out = edges.get(node);
|
|
776
|
+
cur = await travel(m, edges, cur, node);
|
|
777
|
+
budget -= 1;
|
|
778
|
+
if (cur !== node) {
|
|
779
|
+
out.set(d, null);
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
cur = await m.press(d);
|
|
783
|
+
out.set(d, cur);
|
|
784
|
+
if (cur !== null && !edges.has(cur)) {
|
|
785
|
+
edges.set(cur, /* @__PURE__ */ new Map());
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return { reached: new Set(edges.keys()), path: (from, to) => shortestPath(edges, from, to) };
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// src/menu-walk-hook.ts
|
|
792
|
+
var HOOK_WALK_SIZES = [["phone", PHONE_SIZE], ["desktop", DESKTOP_SIZE]];
|
|
793
|
+
function readHook(name) {
|
|
794
|
+
const hook = window[name];
|
|
795
|
+
return hook === void 0 ? null : { screen: hook.screen(), items: hook.items(), focused: hook.focused() };
|
|
796
|
+
}
|
|
797
|
+
var read = (page) => page.evaluate(readHook, gameInput.MENU_WALK_HOOK);
|
|
798
|
+
async function reopen(w) {
|
|
799
|
+
await w.opts.open(w.page, w.screen.name);
|
|
800
|
+
return read(w.page);
|
|
801
|
+
}
|
|
802
|
+
function machine(w) {
|
|
803
|
+
return {
|
|
804
|
+
press: async (d) => {
|
|
805
|
+
await w.driver.dir(d);
|
|
806
|
+
return (await read(w.page))?.focused ?? null;
|
|
807
|
+
},
|
|
808
|
+
reset: async () => (await reopen(w))?.focused ?? null
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
async function activationProblem(w, graph, target) {
|
|
812
|
+
const steps = graph.path((await reopen(w))?.focused ?? null, target.item);
|
|
813
|
+
if (steps === null) {
|
|
814
|
+
return `cannot reach ${target.item} to activate it`;
|
|
815
|
+
}
|
|
816
|
+
for (const d of steps) {
|
|
817
|
+
await w.driver.dir(d);
|
|
818
|
+
}
|
|
819
|
+
await w.driver.activate();
|
|
820
|
+
const landed = (await read(w.page))?.screen;
|
|
821
|
+
const key = w.via === WALK_INPUTS.pad ? "A" : "Enter";
|
|
822
|
+
return landed === target.to ? null : `${key} on ${target.item} opens "${String(landed)}", expected "${target.to}"`;
|
|
823
|
+
}
|
|
824
|
+
async function actionProblems(w, graph) {
|
|
825
|
+
const problems = [];
|
|
826
|
+
const target = w.screen.activates;
|
|
827
|
+
const activation = target === void 0 ? null : await activationProblem(w, graph, target);
|
|
828
|
+
if (activation !== null) {
|
|
829
|
+
problems.push(activation);
|
|
830
|
+
}
|
|
831
|
+
if (w.screen.leaves !== false) {
|
|
832
|
+
await reopen(w);
|
|
833
|
+
await w.driver.back();
|
|
834
|
+
const key = w.via === WALK_INPUTS.pad ? "B" : "Escape";
|
|
835
|
+
if ((await read(w.page))?.screen === w.screen.name) {
|
|
836
|
+
problems.push(`${key} does not leave ${w.screen.name}`);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return problems;
|
|
840
|
+
}
|
|
841
|
+
async function walkHookScreen(w, size) {
|
|
842
|
+
const exempt = w.screen.exempt ?? [];
|
|
843
|
+
const base = { screen: `${w.screen.name} @${size}`, via: w.via, exempt: exempt.map((e) => `${e.item}: ${e.reason}`), notes: [] };
|
|
844
|
+
const first = await reopen(w);
|
|
845
|
+
if (first === null) {
|
|
846
|
+
return { ...base, reached: 0, total: 0, unreached: [], problems: [`window.${gameInput.MENU_WALK_HOOK} is not installed`] };
|
|
847
|
+
}
|
|
848
|
+
const problems = first.screen === w.screen.name ? [] : [`open landed on screen "${first.screen}"`];
|
|
849
|
+
const items = first.items.filter((i) => !exempt.some((e) => e.item === i));
|
|
850
|
+
const graph = await exploreFocus(machine(w), first.items.length);
|
|
851
|
+
const unreached = items.filter((i) => !graph.reached.has(i));
|
|
852
|
+
problems.push(...await actionProblems(w, graph));
|
|
853
|
+
return { ...base, reached: items.length - unreached.length, total: items.length, unreached, problems };
|
|
854
|
+
}
|
|
855
|
+
async function walkHookMenus(page, opts) {
|
|
856
|
+
const via = opts.via ?? [WALK_INPUTS.keys, WALK_INPUTS.pad];
|
|
857
|
+
const pad = via.includes(WALK_INPUTS.pad) ? await stubGamepad(page) : null;
|
|
858
|
+
const results = [];
|
|
859
|
+
for (const [label, size] of opts.sizes ?? HOOK_WALK_SIZES) {
|
|
860
|
+
await page.setViewportSize(size);
|
|
861
|
+
for (const s of opts.screens) {
|
|
862
|
+
const screen = typeof s === "string" ? { name: s } : s;
|
|
863
|
+
for (const v of via) {
|
|
864
|
+
results.push(await walkHookScreen({ page, opts, screen, driver: driverFor(page, v, pad), via: v }, label));
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return results;
|
|
869
|
+
}
|
|
870
|
+
async function expectHookMenuWalkable(page, opts) {
|
|
871
|
+
const results = await walkHookMenus(page, opts);
|
|
872
|
+
if (results.some(walkFailed)) {
|
|
873
|
+
throw new Error(`Canvas menus not walkable by arrow keys / pad:
|
|
874
|
+
${renderWalk(results)}`);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
708
878
|
exports.ANTI_ALIAS_TOLERANCE = ANTI_ALIAS_TOLERANCE;
|
|
709
879
|
exports.CANVAS_TIMEOUT_MS = CANVAS_TIMEOUT_MS;
|
|
710
880
|
exports.CONTROL_SELECTOR = CONTROL_SELECTOR;
|
|
@@ -714,6 +884,7 @@ exports.DESKTOP_SIZE = DESKTOP_SIZE;
|
|
|
714
884
|
exports.EXACT = EXACT;
|
|
715
885
|
exports.FIT_TIMEOUT_MS = FIT_TIMEOUT_MS;
|
|
716
886
|
exports.GAME_SHELL_HEIGHT_VAR = GAME_SHELL_HEIGHT_VAR;
|
|
887
|
+
exports.HOOK_WALK_SIZES = HOOK_WALK_SIZES;
|
|
717
888
|
exports.MAX_REPORTED = MAX_REPORTED;
|
|
718
889
|
exports.MIN_TARGET_PX = MIN_TARGET_PX;
|
|
719
890
|
exports.PHONE_DEVICE = PHONE_DEVICE;
|
|
@@ -734,6 +905,7 @@ exports.domControls = domControls;
|
|
|
734
905
|
exports.expectCanvasHeight = expectCanvasHeight;
|
|
735
906
|
exports.expectCanvasInside = expectCanvasInside;
|
|
736
907
|
exports.expectFitTo = expectFitTo;
|
|
908
|
+
exports.expectHookMenuWalkable = expectHookMenuWalkable;
|
|
737
909
|
exports.expectMenuWalkable = expectMenuWalkable;
|
|
738
910
|
exports.expectNoHorizontalOverflow = expectNoHorizontalOverflow;
|
|
739
911
|
exports.expectNoHorizontalOverflowAcrossRoutes = expectNoHorizontalOverflowAcrossRoutes;
|
|
@@ -759,6 +931,7 @@ exports.summariseOverflow = summariseOverflow;
|
|
|
759
931
|
exports.summariseTouchTargets = summariseTouchTargets;
|
|
760
932
|
exports.toOverflowReading = toOverflowReading;
|
|
761
933
|
exports.walkFailed = walkFailed;
|
|
934
|
+
exports.walkHookMenus = walkHookMenus;
|
|
762
935
|
exports.walkMenus = walkMenus;
|
|
763
936
|
//# sourceMappingURL=index.js.map
|
|
764
937
|
//# sourceMappingURL=index.js.map
|