@dloizides/game-e2e 1.4.0 → 1.5.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 +8 -0
- package/README.md +122 -116
- package/dist/index.d.mts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +132 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -468,14 +468,18 @@ async function expectNoHorizontalOverflow(page, where) {
|
|
|
468
468
|
// src/gamepad-stub.ts
|
|
469
469
|
var STUB_FRAMES = 1;
|
|
470
470
|
var PRESS_WAIT_FRAMES = 240;
|
|
471
|
+
var IDLE_RELEASE_FRAMES = 3;
|
|
471
472
|
var STANDARD_BUTTON_COUNT = 17;
|
|
472
473
|
var AXIS_COUNT = 4;
|
|
473
474
|
function installStub([buttons, axes]) {
|
|
474
475
|
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 })) };
|
|
475
|
-
const latch = { button: -1, frame: null, released: true };
|
|
476
|
+
const latch = { button: -1, frame: null, released: true, reads: 0 };
|
|
476
477
|
const sample = () => {
|
|
477
478
|
const now = document.timeline.currentTime;
|
|
478
479
|
const held = pad.buttons[latch.button];
|
|
480
|
+
if (held !== void 0) {
|
|
481
|
+
latch.reads += 1;
|
|
482
|
+
}
|
|
479
483
|
if (held !== void 0 && latch.frame === null) {
|
|
480
484
|
latch.frame = typeof now === "number" ? now : 0;
|
|
481
485
|
} else if (held !== void 0 && now !== latch.frame) {
|
|
@@ -490,7 +494,7 @@ function installStub([buttons, axes]) {
|
|
|
490
494
|
Object.defineProperty(navigator, "getGamepads", { configurable: true, value: sample });
|
|
491
495
|
window.addEventListener("load", () => window.dispatchEvent(Object.assign(new Event("gamepadconnected"), { gamepad: pad })));
|
|
492
496
|
}
|
|
493
|
-
async function pressInPage([button, maxFrames]) {
|
|
497
|
+
async function pressInPage([button, maxFrames, idleFrames]) {
|
|
494
498
|
const { __navPad: pad, __navPress: latch } = window;
|
|
495
499
|
const target = pad.buttons[button];
|
|
496
500
|
if (target === void 0) {
|
|
@@ -498,10 +502,14 @@ async function pressInPage([button, maxFrames]) {
|
|
|
498
502
|
}
|
|
499
503
|
target.pressed = true;
|
|
500
504
|
target.value = 1;
|
|
501
|
-
Object.assign(latch, { button, frame: null, released: false });
|
|
505
|
+
Object.assign(latch, { button, frame: null, released: false, reads: 0 });
|
|
502
506
|
await new Promise((resolve) => {
|
|
507
|
+
let seen = 0;
|
|
508
|
+
let idle = 0;
|
|
503
509
|
const step = (left) => {
|
|
504
|
-
|
|
510
|
+
idle = latch.reads === seen ? idle + 1 : 0;
|
|
511
|
+
seen = latch.reads;
|
|
512
|
+
if (latch.released || left === 0 || idle >= idleFrames) {
|
|
505
513
|
target.pressed = false;
|
|
506
514
|
target.value = 0;
|
|
507
515
|
Object.assign(latch, { button: -1, frame: null, released: true });
|
|
@@ -516,7 +524,7 @@ async function pressInPage([button, maxFrames]) {
|
|
|
516
524
|
async function stubGamepad(page) {
|
|
517
525
|
await page.addInitScript(installStub, [STANDARD_BUTTON_COUNT, AXIS_COUNT]);
|
|
518
526
|
return {
|
|
519
|
-
press: (button) => page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES]),
|
|
527
|
+
press: (button) => page.evaluate(pressInPage, [button, PRESS_WAIT_FRAMES, IDLE_RELEASE_FRAMES]),
|
|
520
528
|
hold: (axis, value) => page.evaluate(([a, v]) => {
|
|
521
529
|
window.__navPad.axes[a] = v;
|
|
522
530
|
}, [axis, value])
|
|
@@ -893,6 +901,118 @@ ${renderWalk(results)}`);
|
|
|
893
901
|
}
|
|
894
902
|
}
|
|
895
903
|
|
|
896
|
-
|
|
904
|
+
// src/text-fit-report.ts
|
|
905
|
+
var TEXT_FIT_TOLERANCE_PX = 1;
|
|
906
|
+
function ownOverflow(r, tol) {
|
|
907
|
+
if (r.inline) {
|
|
908
|
+
return null;
|
|
909
|
+
}
|
|
910
|
+
const wide = r.scrollWidth - r.clientWidth;
|
|
911
|
+
const tall = r.scrollHeight - r.clientHeight;
|
|
912
|
+
if (wide > tol) {
|
|
913
|
+
return { name: r.name, text: r.text, why: "text wider than its box", px: wide };
|
|
914
|
+
}
|
|
915
|
+
if (tall > tol) {
|
|
916
|
+
return { name: r.name, text: r.text, why: "text taller than its box", px: tall };
|
|
917
|
+
}
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
function spill(r, tol) {
|
|
921
|
+
const px = Math.max(r.parentLeft - r.left, r.parentTop - r.top, r.right - r.parentRight, r.bottom - r.parentBottom);
|
|
922
|
+
return px > tol ? { name: r.name, text: r.text, why: "spills out of its parent", px: Math.round(px) } : null;
|
|
923
|
+
}
|
|
924
|
+
function textFitFindings(r, tol = TEXT_FIT_TOLERANCE_PX) {
|
|
925
|
+
return [ownOverflow(r, tol), spill(r, tol)].filter((f) => f !== null);
|
|
926
|
+
}
|
|
927
|
+
var renderFinding = (f) => `
|
|
928
|
+
${f.name} "${f.text}": ${f.why} by ${String(f.px)}px`;
|
|
929
|
+
function summariseTextFit(states, where, tol = TEXT_FIT_TOLERANCE_PX) {
|
|
930
|
+
if (states.length === 0) {
|
|
931
|
+
return { problems: 1, message: `${where}: no UI state was measured at all` };
|
|
932
|
+
}
|
|
933
|
+
let problems = 0;
|
|
934
|
+
const lines = states.map((s) => {
|
|
935
|
+
if (s.readings.length === 0) {
|
|
936
|
+
problems += 1;
|
|
937
|
+
return `
|
|
938
|
+
${s.state}: BLIND - no visible text element matched`;
|
|
939
|
+
}
|
|
940
|
+
const found = s.readings.flatMap((r) => textFitFindings(r, tol));
|
|
941
|
+
problems += found.length;
|
|
942
|
+
const head = found.length > 0 ? `${String(found.length)} overflow(s)` : "ok";
|
|
943
|
+
return `
|
|
944
|
+
${s.state}: ${head} over ${String(s.readings.length)} text element(s)${found.map(renderFinding).join("")}`;
|
|
945
|
+
});
|
|
946
|
+
return { problems, message: `${where}: ${String(states.length)} state(s), ${String(problems)} problem(s)${lines.join("")}` };
|
|
947
|
+
}
|
|
948
|
+
var TEXT_FIT_SELECTOR = "body *";
|
|
949
|
+
async function readTextBoxes(page, selector = TEXT_FIT_SELECTOR) {
|
|
950
|
+
return page.evaluate((sel) => {
|
|
951
|
+
const display = (el) => getComputedStyle(el).display;
|
|
952
|
+
const ownText = (el) => [...el.childNodes].filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent ?? "").join("").trim();
|
|
953
|
+
const shown = (el) => {
|
|
954
|
+
const r = el.getBoundingClientRect();
|
|
955
|
+
return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== "hidden" && el.closest('[aria-hidden="true"]') === null;
|
|
956
|
+
};
|
|
957
|
+
const scrolls = (el) => /auto|scroll/.test(getComputedStyle(el).overflowX + getComputedStyle(el).overflowY);
|
|
958
|
+
const container = (el) => {
|
|
959
|
+
let p = el.parentElement;
|
|
960
|
+
while (p && (display(p) === "inline" || display(p) === "contents")) {
|
|
961
|
+
p = p.parentElement;
|
|
962
|
+
}
|
|
963
|
+
return p;
|
|
964
|
+
};
|
|
965
|
+
const label = (el) => {
|
|
966
|
+
const id = el.id !== "" ? `#${el.id}` : "";
|
|
967
|
+
const cls = typeof el.className === "string" && el.className.trim() !== "" ? `.${el.className.trim().split(/\s+/).join(".")}` : "";
|
|
968
|
+
return `${el.tagName.toLowerCase()}${id}${cls}`;
|
|
969
|
+
};
|
|
970
|
+
const els = [...document.querySelectorAll(sel)].filter((el) => !(el instanceof SVGElement) && ownText(el) !== "" && shown(el));
|
|
971
|
+
return els.flatMap((el) => {
|
|
972
|
+
const parent = container(el);
|
|
973
|
+
if (!parent || parent === document.body || parent === document.documentElement || scrolls(parent)) {
|
|
974
|
+
return [];
|
|
975
|
+
}
|
|
976
|
+
const r = el.getBoundingClientRect();
|
|
977
|
+
const p = parent.getBoundingClientRect();
|
|
978
|
+
return [{
|
|
979
|
+
name: label(el),
|
|
980
|
+
text: ownText(el).slice(0, 40),
|
|
981
|
+
inline: display(el) === "inline",
|
|
982
|
+
clientWidth: el.clientWidth,
|
|
983
|
+
clientHeight: el.clientHeight,
|
|
984
|
+
scrollWidth: el.scrollWidth,
|
|
985
|
+
scrollHeight: el.scrollHeight,
|
|
986
|
+
left: r.left,
|
|
987
|
+
top: r.top,
|
|
988
|
+
right: r.right,
|
|
989
|
+
bottom: r.bottom,
|
|
990
|
+
parentLeft: p.left,
|
|
991
|
+
parentTop: p.top,
|
|
992
|
+
parentRight: p.right,
|
|
993
|
+
parentBottom: p.bottom
|
|
994
|
+
}];
|
|
995
|
+
});
|
|
996
|
+
}, selector);
|
|
997
|
+
}
|
|
998
|
+
async function measureTextFit(page, selector = TEXT_FIT_SELECTOR, states) {
|
|
999
|
+
if (!states || states.length === 0) {
|
|
1000
|
+
return [{ state: "current", readings: await readTextBoxes(page, selector) }];
|
|
1001
|
+
}
|
|
1002
|
+
const out = [];
|
|
1003
|
+
for (const s of states) {
|
|
1004
|
+
await s.enter(page);
|
|
1005
|
+
out.push({ state: s.name, readings: await readTextBoxes(page, selector) });
|
|
1006
|
+
}
|
|
1007
|
+
return out;
|
|
1008
|
+
}
|
|
1009
|
+
async function expectTextFits(page, selector = TEXT_FIT_SELECTOR, options = {}) {
|
|
1010
|
+
const measured = await measureTextFit(page, selector, options.states);
|
|
1011
|
+
const summary = summariseTextFit(measured, options.where ?? selector, options.tolerancePx ?? TEXT_FIT_TOLERANCE_PX);
|
|
1012
|
+
expect(summary.problems, summary.message).toBe(0);
|
|
1013
|
+
return measured;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
export { ANTI_ALIAS_TOLERANCE, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, EXACT, FIT_TIMEOUT_MS, GAME_SHELL_HEIGHT_VAR, HOOK_WALK_SIZES, MAX_REPORTED, MIN_TARGET_PX, PHONE_DEVICE, PHONE_SIZE, RELAYOUT_TIMEOUT_MS, STUB_FRAMES, TEXT_FIT_SELECTOR, TEXT_FIT_TOLERANCE_PX, WALK_INPUTS, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTextFits, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, measureTextFit, overlaps, phone, readHorizontalOverflow, readTextBoxes, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTextFit, summariseTouchTargets, textFitFindings, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
|
|
897
1017
|
//# sourceMappingURL=index.mjs.map
|
|
898
1018
|
//# sourceMappingURL=index.mjs.map
|