@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.js
CHANGED
|
@@ -903,6 +903,201 @@ ${renderWalk(results)}`);
|
|
|
903
903
|
}
|
|
904
904
|
}
|
|
905
905
|
|
|
906
|
+
// src/text-fit-report.ts
|
|
907
|
+
var TEXT_FIT_TOLERANCE_PX = 1;
|
|
908
|
+
function ownOverflow(r, tol) {
|
|
909
|
+
if (r.inline) {
|
|
910
|
+
return null;
|
|
911
|
+
}
|
|
912
|
+
const wide = r.scrollWidth - r.clientWidth;
|
|
913
|
+
const tall = r.scrollHeight - r.clientHeight;
|
|
914
|
+
if (wide > tol) {
|
|
915
|
+
return { name: r.name, text: r.text, why: "text wider than its box", px: wide };
|
|
916
|
+
}
|
|
917
|
+
if (tall > tol) {
|
|
918
|
+
return { name: r.name, text: r.text, why: "text taller than its box", px: tall };
|
|
919
|
+
}
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
function spill(r, tol) {
|
|
923
|
+
const px = Math.max(r.parentLeft - r.left, r.parentTop - r.top, r.right - r.parentRight, r.bottom - r.parentBottom);
|
|
924
|
+
return px > tol ? { name: r.name, text: r.text, why: "spills out of its parent", px: Math.round(px) } : null;
|
|
925
|
+
}
|
|
926
|
+
function textFitFindings(r, tol = TEXT_FIT_TOLERANCE_PX) {
|
|
927
|
+
return [ownOverflow(r, tol), spill(r, tol)].filter((f) => f !== null);
|
|
928
|
+
}
|
|
929
|
+
var renderFinding = (f) => `
|
|
930
|
+
${f.name} "${f.text}": ${f.why} by ${String(f.px)}px`;
|
|
931
|
+
function summariseTextFit(states, where, tol = TEXT_FIT_TOLERANCE_PX) {
|
|
932
|
+
if (states.length === 0) {
|
|
933
|
+
return { problems: 1, message: `${where}: no UI state was measured at all` };
|
|
934
|
+
}
|
|
935
|
+
let problems = 0;
|
|
936
|
+
const lines = states.map((s) => {
|
|
937
|
+
if (s.readings.length === 0) {
|
|
938
|
+
problems += 1;
|
|
939
|
+
return `
|
|
940
|
+
${s.state}: BLIND - no visible text element matched`;
|
|
941
|
+
}
|
|
942
|
+
const found = s.readings.flatMap((r) => textFitFindings(r, tol));
|
|
943
|
+
problems += found.length;
|
|
944
|
+
const head = found.length > 0 ? `${String(found.length)} overflow(s)` : "ok";
|
|
945
|
+
return `
|
|
946
|
+
${s.state}: ${head} over ${String(s.readings.length)} text element(s)${found.map(renderFinding).join("")}`;
|
|
947
|
+
});
|
|
948
|
+
return { problems, message: `${where}: ${String(states.length)} state(s), ${String(problems)} problem(s)${lines.join("")}` };
|
|
949
|
+
}
|
|
950
|
+
var TEXT_FIT_SELECTOR = "body *";
|
|
951
|
+
async function readTextBoxes(page, selector = TEXT_FIT_SELECTOR) {
|
|
952
|
+
return page.evaluate((sel) => {
|
|
953
|
+
const display = (el) => getComputedStyle(el).display;
|
|
954
|
+
const ownText = (el) => [...el.childNodes].filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent ?? "").join("").trim();
|
|
955
|
+
const shown = (el) => {
|
|
956
|
+
const r = el.getBoundingClientRect();
|
|
957
|
+
return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== "hidden" && el.closest('[aria-hidden="true"]') === null;
|
|
958
|
+
};
|
|
959
|
+
const scrolls = (el) => /auto|scroll/.test(getComputedStyle(el).overflowX + getComputedStyle(el).overflowY);
|
|
960
|
+
const container = (el) => {
|
|
961
|
+
let p = el.parentElement;
|
|
962
|
+
while (p && (display(p) === "inline" || display(p) === "contents")) {
|
|
963
|
+
p = p.parentElement;
|
|
964
|
+
}
|
|
965
|
+
return p;
|
|
966
|
+
};
|
|
967
|
+
const label = (el) => {
|
|
968
|
+
const id = el.id !== "" ? `#${el.id}` : "";
|
|
969
|
+
const cls = typeof el.className === "string" && el.className.trim() !== "" ? `.${el.className.trim().split(/\s+/).join(".")}` : "";
|
|
970
|
+
return `${el.tagName.toLowerCase()}${id}${cls}`;
|
|
971
|
+
};
|
|
972
|
+
const els = [...document.querySelectorAll(sel)].filter((el) => !(el instanceof SVGElement) && ownText(el) !== "" && shown(el));
|
|
973
|
+
return els.flatMap((el) => {
|
|
974
|
+
const parent = container(el);
|
|
975
|
+
if (!parent || parent === document.body || parent === document.documentElement || scrolls(parent)) {
|
|
976
|
+
return [];
|
|
977
|
+
}
|
|
978
|
+
const r = el.getBoundingClientRect();
|
|
979
|
+
const p = parent.getBoundingClientRect();
|
|
980
|
+
return [{
|
|
981
|
+
name: label(el),
|
|
982
|
+
text: ownText(el).slice(0, 40),
|
|
983
|
+
inline: display(el) === "inline",
|
|
984
|
+
clientWidth: el.clientWidth,
|
|
985
|
+
clientHeight: el.clientHeight,
|
|
986
|
+
scrollWidth: el.scrollWidth,
|
|
987
|
+
scrollHeight: el.scrollHeight,
|
|
988
|
+
left: r.left,
|
|
989
|
+
top: r.top,
|
|
990
|
+
right: r.right,
|
|
991
|
+
bottom: r.bottom,
|
|
992
|
+
parentLeft: p.left,
|
|
993
|
+
parentTop: p.top,
|
|
994
|
+
parentRight: p.right,
|
|
995
|
+
parentBottom: p.bottom
|
|
996
|
+
}];
|
|
997
|
+
});
|
|
998
|
+
}, selector);
|
|
999
|
+
}
|
|
1000
|
+
async function measureTextFit(page, selector = TEXT_FIT_SELECTOR, states) {
|
|
1001
|
+
if (!states || states.length === 0) {
|
|
1002
|
+
return [{ state: "current", readings: await readTextBoxes(page, selector) }];
|
|
1003
|
+
}
|
|
1004
|
+
const out = [];
|
|
1005
|
+
for (const s of states) {
|
|
1006
|
+
await s.enter(page);
|
|
1007
|
+
out.push({ state: s.name, readings: await readTextBoxes(page, selector) });
|
|
1008
|
+
}
|
|
1009
|
+
return out;
|
|
1010
|
+
}
|
|
1011
|
+
async function expectTextFits(page, selector = TEXT_FIT_SELECTOR, options = {}) {
|
|
1012
|
+
const measured = await measureTextFit(page, selector, options.states);
|
|
1013
|
+
const summary = summariseTextFit(measured, options.where ?? selector, options.tolerancePx ?? TEXT_FIT_TOLERANCE_PX);
|
|
1014
|
+
test.expect(summary.problems, summary.message).toBe(0);
|
|
1015
|
+
return measured;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// src/action-binding-report.ts
|
|
1019
|
+
function bindingFindings(r, action) {
|
|
1020
|
+
const found = [];
|
|
1021
|
+
if (r.key === null) {
|
|
1022
|
+
found.push({ name: r.name, why: `action ${action} has no key binding` });
|
|
1023
|
+
}
|
|
1024
|
+
if (r.pad === null) {
|
|
1025
|
+
found.push({ name: r.name, why: `action ${action} has no pad binding` });
|
|
1026
|
+
}
|
|
1027
|
+
return found;
|
|
1028
|
+
}
|
|
1029
|
+
function promptFinding(r) {
|
|
1030
|
+
const comparable = r.promptText !== null && r.expectedPromptText !== null;
|
|
1031
|
+
if (!comparable || r.promptText === r.expectedPromptText) {
|
|
1032
|
+
return null;
|
|
1033
|
+
}
|
|
1034
|
+
return { name: r.name, why: `prompt shows "${String(r.promptText)}" but the current binding is "${String(r.expectedPromptText)}"` };
|
|
1035
|
+
}
|
|
1036
|
+
function actionBindingFindings(r) {
|
|
1037
|
+
if (r.action === null) {
|
|
1038
|
+
return r.hasPointerHandler ? [{ name: r.name, why: "pointer handler but no data-gi-action" }] : [];
|
|
1039
|
+
}
|
|
1040
|
+
const prompt = promptFinding(r);
|
|
1041
|
+
const bindings = bindingFindings(r, r.action);
|
|
1042
|
+
return prompt === null ? bindings : [...bindings, prompt];
|
|
1043
|
+
}
|
|
1044
|
+
var renderFinding2 = (f) => `
|
|
1045
|
+
${f.name}: ${f.why}`;
|
|
1046
|
+
function summariseActionBinding(readings, where) {
|
|
1047
|
+
if (readings.length === 0) {
|
|
1048
|
+
return { problems: 1, message: `${where}: BLIND - no clickable or data-gi-action element was read` };
|
|
1049
|
+
}
|
|
1050
|
+
const found = readings.flatMap(actionBindingFindings);
|
|
1051
|
+
const head = `${where}: ${String(readings.length)} element(s), ${String(found.length)} problem(s)`;
|
|
1052
|
+
return { problems: found.length, message: `${head}${found.map(renderFinding2).join("")}` };
|
|
1053
|
+
}
|
|
1054
|
+
var ACTION_ATTR = "data-gi-action";
|
|
1055
|
+
var PROMPT_ATTR = "data-gi-prompt";
|
|
1056
|
+
var POINTER_SELECTOR = 'button, a[href], [role="button"], [onclick]';
|
|
1057
|
+
var ACTION_ROOT_SELECTOR = "body";
|
|
1058
|
+
function toActionReading(el, bindings) {
|
|
1059
|
+
const b = el.action === null ? void 0 : bindings[el.action];
|
|
1060
|
+
return { ...el, key: b?.key ?? null, pad: b?.pad ?? null, expectedPromptText: b?.prompt ?? null };
|
|
1061
|
+
}
|
|
1062
|
+
async function readActionElements(page, root = ACTION_ROOT_SELECTOR, pointerSelector = POINTER_SELECTOR) {
|
|
1063
|
+
return page.evaluate(({ rootSel, pointerSel, actionAttr, promptAttr }) => {
|
|
1064
|
+
const shown = (el) => {
|
|
1065
|
+
const r = el.getBoundingClientRect();
|
|
1066
|
+
return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== "hidden" && el.closest('[aria-hidden="true"]') === null;
|
|
1067
|
+
};
|
|
1068
|
+
const label = (el) => {
|
|
1069
|
+
const id = el.id !== "" ? `#${el.id}` : "";
|
|
1070
|
+
const tag = el.getAttribute(actionAttr);
|
|
1071
|
+
const suffix = tag !== null && id === "" ? `[${actionAttr}=${tag}]` : "";
|
|
1072
|
+
return `${el.tagName.toLowerCase()}${id}${suffix}`;
|
|
1073
|
+
};
|
|
1074
|
+
const prompt = (el) => {
|
|
1075
|
+
const p = el.hasAttribute(promptAttr) ? el : el.querySelector(`[${promptAttr}]`);
|
|
1076
|
+
return p !== null && shown(p) ? (p.textContent ?? "").trim() : null;
|
|
1077
|
+
};
|
|
1078
|
+
const roots = [...document.querySelectorAll(rootSel)];
|
|
1079
|
+
const els = new Set(roots.flatMap((r) => [...r.querySelectorAll(`${pointerSel}, [${actionAttr}]`)]));
|
|
1080
|
+
return [...els].filter(shown).map((el) => ({
|
|
1081
|
+
name: label(el),
|
|
1082
|
+
action: el.getAttribute(actionAttr),
|
|
1083
|
+
hasPointerHandler: el.matches(pointerSel),
|
|
1084
|
+
promptText: prompt(el)
|
|
1085
|
+
}));
|
|
1086
|
+
}, { rootSel: root, pointerSel: pointerSelector, actionAttr: ACTION_ATTR, promptAttr: PROMPT_ATTR });
|
|
1087
|
+
}
|
|
1088
|
+
async function measureActionBinding(page, bindings, options = {}) {
|
|
1089
|
+
const els = await readActionElements(page, options.root, options.pointerSelector);
|
|
1090
|
+
return els.map((el) => toActionReading(el, bindings));
|
|
1091
|
+
}
|
|
1092
|
+
async function expectActionsBound(page, bindings, options = {}) {
|
|
1093
|
+
const readings = await measureActionBinding(page, bindings, options);
|
|
1094
|
+
const summary = summariseActionBinding(readings, options.where ?? options.root ?? ACTION_ROOT_SELECTOR);
|
|
1095
|
+
test.expect(summary.problems, summary.message).toBe(0);
|
|
1096
|
+
return readings;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
exports.ACTION_ATTR = ACTION_ATTR;
|
|
1100
|
+
exports.ACTION_ROOT_SELECTOR = ACTION_ROOT_SELECTOR;
|
|
906
1101
|
exports.ANTI_ALIAS_TOLERANCE = ANTI_ALIAS_TOLERANCE;
|
|
907
1102
|
exports.CANVAS_TIMEOUT_MS = CANVAS_TIMEOUT_MS;
|
|
908
1103
|
exports.CONTROL_SELECTOR = CONTROL_SELECTOR;
|
|
@@ -917,9 +1112,14 @@ exports.MAX_REPORTED = MAX_REPORTED;
|
|
|
917
1112
|
exports.MIN_TARGET_PX = MIN_TARGET_PX;
|
|
918
1113
|
exports.PHONE_DEVICE = PHONE_DEVICE;
|
|
919
1114
|
exports.PHONE_SIZE = PHONE_SIZE;
|
|
1115
|
+
exports.POINTER_SELECTOR = POINTER_SELECTOR;
|
|
1116
|
+
exports.PROMPT_ATTR = PROMPT_ATTR;
|
|
920
1117
|
exports.RELAYOUT_TIMEOUT_MS = RELAYOUT_TIMEOUT_MS;
|
|
921
1118
|
exports.STUB_FRAMES = STUB_FRAMES;
|
|
1119
|
+
exports.TEXT_FIT_SELECTOR = TEXT_FIT_SELECTOR;
|
|
1120
|
+
exports.TEXT_FIT_TOLERANCE_PX = TEXT_FIT_TOLERANCE_PX;
|
|
922
1121
|
exports.WALK_INPUTS = WALK_INPUTS;
|
|
1122
|
+
exports.actionBindingFindings = actionBindingFindings;
|
|
923
1123
|
exports.armVisibleHeight = armVisibleHeight;
|
|
924
1124
|
exports.auditRoute = auditRoute;
|
|
925
1125
|
exports.auditTouchTargets = auditTouchTargets;
|
|
@@ -930,6 +1130,7 @@ exports.desktop = desktop;
|
|
|
930
1130
|
exports.deviceDescriptor = deviceDescriptor;
|
|
931
1131
|
exports.diffPngs = diffPngs;
|
|
932
1132
|
exports.domControls = domControls;
|
|
1133
|
+
exports.expectActionsBound = expectActionsBound;
|
|
933
1134
|
exports.expectCanvasHeight = expectCanvasHeight;
|
|
934
1135
|
exports.expectCanvasInside = expectCanvasInside;
|
|
935
1136
|
exports.expectFitTo = expectFitTo;
|
|
@@ -937,16 +1138,21 @@ exports.expectHookMenuWalkable = expectHookMenuWalkable;
|
|
|
937
1138
|
exports.expectMenuWalkable = expectMenuWalkable;
|
|
938
1139
|
exports.expectNoHorizontalOverflow = expectNoHorizontalOverflow;
|
|
939
1140
|
exports.expectNoHorizontalOverflowAcrossRoutes = expectNoHorizontalOverflowAcrossRoutes;
|
|
1141
|
+
exports.expectTextFits = expectTextFits;
|
|
940
1142
|
exports.expectTouchTargets = expectTouchTargets;
|
|
941
1143
|
exports.expectTouchTargetsAcrossRoutes = expectTouchTargetsAcrossRoutes;
|
|
942
1144
|
exports.findOverlaps = findOverlaps;
|
|
943
1145
|
exports.findOverlapsWithin = findOverlapsWithin;
|
|
944
1146
|
exports.gameProjects = gameProjects;
|
|
945
1147
|
exports.horizontalOverflowPx = horizontalOverflowPx;
|
|
1148
|
+
exports.measureActionBinding = measureActionBinding;
|
|
946
1149
|
exports.measureHorizontalOverflow = measureHorizontalOverflow;
|
|
1150
|
+
exports.measureTextFit = measureTextFit;
|
|
947
1151
|
exports.overlaps = overlaps;
|
|
948
1152
|
exports.phone = phone;
|
|
1153
|
+
exports.readActionElements = readActionElements;
|
|
949
1154
|
exports.readHorizontalOverflow = readHorizontalOverflow;
|
|
1155
|
+
exports.readTextBoxes = readTextBoxes;
|
|
950
1156
|
exports.regionDiff = regionDiff;
|
|
951
1157
|
exports.renderFindings = renderFindings;
|
|
952
1158
|
exports.renderOverflow = renderOverflow;
|
|
@@ -955,8 +1161,12 @@ exports.renderWalk = renderWalk;
|
|
|
955
1161
|
exports.routeProblems = routeProblems;
|
|
956
1162
|
exports.shrinkVisibleHeight = shrinkVisibleHeight;
|
|
957
1163
|
exports.stubGamepad = stubGamepad;
|
|
1164
|
+
exports.summariseActionBinding = summariseActionBinding;
|
|
958
1165
|
exports.summariseOverflow = summariseOverflow;
|
|
1166
|
+
exports.summariseTextFit = summariseTextFit;
|
|
959
1167
|
exports.summariseTouchTargets = summariseTouchTargets;
|
|
1168
|
+
exports.textFitFindings = textFitFindings;
|
|
1169
|
+
exports.toActionReading = toActionReading;
|
|
960
1170
|
exports.toOverflowReading = toOverflowReading;
|
|
961
1171
|
exports.walkFailed = walkFailed;
|
|
962
1172
|
exports.walkHookMenus = walkHookMenus;
|