@krizaka/page-audit 0.0.0-stage → 0.2.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/LICENSE +201 -0
- package/README.md +19 -2
- package/package.json +64 -3
- package/src/cli.mjs +30 -0
- package/src/fixtures.mjs +29 -0
- package/src/index.d.ts +22 -0
- package/src/index.mjs +4 -0
- package/src/page-audit.mjs +287 -0
- package/src/run.mjs +96 -0
- package/src/self-test.mjs +39 -0
- package/src/settle.mjs +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @krizaka/page-audit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The page audit of every Krizaka app, in one place (ADR-013: one source per rule set). It measures a rendered page in a real browser:
|
|
4
|
+
horizontal overflow, a card out of its panel, sections covering each other, a column cut by a clipping ancestor, top chrome that
|
|
5
|
+
overlaps, content cut inside its box, a token wrapped per character, unnamed buttons, empty headings. Closed `<details>`, `aria-hidden`
|
|
6
|
+
layers, scrollers and fixed elements are not counted. Library code, not UI: it lives in krizaka-ts.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm i -D @krizaka/page-audit playwright-core
|
|
10
|
+
npx krizaka-page-audit --self-test # proves it on its own fixtures
|
|
11
|
+
npx krizaka-page-audit --base http://localhost:3000 --routes /en,/fr --widths 360,390,1440 --themes dark,light
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import { auditRoutes, auditContext, loadSettled, resizeSettled, auditPage, problemsOf } from "@krizaka/page-audit";
|
|
16
|
+
const problems = await auditRoutes({ base, routes: ["/en", "/fr"], checks: { h1: true } }); // [] when fine
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`auditContext` / `loadSettled` / `resizeSettled` open a context with reduced motion and no View Transition, and wait for none to run
|
|
20
|
+
before anything is measured (yomizaka#354). `prepare(page, route)` signs in or seeds; `launch` gives your own browser.
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krizaka/page-audit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The page audit of every Krizaka app, in one place: 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
|
+
"keywords": [
|
|
6
|
+
"krizaka",
|
|
7
|
+
"audit",
|
|
8
|
+
"overflow",
|
|
9
|
+
"layout",
|
|
10
|
+
"playwright"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://ts.krizaka.com/page-audit",
|
|
13
|
+
"bugs": "https://github.com/krizaka/krizaka-ts/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/krizaka/krizaka-ts.git",
|
|
17
|
+
"directory": "packages/page-audit"
|
|
18
|
+
},
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"author": "Krizaka (https://www.krizaka.com)",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./src/index.mjs",
|
|
23
|
+
"types": "./src/index.d.ts",
|
|
24
|
+
"bin": {
|
|
25
|
+
"krizaka-page-audit": "./src/cli.mjs"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./src/index.d.ts",
|
|
30
|
+
"import": "./src/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./settle": {
|
|
33
|
+
"types": "./src/index.d.ts",
|
|
34
|
+
"import": "./src/settle.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./fixtures": "./src/fixtures.mjs",
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"playwright-core": ">=1.40"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.10.0",
|
|
50
|
+
"eslint": "^9.39.0",
|
|
51
|
+
"playwright-core": "^1.55.0",
|
|
52
|
+
"vitest": "^4.1.11",
|
|
53
|
+
"@krizaka/config": "^0.13.0"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=22"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"lint": "eslint . --max-warnings 0",
|
|
63
|
+
"typecheck": "node --check src/index.mjs",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"check": "pnpm run lint && pnpm run test"
|
|
66
|
+
}
|
|
6
67
|
}
|
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// krizaka-page-audit --base http://localhost:3000 --routes /en,/fr [--widths 360,390,1440] [--themes dark,light]
|
|
3
|
+
// [--theme-key kz-theme] [--h1] [--shots dir] | krizaka-page-audit --self-test
|
|
4
|
+
import { auditRoutes, THEMES, WIDTHS } from "./run.mjs";
|
|
5
|
+
import { selfTest } from "./self-test.mjs";
|
|
6
|
+
|
|
7
|
+
const arg = (name, fallback) => {
|
|
8
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
9
|
+
return i >= 0 ? process.argv[i + 1] : fallback;
|
|
10
|
+
};
|
|
11
|
+
const list = (value, fallback) => (value ? value.split(",").filter(Boolean) : fallback);
|
|
12
|
+
|
|
13
|
+
if (process.argv.includes("--self-test")) {
|
|
14
|
+
const failures = await selfTest();
|
|
15
|
+
if (failures.length) {
|
|
16
|
+
console.error(`page-audit self-test failed:\n ${failures.join("\n ")}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
console.log("page-audit self-test: 4 broken layouts seen, the fine ones clean");
|
|
20
|
+
} else {
|
|
21
|
+
const routes = list(arg("routes"), ["/"]);
|
|
22
|
+
const widths = list(arg("widths"), WIDTHS).map(Number);
|
|
23
|
+
const themes = list(arg("themes"), THEMES);
|
|
24
|
+
const problems = await auditRoutes({ base: arg("base", "http://localhost:3000"), routes, widths, themes, themeKey: arg("theme-key", "kz-theme"), shots: arg("shots"), checks: { h1: process.argv.includes("--h1") } });
|
|
25
|
+
if (problems.length) {
|
|
26
|
+
console.error(`${problems.length} page problem(s):\n ${problems.join("\n ")}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
console.log(`no page problem: ${routes.length} routes x ${widths.length} widths x ${themes.length} themes`);
|
|
30
|
+
}
|
package/src/fixtures.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Small pages that reproduce what the layout audit must catch (yomizaka#435) and one that is fine, for `check-page-audit.mjs`:
|
|
2
|
+
// the guard is proven on its own fixtures before it is trusted on the app.
|
|
3
|
+
|
|
4
|
+
const page = (body, css = "") => `<!doctype html><html><head><meta charset="utf-8"><style>*{box-sizing:border-box}body{margin:0;font:16px sans-serif}${css}</style></head><body><main>${body}</main></body></html>`;
|
|
5
|
+
|
|
6
|
+
/** The binder as it was: the open folder's card is as tall as its grid row (a fixed height) and runs over the next section. */
|
|
7
|
+
export const CARD_OVER_NEXT = page(
|
|
8
|
+
`<section data-testid="binder" style="height:200px"><h2>Le classeur</h2><div data-testid="collection-card" style="height:500px">Mes documents · 0 fichiers</div></section><section data-testid="latest-checks"><h2>Dernières vérifications</h2></section>`,
|
|
9
|
+
"section{display:block}",
|
|
10
|
+
);
|
|
11
|
+
/** Two sections laid out on top of each other. */
|
|
12
|
+
export const SECTIONS_OVERLAP = page(`<section data-testid="a" style="height:100px">A</section><section data-testid="b" style="margin-top:-60px;height:100px;position:relative">B</section>`);
|
|
13
|
+
/** A two-column layout whose wrapper clips the right column. */
|
|
14
|
+
export const COLUMN_CUT = page(
|
|
15
|
+
`<div style="overflow:hidden;width:600px"><div style="display:grid;grid-template-columns:400px 400px"><section data-testid="main">Main</section><aside data-testid="activity"><section data-testid="activity-figures">Activité</section></aside></div></div>`,
|
|
16
|
+
);
|
|
17
|
+
/** What it should be: the card follows its content, the columns fit, a wide table scrolls inside its own scroller. */
|
|
18
|
+
export const FINE = page(
|
|
19
|
+
`<div style="display:grid;grid-template-columns:minmax(0,1fr) 320px;gap:16px"><section data-testid="binder"><h2>Le classeur</h2><div data-testid="collection-card">Mes documents · 0 fichiers</div></section><aside><section data-testid="activity">Activité</section></aside></div><section data-testid="latest-checks"><h2>Dernières vérifications</h2><div style="overflow:auto;width:300px"><div style="width:900px">table</div></div></section>`,
|
|
20
|
+
);
|
|
21
|
+
/** Not drawn, so not a problem: a chart's text version in a visually hidden wrapper, and the content of a folded `<details>` (the browser still gives both a box). */
|
|
22
|
+
export const HIDDEN_CONTENT = page(
|
|
23
|
+
`<section data-testid="activity" style="height:120px"><h2>Activité</h2><div style="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)"><table><tbody>${"<tr><td>21 oct.</td><td>7</td></tr>".repeat(40)}</tbody></table></div></section><section data-testid="report"><details><summary>Détails</summary><div style="height:400px">Texte du rapport</div></details></section>`,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/** The report tab: a section inside a folded details (the closing note) beside sections it must not be taken to cover. */
|
|
27
|
+
export const FOLDED_SECTION = page(
|
|
28
|
+
`<div style="display:flex;flex-direction:column"><section data-testid="facts" style="height:80px">Faits</section><details><summary>Détails</summary><section data-testid="closing-note" style="padding:16px">Ce que nous avons vérifié</section></details><section data-testid="other" style="height:80px">Autres</section></div>`,
|
|
29
|
+
);
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* Minimal structural types: playwright-core is a peer dependency, not imported here. */
|
|
2
|
+
export type Page = Record<string, unknown>;
|
|
3
|
+
export type BrowserContext = Record<string, unknown>;
|
|
4
|
+
export type Browser = { newContext(o?: object): Promise<BrowserContext>; close(): Promise<void> };
|
|
5
|
+
export const auditPage: string;
|
|
6
|
+
export interface ProblemChecks { errors?: string[]; h1?: boolean; headerAction?: boolean; fileLabels?: boolean }
|
|
7
|
+
export function problemsOf(where: string, result: Record<string, unknown>, checks?: ProblemChecks): string[];
|
|
8
|
+
export function auditOptions<T extends object>(options?: T): T & { reducedMotion: "reduce" };
|
|
9
|
+
export function withoutViewTransitions(): void;
|
|
10
|
+
export function auditContext(browser: { newContext(o?: object): Promise<BrowserContext> }, options?: object): Promise<BrowserContext>;
|
|
11
|
+
export function settled(page: Page): Promise<unknown>;
|
|
12
|
+
export function loadSettled(page: Page, url: string, options?: object): Promise<BrowserContext>;
|
|
13
|
+
export function resizeSettled(page: Page, size: { width: number; height: number }): Promise<void>;
|
|
14
|
+
export const WIDTHS: number[];
|
|
15
|
+
export const THEMES: string[];
|
|
16
|
+
export function isPageError(message: { type(): string; text(): string }): boolean;
|
|
17
|
+
export interface AuditRoutesOptions {
|
|
18
|
+
base: string; routes: string[]; widths?: number[]; themes?: string[]; height?: number; themeKey?: string; shots?: string; settleMs?: number;
|
|
19
|
+
checks?: Omit<ProblemChecks, "errors">; prepare?: (page: Page, route: string) => Promise<void>; launch?: () => Promise<BrowserContext>;
|
|
20
|
+
}
|
|
21
|
+
export function auditRoutes(options: AuditRoutesOptions): Promise<string[]>;
|
|
22
|
+
export function selfTest(options?: { launch?: () => Promise<BrowserContext> }): Promise<string[]>;
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { auditPage, problemsOf } from "./page-audit.mjs";
|
|
2
|
+
export { auditRoutes, isPageError, THEMES,WIDTHS } from "./run.mjs";
|
|
3
|
+
export { selfTest } from "./self-test.mjs";
|
|
4
|
+
export { auditContext, auditOptions, loadSettled, resizeSettled,settled, withoutViewTransitions } from "./settle.mjs";
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// What a rendered page is measured on, in a real browser (Playwright `page.evaluate(auditPage)`), and what counts as a problem.
|
|
2
|
+
// Shared by the responsive guard of the public pages (check-overflow.mjs) and the signed-in pages' check (check-app-pages.mjs).
|
|
3
|
+
|
|
4
|
+
// The probes below run in the page, so each uses only the browser's globals and the other probes (all of them are serialised together
|
|
5
|
+
// into `auditPage`). They are small on purpose: one measure each, proven on its own fixture (check-page-audit.mjs).
|
|
6
|
+
|
|
7
|
+
const ARIA_HIDDEN = '[aria-hidden="true"]';
|
|
8
|
+
const className = (el, n) => String(el.className).split(" ").filter(Boolean).slice(0, n).join(".");
|
|
9
|
+
const nameOf = (el) => {
|
|
10
|
+
const id = el.dataset?.testid;
|
|
11
|
+
return el.tagName.toLowerCase() + (id ? "[" + id + "]" : "") + "." + className(el, 2);
|
|
12
|
+
};
|
|
13
|
+
const scrolls = (el) => ["auto", "scroll"].includes(getComputedStyle(el).overflowY) || ["auto", "scroll"].includes(getComputedStyle(el).overflowX);
|
|
14
|
+
const meets = (ra, rb) => Math.min(ra.right, rb.right) - Math.max(ra.left, rb.left) > 2 && Math.min(ra.bottom, rb.bottom) - Math.max(ra.top, rb.top) > 2;
|
|
15
|
+
const apart = (a, b) => !a.contains(b) && !b.contains(a);
|
|
16
|
+
|
|
17
|
+
/** An element that pokes out only matters when nothing clips it: decorative layers (aria-hidden) and anything inside a clipping or scrolling ancestor are meant to extend. */
|
|
18
|
+
function clipped(el) {
|
|
19
|
+
for (let n = el; n && n !== document.body; n = n.parentElement) {
|
|
20
|
+
if (n.getAttribute("aria-hidden") === "true") return true;
|
|
21
|
+
if (n !== el && ["hidden", "clip", "auto", "scroll"].includes(getComputedStyle(n).overflowX)) return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function wideOf(doc) {
|
|
27
|
+
return [...document.querySelectorAll("body *")]
|
|
28
|
+
.filter((el) => {
|
|
29
|
+
const r = el.getBoundingClientRect();
|
|
30
|
+
return r.width > 0 && (r.right > doc.clientWidth + 1 || r.left < -1) && !clipped(el);
|
|
31
|
+
})
|
|
32
|
+
.slice(0, 3)
|
|
33
|
+
.map((el) => `${el.tagName.toLowerCase()}.${String(el.className).split(" ").slice(0, 3).join(".")}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A button's accessible name: its text, aria-label, aria-labelledby, title — or a <label for> pointing at it (a checkbox, a switch). */
|
|
37
|
+
function named(b) {
|
|
38
|
+
const labelled = !!b.id && !!document.querySelector(`label[for="${CSS.escape(b.id)}"]`);
|
|
39
|
+
return !!((b.textContent || "").trim() || b.getAttribute("aria-label") || b.getAttribute("aria-labelledby") || b.title || labelled);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function unnamedOf() {
|
|
43
|
+
const unnamed = [...document.querySelectorAll("button")].filter((b) => !named(b));
|
|
44
|
+
return { unnamedButtons: unnamed.length, unnamedSamples: unnamed.slice(0, 2).map((b) => b.outerHTML.slice(0, 160).replace(/\s+/g, " ")) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function headerActionOf(doc) {
|
|
48
|
+
const action = document.querySelector('[data-testid="header-check"]');
|
|
49
|
+
if (!action) return null;
|
|
50
|
+
const box = action.getBoundingClientRect();
|
|
51
|
+
const visible = box.width > 0 && box.height > 0 && box.left >= 0 && box.right <= doc.clientWidth + 1 && box.top >= 0;
|
|
52
|
+
return { visible, named: !!(action.getAttribute("aria-label") || action.textContent || "").trim() };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** What a folded `<details>` holds is not drawn, though the browser still gives it a box (its summary is). */
|
|
56
|
+
function folded(el) {
|
|
57
|
+
return !!el.closest("details:not([open])") && !el.closest("summary");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Whether an ancestor between the element and the panel keeps what runs out of it: a scroller, or a visually hidden wrapper (`sr-only`: a 1 px clipped box, the text version of a chart). */
|
|
61
|
+
function keptBetween(el, panel) {
|
|
62
|
+
for (let n = el.parentElement; n && n !== panel; n = n.parentElement) {
|
|
63
|
+
if (scrolls(n)) return true;
|
|
64
|
+
const nb = n.getBoundingClientRect();
|
|
65
|
+
if ((nb.width <= 2 || nb.height <= 2) && getComputedStyle(n).overflowY !== "visible") return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function notDrawn(el, r) {
|
|
71
|
+
return r.width === 0 || r.height === 0 || getComputedStyle(el).position === "fixed" || !!el.closest(ARIA_HIDDEN) || !!el.closest("[data-radix-popper-content-wrapper]") || folded(el);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function runsOut(el, panel, box) {
|
|
75
|
+
const r = el.getBoundingClientRect();
|
|
76
|
+
if (notDrawn(el, r) || keptBetween(el, panel)) return false;
|
|
77
|
+
return r.bottom > box.bottom + 1.5 || r.right > box.right + 1.5;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** `overflowing`: a panel's content that runs out of the panel (a card taller than its panel, over the next section). `spill` holds those elements. */
|
|
81
|
+
function spillOf(panels) {
|
|
82
|
+
const overflowing = [];
|
|
83
|
+
const spill = [];
|
|
84
|
+
for (const panel of panels) {
|
|
85
|
+
if (scrolls(panel) || ["hidden", "clip"].includes(getComputedStyle(panel).overflowY)) continue;
|
|
86
|
+
const box = panel.getBoundingClientRect();
|
|
87
|
+
const out = [...panel.querySelectorAll("*")].find((el) => runsOut(el, panel, box));
|
|
88
|
+
if (!out) continue;
|
|
89
|
+
overflowing.push(`${nameOf(out)} out of ${nameOf(panel)}`);
|
|
90
|
+
spill.push(out);
|
|
91
|
+
}
|
|
92
|
+
return { overflowing, spill };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** `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 »). */
|
|
96
|
+
function overlapsOf(panels, spill) {
|
|
97
|
+
const overlaps = [];
|
|
98
|
+
for (const el of spill) {
|
|
99
|
+
for (const other of panels) if (apart(el, other) && meets(el.getBoundingClientRect(), other.getBoundingClientRect())) overlaps.push(`${nameOf(el)} over ${nameOf(other)}`);
|
|
100
|
+
}
|
|
101
|
+
panels.forEach((a, i) => {
|
|
102
|
+
for (const b of panels.slice(i + 1)) if (apart(a, b) && meets(a.getBoundingClientRect(), b.getBoundingClientRect())) overlaps.push(`${nameOf(a)} over ${nameOf(b)}`);
|
|
103
|
+
});
|
|
104
|
+
return overlaps;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The clipping ancestor that cuts an element sideways (overflow hidden / clip), or null; a scroller stops the search (it keeps what runs out of it). */
|
|
108
|
+
function cutBy(el, r) {
|
|
109
|
+
for (let n = el.parentElement; n && n !== document.documentElement; n = n.parentElement) {
|
|
110
|
+
const style = getComputedStyle(n);
|
|
111
|
+
if (["auto", "scroll"].includes(style.overflowX)) return null;
|
|
112
|
+
if (!["hidden", "clip"].includes(style.overflowX)) continue;
|
|
113
|
+
const c = n.getBoundingClientRect();
|
|
114
|
+
return r.right > c.right + 2 || r.left < c.left - 2 ? n : null;
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** `cutColumns`: a section or a column cut by a clipping ancestor, which hides part of its content. */
|
|
120
|
+
function cutColumnsOf() {
|
|
121
|
+
const cut = [];
|
|
122
|
+
for (const el of document.querySelectorAll("main section, main aside, main [data-testid], [data-panel]")) {
|
|
123
|
+
const r = el.getBoundingClientRect();
|
|
124
|
+
if (el.closest(ARIA_HIDDEN) || r.width === 0 || r.height === 0) continue;
|
|
125
|
+
const by = cutBy(el, r);
|
|
126
|
+
if (by) cut.push(`${nameOf(el)} cut by ${nameOf(by)}`);
|
|
127
|
+
}
|
|
128
|
+
return [...new Set(cut)].slice(0, 3);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The top chrome never overlaps (yomizaka#449): the in-flow blocks above the page (`[data-top-chrome]`, e.g. the development-version notice) and a bar that is fixed or sticky at the top of the viewport. Two of them that share pixels hide one another. */
|
|
132
|
+
function topBoxOf(el) {
|
|
133
|
+
return el.getBoundingClientRect().height === 0 && el.firstElementChild ? el.firstElementChild : el;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A bar is whatever is fixed or sticky across the top of the viewport (a wrapper, whatever its tag): wide, short, near the top. The site's bar stands in a sticky wrapper of zero height, so what it holds is measured. */
|
|
137
|
+
function isTopBar(el, width) {
|
|
138
|
+
const pos = getComputedStyle(el).position;
|
|
139
|
+
if (pos !== "fixed" && pos !== "sticky") return false;
|
|
140
|
+
const r = topBoxOf(el).getBoundingClientRect();
|
|
141
|
+
return r.width > width * 0.5 && r.height > 8 && r.height < 200 && r.top < 160 && r.bottom > 0 && !el.closest("[data-top-chrome]");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function chromeOverlapsOf(doc) {
|
|
145
|
+
const chrome = [...document.querySelectorAll("[data-top-chrome]")].filter((el) => el.getBoundingClientRect().height > 0);
|
|
146
|
+
const bars = [...document.querySelectorAll("body *")].filter((el) => isTopBar(el, doc.clientWidth)).map(topBoxOf);
|
|
147
|
+
const stack = [...chrome, ...bars];
|
|
148
|
+
const found = [];
|
|
149
|
+
stack.forEach((a, i) => {
|
|
150
|
+
for (const b of stack.slice(i + 1)) if (apart(a, b) && meets(a.getBoundingClientRect(), b.getBoundingClientRect())) found.push(`${nameOf(a)} / ${nameOf(b)}`);
|
|
151
|
+
});
|
|
152
|
+
return found;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** « Never overflows »: a control or a card that clips its own content (overflow hidden / clip with more content than room) cuts a word. */
|
|
156
|
+
function clipsOf() {
|
|
157
|
+
return [...document.querySelectorAll("button, a, [role=button], [data-testid], [class*=badge], [class*=chip]")]
|
|
158
|
+
.filter((el) => {
|
|
159
|
+
const r = el.getBoundingClientRect();
|
|
160
|
+
const style = getComputedStyle(el);
|
|
161
|
+
return r.width > 4 && r.height > 4 && ["hidden", "clip"].includes(style.overflowX) && style.textOverflow !== "ellipsis" && el.scrollWidth > el.clientWidth + 1 && !clipped(el);
|
|
162
|
+
})
|
|
163
|
+
.slice(0, 3)
|
|
164
|
+
.map(nameOf);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** A long token (an id, an address) that wraps character by character: a cell taller than two lines for text without a space. */
|
|
168
|
+
function tooTall(el) {
|
|
169
|
+
const text = (el.textContent || "").trim();
|
|
170
|
+
if (text.length < 12 || /\s/.test(text) || el.children.length > 1) return false;
|
|
171
|
+
const cs = getComputedStyle(el);
|
|
172
|
+
const lh = Number.parseFloat(cs.lineHeight) || Number.parseFloat(cs.fontSize) * 1.4;
|
|
173
|
+
const content = el.getBoundingClientRect().height - Number.parseFloat(cs.paddingTop) - Number.parseFloat(cs.paddingBottom);
|
|
174
|
+
return content > lh * 2.5;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function wrappedOf() {
|
|
178
|
+
return [...document.querySelectorAll("td, th, code, [role=cell]")]
|
|
179
|
+
.filter(tooTall)
|
|
180
|
+
.slice(0, 2)
|
|
181
|
+
.map((el) => (el.textContent || "").trim().slice(0, 24));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The whole measure of a page. Decorative layers (aria-hidden), fixed elements and anything inside a scroller are left out of the layout probes (yomizaka#435). */
|
|
185
|
+
/** A heading with no text (and no image or labelled icon) says nothing to a screen reader. */
|
|
186
|
+
function emptyHeadingsOf() {
|
|
187
|
+
return [...document.querySelectorAll("h1, h2, h3")].filter((h) => !(h.textContent || "").trim() && !h.querySelector("img, svg[aria-label]")).length;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** A file input that no label, `aria-label` or title names. */
|
|
191
|
+
function unlabelledFilesOf() {
|
|
192
|
+
return [...document.querySelectorAll("input[type=file]")].filter((i) => !(i.getAttribute("aria-label") || i.getAttribute("aria-labelledby") || i.title || i.labels?.length)).length;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function measurePage() {
|
|
196
|
+
const doc = document.documentElement;
|
|
197
|
+
const panels = [...document.querySelectorAll("[data-panel], main section, main [role=region]")].filter((el) => !el.closest(ARIA_HIDDEN) && !folded(el));
|
|
198
|
+
const { overflowing, spill } = spillOf(panels);
|
|
199
|
+
const chips = [...document.querySelectorAll('[data-testid="audience-picker"] a')].map((a) => Math.round(a.getBoundingClientRect().height));
|
|
200
|
+
return {
|
|
201
|
+
h1: document.querySelectorAll("h1").length,
|
|
202
|
+
scrollWidth: doc.scrollWidth,
|
|
203
|
+
clientWidth: doc.clientWidth,
|
|
204
|
+
wide: wideOf(doc),
|
|
205
|
+
...unnamedOf(),
|
|
206
|
+
headerAction: headerActionOf(doc),
|
|
207
|
+
chips,
|
|
208
|
+
overflowing: overflowing.slice(0, 3),
|
|
209
|
+
overlaps: overlapsOf(panels, spill).slice(0, 3),
|
|
210
|
+
cutColumns: cutColumnsOf(),
|
|
211
|
+
chromeOverlaps: chromeOverlapsOf(doc).slice(0, 3),
|
|
212
|
+
clips: clipsOf(),
|
|
213
|
+
emptyHeadings: emptyHeadingsOf(),
|
|
214
|
+
unlabelledFiles: unlabelledFilesOf(),
|
|
215
|
+
wrapped: wrappedOf(),
|
|
216
|
+
segmentError: !!document.querySelector('[data-testid="segment-error"]'),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const PROBES = [tooTall, wrappedOf, className, nameOf, scrolls, meets, apart, clipped, wideOf, named, unnamedOf, headerActionOf, folded, keptBetween, notDrawn, runsOut, spillOf, overlapsOf, cutBy, cutColumnsOf, topBoxOf, isTopBar, chromeOverlapsOf, clipsOf, emptyHeadingsOf, unlabelledFilesOf, measurePage];
|
|
221
|
+
|
|
222
|
+
/** The expression Playwright runs in the page (`page.evaluate(auditPage)`): the probes, serialised together, then the measure. */
|
|
223
|
+
export const auditPage = `(() => {\nconst ARIA_HIDDEN = ${JSON.stringify(ARIA_HIDDEN)};\n${PROBES.map((f) => `const ${f.name} = ${f.toString()};`).join("\n")}\nreturn measurePage();\n})()`;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The problems of one page × width × theme, in words: console errors, a horizontal overflow (or elements past the edge),
|
|
227
|
+
* not exactly one h1 (when asked), unnamed buttons, the header's action off screen or unnamed (when the page has one).
|
|
228
|
+
*/
|
|
229
|
+
/** Empty headings; file inputs without a label (opt-in until `Dropzone` of @krizaka/ui names its hidden input, a prop of the package). */
|
|
230
|
+
function accessibilityProblems(where, result, fileLabels) {
|
|
231
|
+
const problems = [];
|
|
232
|
+
if (result.emptyHeadings) problems.push(`${where}: ${result.emptyHeadings} empty heading(s)`);
|
|
233
|
+
if (fileLabels && result.unlabelledFiles) problems.push(`${where}: ${result.unlabelledFiles} file input(s) without a label`);
|
|
234
|
+
return problems;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function problemsOf(where, result, { errors = [], h1 = false, headerAction = false, fileLabels = false } = {}) {
|
|
238
|
+
return [
|
|
239
|
+
...errorsOf(where, errors),
|
|
240
|
+
...layoutProblems(where, result),
|
|
241
|
+
...(h1 ? namingProblems(where, result) : []),
|
|
242
|
+
...(headerAction ? headerActionProblems(where, result.headerAction) : []),
|
|
243
|
+
...chipProblems(where, result.chips ?? []),
|
|
244
|
+
...accessibilityProblems(where, result, fileLabels),
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function errorsOf(where, errors) {
|
|
249
|
+
return errors.length ? [`${where}: console error — ${errors[0]}`] : [];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Overflow, elements past the edge, boxes that cover or cut one another, a token wrapped per character, the error state. */
|
|
253
|
+
function layoutProblems(where, result) {
|
|
254
|
+
const problems = [];
|
|
255
|
+
if (result.scrollWidth > result.clientWidth) problems.push(`${where}: scrollWidth ${result.scrollWidth} > ${result.clientWidth} (${result.wide.join(", ")})`);
|
|
256
|
+
else if (result.wide.length) problems.push(`${where}: elements past the edge (${result.wide.join(", ")})`);
|
|
257
|
+
const lists = [[result.overflowing, "overflows its panel"], [result.overlaps, "covers a neighbouring section"], [result.cutColumns, "is cut off"]];
|
|
258
|
+
for (const [list, words] of lists) {
|
|
259
|
+
if (list?.length) problems.push(`${where}: ${words} (${list.join(", ")})`);
|
|
260
|
+
}
|
|
261
|
+
if (result.wrapped?.length) problems.push(`${where}: a token wraps one character per line (${result.wrapped.join(", ")}) — truncate it`);
|
|
262
|
+
if (result.segmentError) problems.push(`${where}: the page rendered its error state (segment-error), e.g. React #441`);
|
|
263
|
+
if (result.chromeOverlaps?.length) problems.push(`${where}: the top chrome chromeOverlaps (${result.chromeOverlaps.slice(0, 2).join(", ")})`);
|
|
264
|
+
if (result.clips?.length) problems.push(`${where}: content cut inside its box (${result.clips.join(", ")})`);
|
|
265
|
+
return problems;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Exactly one h1 and every button named. */
|
|
269
|
+
function namingProblems(where, result) {
|
|
270
|
+
const problems = [];
|
|
271
|
+
if (result.h1 !== 1) problems.push(`${where}: ${result.h1} h1 (expected exactly one)`);
|
|
272
|
+
if (result.unnamedButtons > 0) {
|
|
273
|
+
const samples = (result.unnamedSamples ?? []).join(" | ");
|
|
274
|
+
problems.push(`${where}: ${result.unnamedButtons} unnamed button(s) ${samples}`.trimEnd());
|
|
275
|
+
}
|
|
276
|
+
return problems;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function headerActionProblems(where, action) {
|
|
280
|
+
if (!action) return [`${where}: no header action`];
|
|
281
|
+
if (!action.visible) return [`${where}: the header's action is off screen`];
|
|
282
|
+
return action.named ? [] : [`${where}: the header's action has no accessible name`];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function chipProblems(where, chips) {
|
|
286
|
+
return chips.some((h) => h < 44) ? [`${where}: a chip is ${Math.min(...chips)} px tall (< 44)`] : [];
|
|
287
|
+
}
|
package/src/run.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The audit over a route list: every route × viewport width × theme, in a real browser, the problems in words.
|
|
2
|
+
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
import { auditPage, problemsOf } from "./page-audit.mjs";
|
|
6
|
+
import { auditContext, loadSettled, resizeSettled } from "./settle.mjs";
|
|
7
|
+
|
|
8
|
+
export const WIDTHS = [360, 390, 430, 768, 1024, 1440];
|
|
9
|
+
export const THEMES = ["dark", "light"];
|
|
10
|
+
|
|
11
|
+
/** A blocked third-party resource is not a page error; a script error and a hydration mismatch are. */
|
|
12
|
+
export const isPageError = (message) => message.type() === "error" && !/Failed to load resource/.test(message.text());
|
|
13
|
+
|
|
14
|
+
async function chromiumOf(launch) {
|
|
15
|
+
if (launch) return launch();
|
|
16
|
+
const { chromium } = await import("playwright-core");
|
|
17
|
+
return chromium.launch();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Persists the theme the way the apps do, before any page script runs. */
|
|
21
|
+
function rememberTheme([key, value]) {
|
|
22
|
+
try {
|
|
23
|
+
localStorage.setItem(key, value);
|
|
24
|
+
} catch {
|
|
25
|
+
// storage blocked: the colour scheme is still emulated
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The page's console errors and uncaught exceptions, read and cleared by `take()`. */
|
|
30
|
+
function collectErrors(page) {
|
|
31
|
+
let errors = [];
|
|
32
|
+
page.on("console", (m) => {
|
|
33
|
+
if (isPageError(m)) errors.push(m.text().slice(0, 140));
|
|
34
|
+
});
|
|
35
|
+
page.on("pageerror", (e) => errors.push(String(e).slice(0, 140)));
|
|
36
|
+
return {
|
|
37
|
+
take() {
|
|
38
|
+
const seen = errors;
|
|
39
|
+
errors = [];
|
|
40
|
+
return seen;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** One route at one width: load, settle, measure, screenshot. */
|
|
46
|
+
async function measure(page, { base, route, width, height, settleMs, prepare, checks, errors, where, shots }) {
|
|
47
|
+
await resizeSettled(page, { width, height });
|
|
48
|
+
// « load » and the faces, not « networkidle »: router prefetches can keep the page from ever going idle.
|
|
49
|
+
await loadSettled(page, `${base}${route}`);
|
|
50
|
+
if (prepare) await prepare(page, route);
|
|
51
|
+
if (settleMs) await page.waitForTimeout(settleMs);
|
|
52
|
+
const result = await page.evaluate(auditPage);
|
|
53
|
+
if (shots) {
|
|
54
|
+
mkdirSync(shots, { recursive: true });
|
|
55
|
+
await page.screenshot({ path: join(shots, `${where.replace(/[/?=&@ ]/g, "_")}.png`) });
|
|
56
|
+
}
|
|
57
|
+
return problemsOf(where, result, { ...checks, errors: errors.take() });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {object} o
|
|
62
|
+
* @param {string} o.base origin of the running app
|
|
63
|
+
* @param {string[]} o.routes paths to audit
|
|
64
|
+
* @param {number[]} [o.widths] viewport widths (default 360 to 1440)
|
|
65
|
+
* @param {string[]} [o.themes] "dark" | "light" (default both): emulated colour scheme and, when `themeKey` is set, localStorage
|
|
66
|
+
* @param {number} [o.height] viewport height (default 900)
|
|
67
|
+
* @param {string} [o.themeKey] localStorage key the app persists its theme in (default "kz-theme")
|
|
68
|
+
* @param {string} [o.shots] directory for one screenshot per route × width × theme
|
|
69
|
+
* @param {number} [o.settleMs] pause after load, for late layout (default 300)
|
|
70
|
+
* @param {object} [o.checks] options of `problemsOf` (h1, headerAction, fileLabels)
|
|
71
|
+
* @param {(page: object, route: string) => Promise<void>} [o.prepare] before each route is measured (sign in, seed)
|
|
72
|
+
* @param {() => Promise<object>} [o.launch] returns a Playwright browser (default: chromium of playwright-core)
|
|
73
|
+
* @returns {Promise<string[]>} the problems, empty when the pages are fine
|
|
74
|
+
*/
|
|
75
|
+
export async function auditRoutes({ base, routes, widths = WIDTHS, themes = THEMES, height = 900, themeKey = "kz-theme", shots, settleMs = 300, checks = {}, prepare, launch }) {
|
|
76
|
+
const browser = await chromiumOf(launch);
|
|
77
|
+
const problems = [];
|
|
78
|
+
try {
|
|
79
|
+
for (const theme of themes) {
|
|
80
|
+
const context = await auditContext(browser, { colorScheme: theme });
|
|
81
|
+
if (themeKey) await context.addInitScript(rememberTheme, [themeKey, theme]);
|
|
82
|
+
const page = await context.newPage();
|
|
83
|
+
const errors = collectErrors(page);
|
|
84
|
+
for (const route of routes) {
|
|
85
|
+
for (const width of widths) {
|
|
86
|
+
const where = `${route} @${width} ${theme}`;
|
|
87
|
+
problems.push(...(await measure(page, { base, route, width, height, settleMs, prepare, checks, errors, where, shots })));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
await context.close();
|
|
91
|
+
}
|
|
92
|
+
} finally {
|
|
93
|
+
await browser.close();
|
|
94
|
+
}
|
|
95
|
+
return problems;
|
|
96
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The audit proven on its own fixtures, in a real browser: each broken fixture must be reported, the fine ones must not.
|
|
2
|
+
// A guard that stopped seeing is itself a red build.
|
|
3
|
+
import { CARD_OVER_NEXT, COLUMN_CUT, FINE, FOLDED_SECTION, HIDDEN_CONTENT, SECTIONS_OVERLAP } from "./fixtures.mjs";
|
|
4
|
+
import { auditPage, problemsOf } from "./page-audit.mjs";
|
|
5
|
+
import { auditContext } from "./settle.mjs";
|
|
6
|
+
|
|
7
|
+
const EXPECT = [
|
|
8
|
+
["a card taller than its panel", CARD_OVER_NEXT, /overflows its panel/],
|
|
9
|
+
["a card over the next section", CARD_OVER_NEXT, /covers a neighbouring section/],
|
|
10
|
+
["two sections on top of each other", SECTIONS_OVERLAP, /covers a neighbouring section/],
|
|
11
|
+
["a column cut by a clipping wrapper", COLUMN_CUT, /is cut off/],
|
|
12
|
+
];
|
|
13
|
+
const FINES = [
|
|
14
|
+
["a fine layout", FINE],
|
|
15
|
+
["content that is not drawn (a visually hidden table, a folded details)", HIDDEN_CONTENT],
|
|
16
|
+
["a section folded in a details", FOLDED_SECTION],
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/** @returns {Promise<string[]>} the failures (empty when the audit sees what it must and nothing else) */
|
|
20
|
+
export async function selfTest({ launch } = {}) {
|
|
21
|
+
const browser = launch ? await launch() : await (await import("playwright-core")).chromium.launch();
|
|
22
|
+
const failures = [];
|
|
23
|
+
try {
|
|
24
|
+
const page = await (await auditContext(browser, { viewport: { width: 1280, height: 800 } })).newPage();
|
|
25
|
+
for (const [name, html, pattern] of EXPECT) {
|
|
26
|
+
await page.setContent(html);
|
|
27
|
+
const problems = problemsOf("fixture", await page.evaluate(auditPage));
|
|
28
|
+
if (!problems.some((p) => pattern.test(p))) failures.push(`the audit does not see ${name}: ${problems.join(" | ") || "no problem reported"}`);
|
|
29
|
+
}
|
|
30
|
+
for (const [name, html] of FINES) {
|
|
31
|
+
await page.setContent(html);
|
|
32
|
+
const fine = problemsOf("fixture", await page.evaluate(auditPage));
|
|
33
|
+
if (fine.length) failures.push(`the audit reports ${name}: ${fine.join(" | ")}`);
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
await browser.close();
|
|
37
|
+
}
|
|
38
|
+
return failures;
|
|
39
|
+
}
|
package/src/settle.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// One way for every browser audit to measure (yomizaka#354): never while a View Transition is swapping the page.
|
|
2
|
+
//
|
|
3
|
+
// The flake: the page was read while a transition was running (« Viewport size changed », 0 of 2 h1). The cure is the
|
|
4
|
+
// same everywhere, so it lives here and nowhere else: the context emulates reduced motion (the app honours it, the page
|
|
5
|
+
// change is instant — motion.css of @krizaka/ui) and every load or resize waits, explicitly, until no transition is
|
|
6
|
+
// active. No retry, no sleep standing in for a condition. `tests/browser-audits.test.mjs` fails a script that
|
|
7
|
+
// opens a context, loads a page or resizes without these.
|
|
8
|
+
|
|
9
|
+
/** The options of an audit's browser context: the caller's, plus reduced motion. */
|
|
10
|
+
export const auditOptions = (options = {}) => ({ ...options, reducedMotion: "reduce" });
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Runs before any page script: the browser offers no View Transition, so PageTransition (@krizaka/ui) changes the page
|
|
14
|
+
* at once. Reduced motion alone is not enough: the transition still starts, and a resize or a load under it, or a slow
|
|
15
|
+
* runner, makes the browser log « Transition was aborted » / « DOM update timed out » as a console error that has
|
|
16
|
+
* nothing to do with the page (main and two PRs, 2026-10-27). An audit measures layout, not motion.
|
|
17
|
+
*/
|
|
18
|
+
export const withoutViewTransitions = () => {
|
|
19
|
+
Object.defineProperty(Document.prototype, "startViewTransition", { value: undefined, configurable: true });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** A browser context for an audit (reduced motion emulated, no View Transition). */
|
|
23
|
+
export async function auditContext(browser, options) {
|
|
24
|
+
const context = await browser.newContext(auditOptions(options));
|
|
25
|
+
await context.addInitScript(withoutViewTransitions);
|
|
26
|
+
return context;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Resolves once no view transition is running (none starts under reduced motion; this makes the wait explicit). */
|
|
30
|
+
export const settled = (page) =>
|
|
31
|
+
page.waitForFunction(() => !document.activeViewTransition && !document.documentElement.matches(":active-view-transition"), null, { timeout: 10_000 });
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Loads a page, then waits for the faces and for the transitions: what is read afterwards is final. Returns the response.
|
|
35
|
+
* It first lets the page we are leaving finish any transition it started after the last measure (a router refresh, a
|
|
36
|
+
* poll): leaving one running aborts it, and the browser reports « Transition was aborted » as a console error (#354).
|
|
37
|
+
*/
|
|
38
|
+
export async function loadSettled(page, url, options = { waitUntil: "load" }) {
|
|
39
|
+
if (page.url() !== "about:blank") await settled(page);
|
|
40
|
+
const response = await page.goto(url, options);
|
|
41
|
+
await page.evaluate(() => document.fonts.ready);
|
|
42
|
+
await settled(page);
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Resizes the viewport, then waits for the transitions a resize can start. A transition already running is let finish
|
|
48
|
+
* first: a resize under it aborts it (« Viewport size changed », a console error), which is how this audit once failed.
|
|
49
|
+
*/
|
|
50
|
+
export async function resizeSettled(page, size) {
|
|
51
|
+
await settled(page);
|
|
52
|
+
await page.setViewportSize(size);
|
|
53
|
+
await settled(page);
|
|
54
|
+
}
|