@krizaka/page-audit 0.7.0 → 0.8.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/README.md +20 -8
- package/package.json +2 -2
- package/src/fixtures.mjs +8 -0
- package/src/index.d.ts +2 -0
- package/src/page-audit.mjs +21 -0
- package/src/self-test.mjs +5 -0
package/README.md
CHANGED
|
@@ -25,15 +25,24 @@ Opt-in through `checks` (nothing changes for a repo that does not ask): `status`
|
|
|
25
25
|
(the signed-in frame, `[data-app-frame-slot]`, forces a scroll), `minAction` (a button-styled action under N px), `boxes` (a landmark
|
|
26
26
|
wider than its box), `landmarks` (`"public"` one footer naming Krizaka and a nav, `"app"`, `"auth"`), `pictures`, `emptyControls`,
|
|
27
27
|
`hardColors`, `maps` (an empty map, akinaza#488: a GL / Leaflet / `[data-kz-map]` box under 120 px on a side, a GL map with no canvas,
|
|
28
|
-
a Leaflet map with no loaded tile; `maps: { required: true }` also fails a page that should draw one but has none), `controlOverlaps` (two interactive elements that share pixels on screen, one not inside the other — akinaza#214: the composer's title over a row). Console noise the app tolerates: `ignoreConsole: [/…/]` (`[]` counts every error); `attempts` retries a route.
|
|
28
|
+
a Leaflet map with no loaded tile; `maps: { required: true }` also fails a page that should draw one but has none), `smallTargets` (a control under 44 px on a side — an inline link in a sentence is exempt), `controlOverlaps` (two interactive elements that share pixels on screen, one not inside the other — akinaza#214: the composer's title over a row). Console noise the app tolerates: `ignoreConsole: [/…/]` (`[]` counts every error); `attempts` retries a route.
|
|
29
29
|
|
|
30
30
|
```js
|
|
31
31
|
const routes = await routesFromSitemap(base, { first: ["/", "/docs"], limit: 14 }); // a crawl as the route source (null: nothing answers)
|
|
32
32
|
await auditRoutes({
|
|
33
|
-
base,
|
|
34
|
-
|
|
33
|
+
base,
|
|
34
|
+
routes: [...routes, { url: "/login", chrome: "auth" }, { url: "/chat", session: true, chrome: "app" }],
|
|
35
|
+
widths: [
|
|
36
|
+
{ width: 1440, height: 900 },
|
|
37
|
+
{ width: 390, height: 844 },
|
|
38
|
+
],
|
|
35
39
|
session: { storageState }, // or { signIn(context, { base, theme }) {…}, routes: async (page) => […] } for pages found once signed in
|
|
36
|
-
a11y: {
|
|
40
|
+
a11y: {
|
|
41
|
+
app: "my-app",
|
|
42
|
+
baseline: "a11y-baseline.json",
|
|
43
|
+
widths: [390, 1440],
|
|
44
|
+
session: { app: "my-app-app", baseline: "a11y-baseline.app.json" },
|
|
45
|
+
},
|
|
37
46
|
checks: { status: true, emptyMain: true, minAction: 36, landmarks: "public", frame: true },
|
|
38
47
|
});
|
|
39
48
|
```
|
|
@@ -50,13 +59,16 @@ as the runner. It freezes what moves (clock, motion, caret, View Transition, loc
|
|
|
50
59
|
import { test, expect } from "@playwright/test";
|
|
51
60
|
import { defineJourneyTests } from "@krizaka/page-audit/visual";
|
|
52
61
|
defineJourneyTests({
|
|
53
|
-
test,
|
|
54
|
-
|
|
62
|
+
test,
|
|
63
|
+
expect,
|
|
64
|
+
signIn: async (page) => {
|
|
65
|
+
/* the seeded persona signs in through the form */
|
|
66
|
+
},
|
|
55
67
|
journeys: [
|
|
56
68
|
{ name: "landing", path: "/fr" },
|
|
57
69
|
{ name: "home", path: "/fr/app", session: true, mask: ["[data-live]"] },
|
|
58
|
-
{ name: "home", path: "/fr/app", session: true, firstPaint: true, viewports: ["phone"] },
|
|
59
|
-
{ name: "home", path: "/fr/app", session: true, firstPaint: { hold: ["**/api/me"] } },
|
|
70
|
+
{ name: "home", path: "/fr/app", session: true, firstPaint: true, viewports: ["phone"] }, // the HTML the server sent
|
|
71
|
+
{ name: "home", path: "/fr/app", session: true, firstPaint: { hold: ["**/api/me"] } }, // hydrated, account query pending
|
|
60
72
|
],
|
|
61
73
|
});
|
|
62
74
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krizaka/page-audit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "The page audit of every Krizaka app, in one place: HTTP status, empty main, horizontal overflow, a card out of its panel, sections covering each other, a column cut off, top chrome overlaps, unnamed buttons, empty headings. Runs in a real browser (Playwright) over a route list, viewports and themes, with View Transitions neutralised and a self-test on its own fixtures.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"krizaka",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"eslint": "^9.39.0",
|
|
66
66
|
"playwright-core": "^1.55.0",
|
|
67
67
|
"vitest": "^4.1.11",
|
|
68
|
-
"@krizaka/config": "^0.
|
|
68
|
+
"@krizaka/config": "^0.20.0"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=22"
|
package/src/fixtures.mjs
CHANGED
|
@@ -43,6 +43,14 @@ export const FRAME_FITS = page(
|
|
|
43
43
|
);
|
|
44
44
|
/** A button-styled action 24 px tall, under the 36 px tap target. */
|
|
45
45
|
export const SMALL_ACTION = page(`<a class="kz-button" href="/" style="display:block;height:24px;width:120px">Go</a>`);
|
|
46
|
+
/** A button 32 px tall next to a 44 px one, and a link inside a sentence (exempt). */
|
|
47
|
+
export const SMALL_TARGET = page(
|
|
48
|
+
`<button style="display:block;height:32px;width:120px">Add</button><p>Read <a href="/">the guide</a> now</p>`,
|
|
49
|
+
);
|
|
50
|
+
/** Controls of 44 px and more, and an inline link. */
|
|
51
|
+
export const TARGETS_FINE = page(
|
|
52
|
+
`<button style="display:block;height:44px;width:120px">Add</button><a href="/" style="display:block;height:48px;width:48px">x</a><p>Read <a href="/">the guide</a> now</p>`,
|
|
53
|
+
);
|
|
46
54
|
/** A landmark whose content is wider than its box. */
|
|
47
55
|
export const BOX_TOO_WIDE = page(`<aside style="width:200px"><div style="width:500px">wide</div></aside>`);
|
|
48
56
|
/** Broken picture, a tile that draws nothing, an inline hard-coded colour. */
|
package/src/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface ProblemChecks {
|
|
|
23
23
|
maps?: boolean | { min?: number; required?: boolean };
|
|
24
24
|
/** Two interactive elements (buttons, links, inputs, radios…) that share pixels on screen, one not inside the other: one of them cannot be clicked. The box is cut by clipping and scrolling ancestors. */
|
|
25
25
|
controlOverlaps?: boolean;
|
|
26
|
+
/** A control (button, link outside a sentence, input, tab…) drawn under 44 px on a side: too small for a thumb (WCAG 2.5.5). */
|
|
27
|
+
smallTargets?: boolean;
|
|
26
28
|
}
|
|
27
29
|
export function problemsOf(where: string, result: Record<string, unknown>, checks?: ProblemChecks): string[];
|
|
28
30
|
export function auditOptions<T extends object>(options?: T): T & { reducedMotion: "reduce" };
|
package/src/page-audit.mjs
CHANGED
|
@@ -153,6 +153,20 @@ function controlOverlapsOf() {
|
|
|
153
153
|
return overlaps;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
/** `smallTargets`: the controls drawn on screen under 44 px on a side (WCAG 2.5.5, the thumb): an inline link in a sentence is exempt. */
|
|
157
|
+
function smallTargetsOf() {
|
|
158
|
+
const controls =
|
|
159
|
+
'button, a[href], input:not([type="hidden"]), select, textarea, summary, [role="button"], [role="radio"], [role="checkbox"], [role="switch"], [role="tab"], [role="menuitem"], [role="link"], [role="combobox"]';
|
|
160
|
+
return [...document.querySelectorAll(controls)]
|
|
161
|
+
.filter(
|
|
162
|
+
(el) => !clipped(el) && getComputedStyle(el).visibility !== "hidden" && getComputedStyle(el).display !== "none",
|
|
163
|
+
)
|
|
164
|
+
.filter((el) => !(el.matches("a") && getComputedStyle(el).display === "inline"))
|
|
165
|
+
.map((el) => ({ el, r: el.getBoundingClientRect() }))
|
|
166
|
+
.filter(({ r }) => r.width > 4 && r.height > 4 && (r.width < 44 || r.height < 44))
|
|
167
|
+
.map(({ el, r }) => nameOf(el) + " " + Math.round(r.width) + "x" + Math.round(r.height));
|
|
168
|
+
}
|
|
169
|
+
|
|
156
170
|
/** `overlaps`: two sections that are not nested and cover each other, or what ran out of its panel and lands on another section (the card covering « Dernières vérifications »). */
|
|
157
171
|
function overlapsOf(panels, spill) {
|
|
158
172
|
const overlaps = [];
|
|
@@ -426,6 +440,7 @@ function measurePage() {
|
|
|
426
440
|
cutColumns: cutColumnsOf(),
|
|
427
441
|
chromeOverlaps: chromeOverlapsOf(doc).slice(0, 3),
|
|
428
442
|
controlOverlaps: controlOverlapsOf().slice(0, 5),
|
|
443
|
+
smallTargets: smallTargetsOf().slice(0, 8),
|
|
429
444
|
clips: clipsOf(),
|
|
430
445
|
emptyHeadings: emptyHeadingsOf(),
|
|
431
446
|
unlabelledFiles: unlabelledFilesOf(),
|
|
@@ -463,6 +478,7 @@ const PROBES = [
|
|
|
463
478
|
spillOf,
|
|
464
479
|
seenBox,
|
|
465
480
|
controlOverlapsOf,
|
|
481
|
+
smallTargetsOf,
|
|
466
482
|
overlapsOf,
|
|
467
483
|
cutBy,
|
|
468
484
|
cutColumnsOf,
|
|
@@ -524,6 +540,11 @@ const FLAGGED_CHECKS = [
|
|
|
524
540
|
: [],
|
|
525
541
|
],
|
|
526
542
|
["maps", (where, result, maps) => mapProblems(where, result.maps ?? [], maps)],
|
|
543
|
+
[
|
|
544
|
+
"smallTargets",
|
|
545
|
+
(where, result) =>
|
|
546
|
+
result.smallTargets?.length ? [`${where}: touch target under 44 px (${result.smallTargets.join(", ")})`] : [],
|
|
547
|
+
],
|
|
527
548
|
[
|
|
528
549
|
"controlOverlaps",
|
|
529
550
|
(where, result) =>
|
package/src/self-test.mjs
CHANGED
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
MAP_NO_CANVAS,
|
|
22
22
|
SECTIONS_OVERLAP,
|
|
23
23
|
SMALL_ACTION,
|
|
24
|
+
SMALL_TARGET,
|
|
25
|
+
TARGETS_FINE,
|
|
24
26
|
TOKEN_IN_STRETCHED_ROW,
|
|
25
27
|
TOKEN_WRAPPED,
|
|
26
28
|
} from "./fixtures.mjs";
|
|
@@ -36,6 +38,7 @@ const EXPECT = [
|
|
|
36
38
|
["an empty <main>", EMPTY_MAIN, /empty <main>/, { emptyMain: true }],
|
|
37
39
|
["a frame that forces a scroll", FRAME_FORCES_SCROLL, /the frame forces a scroll/, { frame: true }],
|
|
38
40
|
["an action under the tap target", SMALL_ACTION, /an action is 24 px tall \(< 36\)/, { minAction: 36 }],
|
|
41
|
+
["a control under 44 px", SMALL_TARGET, /touch target under 44 px \(button\. 120x32\)/, { smallTargets: true }],
|
|
39
42
|
["a landmark wider than its box", BOX_TOO_WIDE, /content wider than its box/, { boxes: true }],
|
|
40
43
|
["a broken picture", BROKEN_PARTS, /broken picture/, { pictures: true }],
|
|
41
44
|
["a tile that draws nothing", BROKEN_PARTS, /empty tile/, { emptyControls: true }],
|
|
@@ -70,12 +73,14 @@ const ALL = {
|
|
|
70
73
|
landmarks: "public",
|
|
71
74
|
maps: true,
|
|
72
75
|
controlOverlaps: true,
|
|
76
|
+
smallTargets: true,
|
|
73
77
|
};
|
|
74
78
|
const FINES_STRICT = [
|
|
75
79
|
["a frame that fits its screen", FRAME_FITS, { frame: true, emptyMain: false }],
|
|
76
80
|
["the family chrome", CHROME_FINE, ALL],
|
|
77
81
|
["maps with a size and something drawn", MAP_FINE, { maps: true }],
|
|
78
82
|
["controls side by side, in a label, in a scroller", CONTROLS_FINE, { controlOverlaps: true }],
|
|
83
|
+
["controls of 44 px and an inline link", TARGETS_FINE, { smallTargets: true }],
|
|
79
84
|
["a map that is not drawn (display none)", MAP_HIDDEN, { maps: true }],
|
|
80
85
|
];
|
|
81
86
|
|