@dloizides/game-e2e 1.4.1 → 1.6.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 +17 -0
- package/README.md +122 -116
- package/dist/index.d.mts +104 -1
- package/dist/index.d.ts +104 -1
- package/dist/index.js +210 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -901,6 +901,199 @@ ${renderWalk(results)}`);
|
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
|
|
904
|
-
|
|
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
|
+
// src/action-binding-report.ts
|
|
1017
|
+
function bindingFindings(r, action) {
|
|
1018
|
+
const found = [];
|
|
1019
|
+
if (r.key === null) {
|
|
1020
|
+
found.push({ name: r.name, why: `action ${action} has no key binding` });
|
|
1021
|
+
}
|
|
1022
|
+
if (r.pad === null) {
|
|
1023
|
+
found.push({ name: r.name, why: `action ${action} has no pad binding` });
|
|
1024
|
+
}
|
|
1025
|
+
return found;
|
|
1026
|
+
}
|
|
1027
|
+
function promptFinding(r) {
|
|
1028
|
+
const comparable = r.promptText !== null && r.expectedPromptText !== null;
|
|
1029
|
+
if (!comparable || r.promptText === r.expectedPromptText) {
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
return { name: r.name, why: `prompt shows "${String(r.promptText)}" but the current binding is "${String(r.expectedPromptText)}"` };
|
|
1033
|
+
}
|
|
1034
|
+
function actionBindingFindings(r) {
|
|
1035
|
+
if (r.action === null) {
|
|
1036
|
+
return r.hasPointerHandler ? [{ name: r.name, why: "pointer handler but no data-gi-action" }] : [];
|
|
1037
|
+
}
|
|
1038
|
+
const prompt = promptFinding(r);
|
|
1039
|
+
const bindings = bindingFindings(r, r.action);
|
|
1040
|
+
return prompt === null ? bindings : [...bindings, prompt];
|
|
1041
|
+
}
|
|
1042
|
+
var renderFinding2 = (f) => `
|
|
1043
|
+
${f.name}: ${f.why}`;
|
|
1044
|
+
function summariseActionBinding(readings, where) {
|
|
1045
|
+
if (readings.length === 0) {
|
|
1046
|
+
return { problems: 1, message: `${where}: BLIND - no clickable or data-gi-action element was read` };
|
|
1047
|
+
}
|
|
1048
|
+
const found = readings.flatMap(actionBindingFindings);
|
|
1049
|
+
const head = `${where}: ${String(readings.length)} element(s), ${String(found.length)} problem(s)`;
|
|
1050
|
+
return { problems: found.length, message: `${head}${found.map(renderFinding2).join("")}` };
|
|
1051
|
+
}
|
|
1052
|
+
var ACTION_ATTR = "data-gi-action";
|
|
1053
|
+
var PROMPT_ATTR = "data-gi-prompt";
|
|
1054
|
+
var POINTER_SELECTOR = 'button, a[href], [role="button"], [onclick]';
|
|
1055
|
+
var ACTION_ROOT_SELECTOR = "body";
|
|
1056
|
+
function toActionReading(el, bindings) {
|
|
1057
|
+
const b = el.action === null ? void 0 : bindings[el.action];
|
|
1058
|
+
return { ...el, key: b?.key ?? null, pad: b?.pad ?? null, expectedPromptText: b?.prompt ?? null };
|
|
1059
|
+
}
|
|
1060
|
+
async function readActionElements(page, root = ACTION_ROOT_SELECTOR, pointerSelector = POINTER_SELECTOR) {
|
|
1061
|
+
return page.evaluate(({ rootSel, pointerSel, actionAttr, promptAttr }) => {
|
|
1062
|
+
const shown = (el) => {
|
|
1063
|
+
const r = el.getBoundingClientRect();
|
|
1064
|
+
return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== "hidden" && el.closest('[aria-hidden="true"]') === null;
|
|
1065
|
+
};
|
|
1066
|
+
const label = (el) => {
|
|
1067
|
+
const id = el.id !== "" ? `#${el.id}` : "";
|
|
1068
|
+
const tag = el.getAttribute(actionAttr);
|
|
1069
|
+
const suffix = tag !== null && id === "" ? `[${actionAttr}=${tag}]` : "";
|
|
1070
|
+
return `${el.tagName.toLowerCase()}${id}${suffix}`;
|
|
1071
|
+
};
|
|
1072
|
+
const prompt = (el) => {
|
|
1073
|
+
const p = el.hasAttribute(promptAttr) ? el : el.querySelector(`[${promptAttr}]`);
|
|
1074
|
+
return p !== null && shown(p) ? (p.textContent ?? "").trim() : null;
|
|
1075
|
+
};
|
|
1076
|
+
const roots = [...document.querySelectorAll(rootSel)];
|
|
1077
|
+
const els = new Set(roots.flatMap((r) => [...r.querySelectorAll(`${pointerSel}, [${actionAttr}]`)]));
|
|
1078
|
+
return [...els].filter(shown).map((el) => ({
|
|
1079
|
+
name: label(el),
|
|
1080
|
+
action: el.getAttribute(actionAttr),
|
|
1081
|
+
hasPointerHandler: el.matches(pointerSel),
|
|
1082
|
+
promptText: prompt(el)
|
|
1083
|
+
}));
|
|
1084
|
+
}, { rootSel: root, pointerSel: pointerSelector, actionAttr: ACTION_ATTR, promptAttr: PROMPT_ATTR });
|
|
1085
|
+
}
|
|
1086
|
+
async function measureActionBinding(page, bindings, options = {}) {
|
|
1087
|
+
const els = await readActionElements(page, options.root, options.pointerSelector);
|
|
1088
|
+
return els.map((el) => toActionReading(el, bindings));
|
|
1089
|
+
}
|
|
1090
|
+
async function expectActionsBound(page, bindings, options = {}) {
|
|
1091
|
+
const readings = await measureActionBinding(page, bindings, options);
|
|
1092
|
+
const summary = summariseActionBinding(readings, options.where ?? options.root ?? ACTION_ROOT_SELECTOR);
|
|
1093
|
+
expect(summary.problems, summary.message).toBe(0);
|
|
1094
|
+
return readings;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
export { ACTION_ATTR, ACTION_ROOT_SELECTOR, 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, POINTER_SELECTOR, PROMPT_ATTR, RELAYOUT_TIMEOUT_MS, STUB_FRAMES, TEXT_FIT_SELECTOR, TEXT_FIT_TOLERANCE_PX, WALK_INPUTS, actionBindingFindings, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectActionsBound, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTextFits, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureActionBinding, measureHorizontalOverflow, measureTextFit, overlaps, phone, readActionElements, readHorizontalOverflow, readTextBoxes, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseActionBinding, summariseOverflow, summariseTextFit, summariseTouchTargets, textFitFindings, toActionReading, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
|
|
905
1098
|
//# sourceMappingURL=index.mjs.map
|
|
906
1099
|
//# sourceMappingURL=index.mjs.map
|