@ashishjain15491/tapcheck 0.1.2 → 0.1.3
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 +28 -0
- package/README.md +6 -5
- package/dist/auth.d.ts +2 -0
- package/dist/auth.js +11 -5
- package/dist/browser.d.ts +35 -7
- package/dist/browser.js +198 -8
- package/dist/cli.js +19 -8
- package/dist/config.d.ts +7 -0
- package/dist/config.js +18 -6
- package/dist/flow.d.ts +15 -2
- package/dist/flow.js +37 -4
- package/dist/jev.d.ts +3 -1
- package/dist/jev.js +4 -0
- package/dist/parts.d.ts +3 -1
- package/dist/parts.js +3 -2
- package/dist/questions.d.ts +1 -1
- package/dist/questions.js +2 -2
- package/dist/report.d.ts +10 -0
- package/dist/report.js +54 -5
- package/dist/suites/a11y.js +5 -3
- package/dist/suites/audit.js +32 -12
- package/dist/suites/crawl.js +12 -9
- package/dist/suites/interact.js +24 -9
- package/dist/suites/usability.js +1 -1
- package/dist/suites/ux.js +1 -1
- package/package.json +1 -1
- package/schema/tapcheck.schema.json +19 -2
package/dist/flow.d.ts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import type { BrowserContext, Page } from 'playwright';
|
|
2
|
-
import { type Run } from './browser.ts';
|
|
2
|
+
import { type Mark, type Run } from './browser.ts';
|
|
3
3
|
import { type Config } from './config.ts';
|
|
4
|
+
import { type Finding } from './report.ts';
|
|
4
5
|
import type { FailRule, Reply, Seen } from './stub.ts';
|
|
5
6
|
/** For a flow's own questions to t.jev(), t.ask() and t.mail.judge(), and tapcheck's own sets to start from. */
|
|
6
7
|
export { choice, noul, score } from '@typesafe-ai/sdk';
|
|
7
8
|
export { EMAIL, VISUAL } from './questions.ts';
|
|
9
|
+
export type { Mark, MarkKind } from './browser.ts';
|
|
8
10
|
/**
|
|
9
11
|
* timeout: seconds the whole flow may take (default 3600); past it the flow fails and the run goes on.
|
|
10
12
|
* serial: with `parallel` above 1, this flow runs alone, after the flows before it end and before the ones after it start
|
|
11
13
|
* (for a flow that changes data the others read, stub rules or the whole Mailpit inbox).
|
|
14
|
+
* item: the release item this flow verifies, in the release note's words; it makes the flow a verify flow.
|
|
12
15
|
*/
|
|
13
16
|
export type Flow = {
|
|
14
17
|
name: string;
|
|
15
18
|
side?: string;
|
|
16
19
|
timeout?: number;
|
|
17
20
|
serial?: boolean;
|
|
21
|
+
item?: string;
|
|
18
22
|
run: (t: T) => Promise<void>;
|
|
19
23
|
};
|
|
20
24
|
/** A flow as loaded: its side settled and its part name. */
|
|
21
|
-
export type Loaded = Required<Flow
|
|
25
|
+
export type Loaded = Required<Omit<Flow, 'item'>> & {
|
|
26
|
+
item?: string;
|
|
22
27
|
part: string;
|
|
23
28
|
};
|
|
24
29
|
/** One message in Mailpit. headers: every header by name, as Mailpit spells it ("List-Unsubscribe"), each with its values. */
|
|
@@ -107,6 +112,14 @@ export declare class T {
|
|
|
107
112
|
}>): Promise<boolean>;
|
|
108
113
|
/** A finding the flow decides itself: a warning (default), a failure, or info such as a check it skipped and why. */
|
|
109
114
|
note(name: string, detail: string, status?: 'warn' | 'info' | 'fail'): void;
|
|
115
|
+
/**
|
|
116
|
+
* A finding the flow decided, with a marked screenshot of the current page as its evidence when marks are on (MARK=1
|
|
117
|
+
* or `marks: true`): the banner says `check` and `detail`, each mark boxes its target with its note. A pass is drawn
|
|
118
|
+
* only on a run ONLY or CHANGED scoped and in a verify flow; without marks on it is t.note with a status.
|
|
119
|
+
*/
|
|
120
|
+
mark(check: string, status: Finding['status'], marks: Mark[], detail?: string): Promise<void>;
|
|
121
|
+
/** A verify flow's item couldn't be checked in this run, and why: it is listed under "Not tested", neither passed nor failed. */
|
|
122
|
+
untested(why: string): void;
|
|
110
123
|
/** Records that Jev's look at `label` was skipped, and why. */
|
|
111
124
|
private skipped;
|
|
112
125
|
/**
|
package/dist/flow.js
CHANGED
|
@@ -28,15 +28,29 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
28
28
|
* finding without a step. Unlike the suites, a flow may click anything and change data: run it against a copy
|
|
29
29
|
* you can reset. t.jev() and t.mail.judge() ask Jev to look at the current page or at an email; with JEV=off or no key
|
|
30
30
|
* they record that they were skipped and return null, so a flow that calls them still runs everywhere.
|
|
31
|
+
*
|
|
32
|
+
* t.mark(check, status, marks, detail?) records a finding the flow decided ('pass', 'fail', 'warn' or 'info') and, with
|
|
33
|
+
* marks on (MARK=1, or marks: true in tapcheck.yml), a marked screenshot of the current page as its evidence: a banner
|
|
34
|
+
* in the status's colour saying the check and its detail (say what was expected and what is there), and a box, a
|
|
35
|
+
* numbered marker and a note on each `{ target, note, kind? }`. A target is a selector, a Playwright locator, or a box
|
|
36
|
+
* `{ x, y, width, height }` in viewport pixels; kind colours one mark by itself ('bug' red, 'pass' green, 'setting'
|
|
37
|
+
* blue, 'question' amber) and is otherwise the status's: fail, pass, info, warn in that order. A failure, a warning and
|
|
38
|
+
* an info are drawn on every run with marks on; a pass only on a run that ONLY or CHANGED scoped, or in a verify flow,
|
|
39
|
+
* so a full audit stays quiet. It needs no Jev.
|
|
40
|
+
*
|
|
41
|
+
* A verify flow checks one item of a release note or a pull request: it says which in `item`, is tagged verify
|
|
42
|
+
* (ONLY=verify runs just those), and its findings open the report as "Release verification". t.untested(why) records
|
|
43
|
+
* that the item couldn't be checked now (it needs market hours, a second device, another environment).
|
|
31
44
|
*/
|
|
32
45
|
import { globSync, mkdirSync } from 'node:fs';
|
|
33
46
|
import { resolve } from 'node:path';
|
|
34
47
|
import { pathToFileURL } from 'node:url';
|
|
35
48
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
36
|
-
import { abs, context,
|
|
49
|
+
import { abs, context, host, marked, reach, signedIn, REFUSED, settle, slices, slug, watch } from './browser.js';
|
|
37
50
|
import { isLocal } from './config.js';
|
|
38
51
|
import * as jev from './jev.js';
|
|
39
52
|
import { EMAIL, VISUAL, YES_IS_DEFECT } from './questions.js';
|
|
53
|
+
import { UNTESTED } from './report.js';
|
|
40
54
|
/** For a flow's own questions to t.jev(), t.ask() and t.mail.judge(), and tapcheck's own sets to start from. */
|
|
41
55
|
export { choice, noul, score } from '@typesafe-ai/sdk';
|
|
42
56
|
export { EMAIL, VISUAL } from './questions.js';
|
|
@@ -67,7 +81,7 @@ export class T {
|
|
|
67
81
|
/** The run's folder, for files of the flow's own (a payload log, a list it made). */
|
|
68
82
|
get dir() { return this.r.dir; }
|
|
69
83
|
record(f) { if (this.live())
|
|
70
|
-
this.r.record(f); }
|
|
84
|
+
this.r.record(this.flow.item ? { ...f, item: this.flow.item } : f); }
|
|
71
85
|
live() { return !this.dead || inCleanup.getStore()?.on === true; }
|
|
72
86
|
/** Stops the flow at its timeout: later findings are dropped and `t.signal` is aborted. */
|
|
73
87
|
kill(why) { this.dead = true; this.abort.abort(new Error(why)); }
|
|
@@ -163,7 +177,7 @@ export class T {
|
|
|
163
177
|
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
164
178
|
await settle(page);
|
|
165
179
|
if (opts.guard !== false && !this.signedOut.has(page.context()))
|
|
166
|
-
|
|
180
|
+
await signedIn(this.r, page, new URL(url).pathname);
|
|
167
181
|
return page;
|
|
168
182
|
}
|
|
169
183
|
/**
|
|
@@ -229,6 +243,23 @@ export class T {
|
|
|
229
243
|
this.alive();
|
|
230
244
|
this.record({ suite: this.flow.part, where: this.flow.name, check: name, status, detail });
|
|
231
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* A finding the flow decided, with a marked screenshot of the current page as its evidence when marks are on (MARK=1
|
|
248
|
+
* or `marks: true`): the banner says `check` and `detail`, each mark boxes its target with its note. A pass is drawn
|
|
249
|
+
* only on a run ONLY or CHANGED scoped and in a verify flow; without marks on it is t.note with a status.
|
|
250
|
+
*/
|
|
251
|
+
async mark(check, status, marks, detail) {
|
|
252
|
+
this.alive();
|
|
253
|
+
const page = this.current;
|
|
254
|
+
const draw = this.r.cfg.marks && page && !page.isClosed() && (status !== 'pass' || this.r.scoped || !!this.flow.item);
|
|
255
|
+
const shot = draw ? await marked(this.r, page, `${this.flow.part} ${check}`, { status, title: check, detail }, marks) : undefined;
|
|
256
|
+
this.record({ suite: this.flow.part, where: this.flow.name, check, status, detail, evidence: shot ? [shot] : undefined });
|
|
257
|
+
}
|
|
258
|
+
/** A verify flow's item couldn't be checked in this run, and why: it is listed under "Not tested", neither passed nor failed. */
|
|
259
|
+
untested(why) {
|
|
260
|
+
this.alive();
|
|
261
|
+
this.record({ suite: this.flow.part, where: this.flow.name, check: UNTESTED, status: 'info', detail: why });
|
|
262
|
+
}
|
|
232
263
|
/** Records that Jev's look at `label` was skipped, and why. */
|
|
233
264
|
skipped(label, why) {
|
|
234
265
|
this.record({ suite: this.flow.part, where: `${this.flow.name} › ${label}`, check: "Jev's look", status: 'info', detail: `skipped (${why})` });
|
|
@@ -479,10 +510,12 @@ export async function loadFlows(cfg) {
|
|
|
479
510
|
throw new Error(`${file}: timeout must be a number of seconds above 0.`);
|
|
480
511
|
if (f.serial !== undefined && typeof f.serial !== 'boolean')
|
|
481
512
|
throw new Error(`${file}: serial must be true or false.`);
|
|
513
|
+
if (f.item !== undefined && (typeof f.item !== 'string' || !f.item.trim()))
|
|
514
|
+
throw new Error(`${file}: item must be the release item this flow verifies, as text.`);
|
|
482
515
|
const part = `flow-${slug(f.name).replace(/_/g, '-')}`;
|
|
483
516
|
if (out.some((o) => o.part === part))
|
|
484
517
|
throw new Error(`${file}: another flow is already called "${f.name}" (part ${part}).`);
|
|
485
|
-
out.push({ name: f.name, side, timeout: f.timeout ?? 3600, serial: f.serial ?? false, run: f.run, part });
|
|
518
|
+
out.push({ name: f.name, side, timeout: f.timeout ?? 3600, serial: f.serial ?? false, item: f.item, run: f.run, part });
|
|
486
519
|
}
|
|
487
520
|
}
|
|
488
521
|
return out;
|
package/dist/jev.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export declare function apiKey(): string | undefined;
|
|
|
31
31
|
export declare const whyOff: () => "" | "JEV=off" | "no TYPESAFE_API_KEY";
|
|
32
32
|
export declare const payloads: unknown[];
|
|
33
33
|
/** Starts a run: its budget and headers, counters and memo cleared. A self-check passes a fake client; nothing then reaches the network. */
|
|
34
|
-
export declare function setup(jev: Config['jev']
|
|
34
|
+
export declare function setup(jev: Config['jev'] & {
|
|
35
|
+
context?: string;
|
|
36
|
+
}, fake?: Client): void;
|
|
35
37
|
/** One Jev request. `images` are the files behind the images in `state`: they key the memo and stand in for the bytes in the log. */
|
|
36
38
|
export declare function ask(label: string, state: unknown, questions: Record<string, any>, images: string[], model?: string): Promise<any>;
|
|
37
39
|
export declare const img: (file: string) => import("@typesafe-ai/sdk").Image;
|
package/dist/jev.js
CHANGED
|
@@ -47,6 +47,10 @@ export function setup(jev, fake) {
|
|
|
47
47
|
}
|
|
48
48
|
/** One Jev request. `images` are the files behind the images in `state`: they key the memo and stand in for the bytes in the log. */
|
|
49
49
|
export async function ask(label, state, questions, images, model) {
|
|
50
|
+
// tapcheck.yml's context: the kind of product, so every judgment is made against what its users expect.
|
|
51
|
+
// Only a plain record of fields: a request whose state is the image itself (predicted attention) is left as it is.
|
|
52
|
+
if (opts.context && state && Object.getPrototypeOf(state) === Object.prototype)
|
|
53
|
+
state = { product: opts.context, ...state };
|
|
50
54
|
const shown = JSON.parse(JSON.stringify(state)); // the SDK writes each image as a short "<image:…>" name here, never its bytes
|
|
51
55
|
const hash = createHash('sha256').update(JSON.stringify([model, shown, questions]));
|
|
52
56
|
for (const f of images)
|
package/dist/parts.d.ts
CHANGED
|
@@ -13,12 +13,14 @@ export type State = {
|
|
|
13
13
|
parts: Record<string, Snap>;
|
|
14
14
|
reset?: Snap;
|
|
15
15
|
};
|
|
16
|
-
/** Every part in run order: code (when there is any), then by side its suites and its flows (`part` is a flow's part
|
|
16
|
+
/** Every part in run order: code (when there is any), then by side its suites and its flows (`part` is a flow's part
|
|
17
|
+
* name; one with an `item` verifies a release item and is tagged verify too). */
|
|
17
18
|
export declare const build: (sides: string[], extra?: {
|
|
18
19
|
code?: boolean;
|
|
19
20
|
flows?: {
|
|
20
21
|
part: string;
|
|
21
22
|
side: string;
|
|
23
|
+
item?: string;
|
|
22
24
|
}[];
|
|
23
25
|
}) => Part[];
|
|
24
26
|
/** The suite name a part's findings carry: its suite, or for a flow its own name (so one flow failing doesn't fail the others). */
|
package/dist/parts.js
CHANGED
|
@@ -8,13 +8,14 @@ import { matchesGlob, posix, relative, resolve } from 'node:path';
|
|
|
8
8
|
import { SUITES } from './config.js';
|
|
9
9
|
const JEV = ['ux', 'usability']; // the suites Jev judges
|
|
10
10
|
const NEEDS_CRAWL = ['contract', 'security', 'interact']; // they read the crawl's records
|
|
11
|
-
/** Every part in run order: code (when there is any), then by side its suites and its flows (`part` is a flow's part
|
|
11
|
+
/** Every part in run order: code (when there is any), then by side its suites and its flows (`part` is a flow's part
|
|
12
|
+
* name; one with an `item` verifies a release item and is tagged verify too). */
|
|
12
13
|
export const build = (sides, extra = {}) => [
|
|
13
14
|
...(extra.code ? [{ name: 'code', suite: 'code', side: '', tags: ['code', 'measured'], needs: [] }] : []),
|
|
14
15
|
...sides.flatMap((side) => [
|
|
15
16
|
...SUITES.map((suite) => ({ name: `${suite}-${side}`, suite, side, tags: [suite, side, JEV.includes(suite) ? 'jev' : 'measured'],
|
|
16
17
|
needs: NEEDS_CRAWL.includes(suite) ? [`crawl-${side}`] : [] })),
|
|
17
|
-
...(extra.flows ?? []).filter((f) => f.side === side).map((f) => ({ name: f.part, suite: 'flow', side, tags: ['flow', side, 'measured'], needs: [] })),
|
|
18
|
+
...(extra.flows ?? []).filter((f) => f.side === side).map((f) => ({ name: f.part, suite: 'flow', side, tags: ['flow', side, 'measured', ...(f.item ? ['verify'] : [])], needs: [] })),
|
|
18
19
|
]),
|
|
19
20
|
];
|
|
20
21
|
/** The suite name a part's findings carry: its suite, or for a flow its own name (so one flow failing doesn't fail the others). */
|
package/dist/questions.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare const DESIGN: {
|
|
|
28
28
|
legibility: import("@typesafe-ai/sdk").ScoreQuestion<readonly ["Much of the text is too faint, too small or too low in contrast to read.", "Several labels or paragraphs are hard to read.", "Most text is readable, but some secondary text is faint or tiny.", "Nearly all text is easy to read; one or two small labels are a little faint.", "All text is crisp, well sized and in strong contrast with its background."]>;
|
|
29
29
|
spacing: import("@typesafe-ai/sdk").ScoreQuestion<readonly ["Elements are crammed together or scattered with no visible rhythm.", "Spacing varies noticeably between elements of the same kind.", "Spacing is mostly regular, with some cramped or loose areas.", "Spacing is regular, with one or two small inconsistencies.", "Spacing between and around every group is even and deliberate."]>;
|
|
30
30
|
};
|
|
31
|
-
export declare const HEURISTICS: (audience: string) => {
|
|
31
|
+
export declare const HEURISTICS: (audience: string, context?: string) => {
|
|
32
32
|
h1_status: import("@typesafe-ai/sdk").ScoreQuestion<readonly ["Nothing tells the person where they are or what state things are in.", "The current page is hard to make out and states are not shown.", "The current page is shown, but states such as saved, draft or loading are unclear.", "The current page and most states are clear.", "The current page, item states and any progress are all plain to see."]>;
|
|
33
33
|
h2_language: import("@typesafe-ai/sdk").ScoreQuestion<readonly ["Much of the wording is technical jargon, codes or internal names.", "Several labels use jargon or words that reader would not use.", "Mostly plain, with a few technical terms left unexplained.", "Plain everyday wording, with one or two technical terms.", "Every label and message reads as a person would say it."]>;
|
|
34
34
|
h4_consistency: import("@typesafe-ai/sdk").ScoreQuestion<readonly ["Things that do the same job look different everywhere.", "Several buttons or links of the same kind look different.", "Mostly consistent, with a few odd ones out.", "Consistent, with one small exception.", "Every control of a kind looks and behaves the same way."]>;
|
package/dist/questions.js
CHANGED
|
@@ -106,7 +106,7 @@ export const DESIGN = {
|
|
|
106
106
|
// ───────────────────────────── HEURISTIC EVALUATION (the usability heuristics a screenshot can show) ─────────────────────────────
|
|
107
107
|
// Error recovery, undo and shortcuts for experts need interaction, so the usability suite covers them, not these.
|
|
108
108
|
// `audience` is tapcheck.yml's audience: who the app is for, so plain wording is judged for that reader.
|
|
109
|
-
export const HEURISTICS = (audience) => ({
|
|
109
|
+
export const HEURISTICS = (audience, context) => ({
|
|
110
110
|
h1_status: score('How well do `screenshots` show where the person is and the state of things (current page, saved or not, loading, counts)?', [
|
|
111
111
|
'Nothing tells the person where they are or what state things are in.',
|
|
112
112
|
'The current page is hard to make out and states are not shown.',
|
|
@@ -114,7 +114,7 @@ export const HEURISTICS = (audience) => ({
|
|
|
114
114
|
'The current page and most states are clear.',
|
|
115
115
|
'The current page, item states and any progress are all plain to see.',
|
|
116
116
|
]),
|
|
117
|
-
h2_language: score(`How well does the wording in \`screenshots\` use everyday words ${audience} would use
|
|
117
|
+
h2_language: score(`How well does the wording in \`screenshots\` use everyday words ${audience} would use?${context ? ' The terms of their field that `product` names count as their own words.' : ''}`, [
|
|
118
118
|
'Much of the wording is technical jargon, codes or internal names.',
|
|
119
119
|
'Several labels use jargon or words that reader would not use.',
|
|
120
120
|
'Mostly plain, with a few technical terms left unexplained.',
|
package/dist/report.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Recording } from './browser.ts';
|
|
2
|
+
/** item: the release item a verify flow checks (its `item`), on each of that flow's findings. */
|
|
2
3
|
export type Finding = {
|
|
3
4
|
suite: string;
|
|
4
5
|
side: string;
|
|
@@ -7,9 +8,18 @@ export type Finding = {
|
|
|
7
8
|
status: 'pass' | 'fail' | 'warn' | 'info';
|
|
8
9
|
detail?: string;
|
|
9
10
|
evidence?: string[];
|
|
11
|
+
item?: string;
|
|
10
12
|
};
|
|
11
13
|
export declare const findings: Finding[];
|
|
14
|
+
/** The check t.untested() records under: a verify flow's item that couldn't be checked in this run. */
|
|
15
|
+
export declare const UNTESTED = "not tested";
|
|
12
16
|
export declare const record: (f: Finding) => void;
|
|
17
|
+
/** tapcheck.yml's expect: a fail or warn whose "<suite>: <check> @ <where>" matches a rule is right for this product. It is
|
|
18
|
+
* kept as info, saying why and what it was, so the report still shows it and nothing is dropped. */
|
|
19
|
+
export declare function expected(f: Finding, rules: {
|
|
20
|
+
match: RegExp;
|
|
21
|
+
why: string;
|
|
22
|
+
}[]): Finding;
|
|
13
23
|
/** Writes the three reports into `dir`; returns the per-suite counts and the number of failures. */
|
|
14
24
|
export declare function write(dir: string, meta: {
|
|
15
25
|
base: string;
|
package/dist/report.js
CHANGED
|
@@ -1,13 +1,61 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The evidence report: report.html (failures first, with evidence thumbnails and links), REPORT.md (for a PR or a
|
|
3
3
|
* ticket) and findings.json, all in the run's folder next to the screenshots and JSON evidence they point to. A run with
|
|
4
|
-
* RECORD=1 also lists its videos and Playwright traces, per side and part.
|
|
4
|
+
* RECORD=1 also lists its videos and Playwright traces, per side and part. A run with verify flows (flows with an `item`)
|
|
5
|
+
* opens with "Release verification": what the release claimed and what held, in a QA report's order.
|
|
5
6
|
*/
|
|
6
7
|
import { writeFileSync } from 'node:fs';
|
|
7
8
|
export const findings = [];
|
|
9
|
+
/** The check t.untested() records under: a verify flow's item that couldn't be checked in this run. */
|
|
10
|
+
export const UNTESTED = 'not tested';
|
|
8
11
|
export const record = (f) => { findings.push(f); };
|
|
12
|
+
/** tapcheck.yml's expect: a fail or warn whose "<suite>: <check> @ <where>" matches a rule is right for this product. It is
|
|
13
|
+
* kept as info, saying why and what it was, so the report still shows it and nothing is dropped. */
|
|
14
|
+
export function expected(f, rules) {
|
|
15
|
+
if (f.status !== 'fail' && f.status !== 'warn')
|
|
16
|
+
return f;
|
|
17
|
+
const rule = rules.find((x) => x.match.test(`${f.suite}: ${f.check} @ ${f.where}`));
|
|
18
|
+
return rule ? { ...f, status: 'info', detail: `expected: ${rule.why} (was ${f.status}${f.detail ? `: ${f.detail}` : ''})` } : f;
|
|
19
|
+
}
|
|
9
20
|
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
10
21
|
const ORDER = { fail: 0, warn: 1, info: 2, pass: 3 };
|
|
22
|
+
const cell = (s) => s.replace(/[\\|]/g, '\\$&').replace(/\s+/g, ' '); // a backslash first, so `a\|b` stays one cell
|
|
23
|
+
const png = (f) => f.evidence?.find((e) => /\.png$/.test(e));
|
|
24
|
+
/**
|
|
25
|
+
* The verify flows' findings as the section that opens both reports: a one-line count, the failed items with their
|
|
26
|
+
* steps and screenshots (its questions' are under the questions), the passed ones as a table, the questions (every
|
|
27
|
+
* warning), and what wasn't tested and why.
|
|
28
|
+
* An item is its flow: failed with any failing finding, else not tested with a t.untested(), else passed with a pass.
|
|
29
|
+
* Null when the run had no verify flow.
|
|
30
|
+
*/
|
|
31
|
+
function verification(rel, ev) {
|
|
32
|
+
const of = (f) => `${f.suite}\n${f.side}`;
|
|
33
|
+
const items = [...new Set(findings.filter((f) => f.item).map(of))].map((k) => {
|
|
34
|
+
const list = findings.filter((f) => of(f) === k), has = (st) => list.some((f) => f.status === st);
|
|
35
|
+
const why = list.find((f) => f.check === UNTESTED);
|
|
36
|
+
return { item: list.find((f) => f.item).item, list, why, state: has('fail') ? 'failed' : why ? 'untested' : has('pass') ? 'passed' : '' };
|
|
37
|
+
});
|
|
38
|
+
if (!items.length)
|
|
39
|
+
return null;
|
|
40
|
+
const failed = items.filter((i) => i.state === 'failed'), passed = items.filter((i) => i.state === 'passed'), untested = items.filter((i) => i.state === 'untested');
|
|
41
|
+
const questions = items.flatMap((i) => i.list.filter((f) => f.status === 'warn').map((f) => ({ item: i.item, f })));
|
|
42
|
+
const summary = `${passed.length} passed · ${failed.length} failed · ${questions.length} question${questions.length === 1 ? '' : 's'} · ${untested.length} not tested`;
|
|
43
|
+
const step = (f) => `${f.check}${f.detail ? `: ${f.detail}` : ''}`;
|
|
44
|
+
const checked = (i) => i.list.filter((f) => f.status === 'pass').map(step).join('; ');
|
|
45
|
+
const shots = (i, ...st) => [...new Set(i.list.filter((f) => st.includes(f.status)).map(png).filter((e) => !!e))];
|
|
46
|
+
const html = `<h2>Release verification</h2><p class="meta">${summary}</p>`
|
|
47
|
+
+ (failed.length ? `<h3>Failed</h3>${failed.map((i) => `<h4>${esc(i.item)}</h4><ol>${i.list.map((f) => `<li><span class="tag ${f.status}">${f.status}</span> ${esc(step(f))}</li>`).join('')}</ol>`
|
|
48
|
+
+ `<p class="big">${shots(i, 'fail', 'info').map((e) => `<a href="${esc(rel(e))}" target="_blank" rel="noopener"><img src="${esc(rel(e))}" alt="evidence" loading="lazy"></a>`).join('')}</p>`).join('')}` : '')
|
|
49
|
+
+ (passed.length ? `<h3>Passed</h3><div class="wrap"><table><thead><tr><th>Release item</th><th>What was checked</th><th>Evidence</th></tr></thead><tbody>${passed.map((i) => `<tr><td>${esc(i.item)}</td><td>${esc(checked(i))}</td><td>${shots(i, 'pass', 'info').map(ev).join('')}</td></tr>`).join('')}</tbody></table></div>` : '')
|
|
50
|
+
+ (questions.length ? `<h3>Questions for the team</h3><ul>${questions.map((q) => `<li><b>${esc(q.item)}</b> · ${esc(step(q.f))}${png(q.f) ? ev(png(q.f)) : ''}</li>`).join('')}</ul>` : '')
|
|
51
|
+
+ (untested.length ? `<h3>Not tested</h3><div class="wrap"><table><thead><tr><th>Release item</th><th>Why not</th></tr></thead><tbody>${untested.map((i) => `<tr><td>${esc(i.item)}</td><td>${esc(i.why.detail ?? '')}</td></tr>`).join('')}</tbody></table></div>` : '');
|
|
52
|
+
const md = ['## Release verification', '', summary, '',
|
|
53
|
+
...(failed.length ? ['### Failed', '', ...failed.flatMap((i) => [`**${i.item}**`, '', ...i.list.map((f, n) => `${n + 1}. ${f.status} · ${step(f)}`), '', ...shots(i, 'fail', 'info').map((e) => `})`), ''])] : []),
|
|
54
|
+
...(passed.length ? ['### Passed', '', '| Release item | What was checked | Evidence |', '|---|---|---|', ...passed.map((i) => `| ${cell(i.item)} | ${cell(checked(i))} | ${shots(i, 'pass', 'info').map((e) => cell(rel(e))).join(' · ')} |`), ''] : []),
|
|
55
|
+
...(questions.length ? ['### Questions for the team', '', ...questions.map((q) => `- **${q.item}** · ${step(q.f)}${png(q.f) ? ` (${rel(png(q.f))})` : ''}`), ''] : []),
|
|
56
|
+
...(untested.length ? ['### Not tested', '', '| Release item | Why not |', '|---|---|', ...untested.map((i) => `| ${cell(i.item)} | ${cell(i.why.detail ?? '')} |`), ''] : [])];
|
|
57
|
+
return { html, md };
|
|
58
|
+
}
|
|
11
59
|
/** Writes the three reports into `dir`; returns the per-suite counts and the number of failures. */
|
|
12
60
|
export function write(dir, meta) {
|
|
13
61
|
const rel = (p) => (p.startsWith(`${dir}/`) ? p.slice(dir.length + 1) : p);
|
|
@@ -27,6 +75,7 @@ export function write(dir, meta) {
|
|
|
27
75
|
: ` <a href="${esc(rel(e))}">${esc(rel(e))}</a>`);
|
|
28
76
|
const row = (f) => `<tr class="${f.status}"><td><span class="tag ${f.status}">${f.status}</span></td><td>${esc(key(f))}</td><td>${esc(f.where)}</td>`
|
|
29
77
|
+ `<td>${esc(f.check)}</td><td>${esc(f.detail ?? '')}${(f.evidence ?? []).map(ev).join('')}</td></tr>`;
|
|
78
|
+
const verify = verification(rel, ev);
|
|
30
79
|
const recs = (meta.recordings ?? []).filter((r) => r.videos.length || r.trace);
|
|
31
80
|
const recorded = recs.length ? `<h2>Recordings</h2><p class="meta">A video per browser page, and a trace of every action with the page as it was: open one with the command next to it.</p><ul>${recs.map((r) => `<li>${esc(r.side)} · ${esc(r.label)}${r.videos.map((v, i) => ` · <a href="${esc(rel(v))}">video${r.videos.length > 1 ? ` ${i + 1}` : ''}</a>`).join('')}`
|
|
32
81
|
+ `${r.trace ? ` · <a href="${esc(rel(r.trace))}">trace</a> <code>npx playwright show-trace ${esc(r.trace)}</code>` : ''}</li>`).join('')}</ul>` : '';
|
|
@@ -34,22 +83,22 @@ export function write(dir, meta) {
|
|
|
34
83
|
:root{--bg:#fff;--fg:#1f2937;--mut:#6b7280;--line:#e5e7eb;--fail:#b91c1c;--warn:#b45309;--pass:#15803d;--info:#1d4ed8}
|
|
35
84
|
@media (prefers-color-scheme:dark){:root{--bg:#111827;--fg:#e5e7eb;--mut:#9ca3af;--line:#374151;--fail:#f87171;--warn:#fbbf24;--pass:#4ade80;--info:#93c5fd}}
|
|
36
85
|
body{margin:0;padding:24px 16px;background:var(--bg);color:var(--fg);font:14px/1.5 system-ui,sans-serif}main{max-width:1280px;margin:0 auto}
|
|
37
|
-
h1{margin:0 0 4px;font-size:22px}h2{margin:28px 0 4px;font-size:16px}li{margin:4px 0}code{font-size:12px;color:var(--mut)}p.meta{color:var(--mut);margin:0 0 20px}.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px;margin-bottom:24px}
|
|
86
|
+
h1{margin:0 0 4px;font-size:22px}h2{margin:28px 0 4px;font-size:16px}h3{margin:20px 0 6px;font-size:14px}h4{margin:14px 0 2px;font-size:14px}.big img{display:block;max-width:min(100%,960px);margin:8px 0 16px;border:1px solid var(--line);border-radius:4px}li{margin:4px 0}code{font-size:12px;color:var(--mut)}p.meta{color:var(--mut);margin:0 0 20px}.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px;margin-bottom:24px}
|
|
38
87
|
.card{border:1px solid var(--line);border-radius:10px;padding:12px}.card b{display:block;text-transform:uppercase;font-size:12px;color:var(--mut);letter-spacing:.04em}
|
|
39
88
|
.card span{font-size:13px}.n{font-size:20px;font-weight:700}.f{color:var(--fail)}.w{color:var(--warn)}.p{color:var(--pass)}
|
|
40
89
|
.filters{margin:0 0 12px;display:flex;gap:8px;flex-wrap:wrap}.filters label{border:1px solid var(--line);border-radius:999px;padding:4px 10px;cursor:pointer}
|
|
41
90
|
.wrap{overflow-x:auto}table{border-collapse:collapse;width:100%}th,td{text-align:left;vertical-align:top;padding:8px;border-bottom:1px solid var(--line)}th{font-size:12px;color:var(--mut);text-transform:uppercase}
|
|
42
|
-
td img{max-width:120px;max-height:80px;border:1px solid var(--line);border-radius:4px;vertical-align:middle;margin:2px}
|
|
91
|
+
td img,li img{max-width:120px;max-height:80px;border:1px solid var(--line);border-radius:4px;vertical-align:middle;margin:2px}
|
|
43
92
|
.tag{font-size:11px;font-weight:700;text-transform:uppercase;padding:2px 6px;border-radius:4px;border:1px solid currentColor}.tag.fail{color:var(--fail)}.tag.warn{color:var(--warn)}.tag.pass{color:var(--pass)}.tag.info{color:var(--info)}
|
|
44
93
|
body:has(#hp:not(:checked)) tr.pass{display:none}body:has(#hw:not(:checked)) tr.warn{display:none}body:has(#hi:not(:checked)) tr.info{display:none}
|
|
45
|
-
</style></head><body><main><h1>tapcheck report</h1><p class="meta">${esc(meta.base)} · ${when} · ${mins} min${meta.note ? ` · ${esc(meta.note)}` : ''}</p>
|
|
94
|
+
</style></head><body><main><h1>tapcheck report</h1><p class="meta">${esc(meta.base)} · ${when} · ${mins} min${meta.note ? ` · ${esc(meta.note)}` : ''}</p>${verify ? `${verify.html}<h2>Every check</h2>` : ''}
|
|
46
95
|
<div class="cards">${bySuite.map((b) => `<div class="card"><b>${esc(b.s)}</b><span class="n ${b.fail ? 'f' : b.skipped ? 'w' : 'p'}">${b.fail ? `${b.fail} failing` : b.skipped ? 'skipped' : 'clean'}</span><br><span><span class="w">${b.warn} warn</span> · <span class="p">${b.pass} pass</span> · ${b.total} checks</span></div>`).join('')}</div>
|
|
47
96
|
<div class="filters"><label><input type="checkbox" id="hw" checked> warnings</label><label><input type="checkbox" id="hi" checked> info</label><label><input type="checkbox" id="hp"> passes</label></div>
|
|
48
97
|
<div class="wrap"><table><thead><tr><th>Status</th><th>Suite</th><th>Where</th><th>Check</th><th>Detail and evidence</th></tr></thead><tbody>${sorted.map(row).join('')}</tbody></table></div>${recorded}
|
|
49
98
|
<p class="meta">Raw evidence: findings.json, payloads.json (every Jev request), code.json (the gates' output), and per side crawl.json, network.json, missed-routes.json, axe.json, interact.json, audit.json, clickstream.json and hits.json (what each part reached, for COVERAGE=1).</p></main></body></html>`;
|
|
50
99
|
writeFileSync(`${dir}/report.html`, html);
|
|
51
100
|
const line = (f) => `- **${key(f)}** · ${f.where} · ${f.check}${f.detail ? `: ${f.detail}` : ''}`;
|
|
52
|
-
const md = [`# tapcheck · ${meta.base}`, '', `${when} · ${mins} min${meta.note ? ` · ${meta.note}` : ''}`, '',
|
|
101
|
+
const md = [`# tapcheck · ${meta.base}`, '', `${when} · ${mins} min${meta.note ? ` · ${meta.note}` : ''}`, '', ...(verify?.md ?? []),
|
|
53
102
|
'| Suite | Failing | Warnings | Passing |', '|---|---|---|---|', ...bySuite.map((b) => `| ${b.s} | ${b.fail} | ${b.warn} | ${b.pass} |`), '',
|
|
54
103
|
'## Failing', '', ...sorted.filter((f) => f.status === 'fail').map(line), '', '## Warnings', '', ...sorted.filter((f) => f.status === 'warn').map(line), '',
|
|
55
104
|
...(sorted.some((f) => f.check === 'part ran' && f.status === 'info') ? ['## Skipped', '', ...sorted.filter((f) => f.check === 'part ran' && f.status === 'info').map(line), ''] : []),
|
package/dist/suites/a11y.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
|
-
import { context, open, resolve, SessionExpired, slug } from '../browser.js';
|
|
8
|
+
import { context, marked, open, resolve, SessionExpired, slug } from '../browser.js';
|
|
9
9
|
export const AXE = readFileSync(createRequire(import.meta.url).resolve('axe-core/axe.min.js'), 'utf8');
|
|
10
10
|
const TABS = 12;
|
|
11
11
|
export async function run(r) {
|
|
@@ -30,8 +30,10 @@ export async function run(r) {
|
|
|
30
30
|
all[`${slug(s.name)}-${vp.name}`] = res.violations.map((x) => ({ id: x.id, impact: x.impact, help: x.help, nodes: x.nodes.slice(0, 5).map((n) => n.target) }));
|
|
31
31
|
for (const impact of ['critical', 'serious', 'moderate']) {
|
|
32
32
|
const v = res.violations.filter((x) => x.impact === impact);
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const status = v.length ? (impact === 'moderate' ? 'warn' : 'fail') : 'pass', detail = v.map((x) => `${x.id} ×${x.nodes.length}`).join(', ') || undefined;
|
|
34
|
+
// MARK=1: axe's own selector for each node, with its rule as the note (a node inside a frame or a shadow root has no single selector).
|
|
35
|
+
const shot = v.length && r.cfg.marks ? await marked(r, page, `a11y ${where} ${impact}`, { status, title: `axe: no ${impact} violations`, detail: `${where} · ${detail}` }, v.flatMap((x) => x.nodes.filter((n) => n.target.length === 1 && typeof n.target[0] === 'string').map((n) => ({ target: n.target[0], note: x.id })))) : undefined;
|
|
36
|
+
r.record({ suite: S, where, check: `axe: no ${impact} violations`, status, detail, evidence: shot ? [shot] : undefined });
|
|
35
37
|
}
|
|
36
38
|
if (vp.mobile)
|
|
37
39
|
continue;
|
package/dist/suites/audit.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* suite's UNSAFE words, never a submit button. audit.json holds everything found.
|
|
18
18
|
*/
|
|
19
19
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
20
|
-
import { context, open, resolve, SessionExpired, slices, slug } from '../browser.js';
|
|
20
|
+
import { context, hashRoute, marked, open, resolve, SessionExpired, slices, slug } from '../browser.js';
|
|
21
21
|
import { ask, BudgetReached, img, whyOff } from '../jev.js';
|
|
22
22
|
import { VISUAL } from '../questions.js';
|
|
23
23
|
import { AXE } from './a11y.js';
|
|
@@ -26,6 +26,9 @@ import { visual } from './ux.js';
|
|
|
26
26
|
const S = 'audit';
|
|
27
27
|
const NARROW = [{ name: 'tablet', width: 768, height: 1024, mobile: false }, { name: 'phone', width: 375, height: 812, mobile: true }];
|
|
28
28
|
const WARN = new Set(['shortened text can be read in full', 'heading levels in order']); // the other measured checks fail
|
|
29
|
+
// The checks that know their elements: measure() tags each with data-tapcheck-mark-<this> (its value the element's note), for a marked screenshot.
|
|
30
|
+
const MARKS = { 'no sideways scroll': 'wide', 'text is not cut off': 'cut', 'shortened text can be read in full': 'short', 'controls do not overlap': 'overlap',
|
|
31
|
+
'targets at least 24 px': 'small', 'images have alt text': 'alt' };
|
|
29
32
|
const TABS = 20, MAX_POPUPS = 4;
|
|
30
33
|
const POPUP = '[role=menu], [role=listbox], dialog[open], [role=dialog], [role=alertdialog], [popover]:popover-open';
|
|
31
34
|
// ponytail: primary, secondary and danger is the most a button kind gets before its colours count as inconsistent; fields get one.
|
|
@@ -46,8 +49,13 @@ function measure({ root: rootSel, extras, design }) {
|
|
|
46
49
|
const all = [...root.querySelectorAll('*')].filter(visible);
|
|
47
50
|
const cut = new Set(), short = new Set(), overlap = new Set(), small = new Set();
|
|
48
51
|
const problems = {};
|
|
52
|
+
const mark = (el, what, note) => el.setAttribute(`data-tapcheck-mark-${what}`, note);
|
|
53
|
+
for (const what of ['wide', 'cut', 'short', 'overlap', 'small', 'alt'])
|
|
54
|
+
document.querySelectorAll(`[data-tapcheck-mark-${what}]`).forEach((el) => el.removeAttribute(`data-tapcheck-mark-${what}`)); // an earlier measure's
|
|
49
55
|
if (!rootSel) {
|
|
50
56
|
const wide = document.documentElement.scrollWidth > vw + 1 && all.filter((e) => e.getBoundingClientRect().right > vw + 1).sort((a, b) => b.getBoundingClientRect().right - a.getBoundingClientRect().right)[0];
|
|
57
|
+
if (wide)
|
|
58
|
+
mark(wide, 'wide', `widest: ${desc(wide)}`);
|
|
51
59
|
problems['no sideways scroll'] = document.documentElement.scrollWidth > vw + 1 ? [`the page is ${document.documentElement.scrollWidth} px wide in a ${vw} px window${wide ? `; widest: ${desc(wide)}` : ''}`] : [];
|
|
52
60
|
}
|
|
53
61
|
else {
|
|
@@ -64,10 +72,14 @@ function measure({ root: rootSel, extras, design }) {
|
|
|
64
72
|
continue;
|
|
65
73
|
if (!ownText(el) && ![...el.children].every((c) => getComputedStyle(c).display.startsWith('inline')))
|
|
66
74
|
continue;
|
|
67
|
-
if (s.textOverflow !== 'ellipsis')
|
|
75
|
+
if (s.textOverflow !== 'ellipsis') {
|
|
68
76
|
cut.add(`"${txt(el)}" (${desc(el)})`);
|
|
69
|
-
|
|
77
|
+
mark(el, 'cut', 'text cut off');
|
|
78
|
+
}
|
|
79
|
+
else if (!el.getAttribute('title') && !el.getAttribute('aria-label') && !el.closest('[title], [aria-describedby]')) {
|
|
70
80
|
short.add(`"${txt(el)}" (${desc(el)})`);
|
|
81
|
+
mark(el, 'short', 'shortened, with no way to read it');
|
|
82
|
+
}
|
|
71
83
|
}
|
|
72
84
|
// Controls, each clipped to what its scrolling ancestors leave visible.
|
|
73
85
|
const seen = (el) => {
|
|
@@ -92,8 +104,11 @@ function measure({ root: rootSel, extras, design }) {
|
|
|
92
104
|
if (a.el.contains(b.el) || b.el.contains(a.el) || (a.el.closest('label') && a.el.closest('label') === b.el.closest('label')))
|
|
93
105
|
continue;
|
|
94
106
|
const w = Math.min(a.box.right, b.box.right) - Math.max(a.box.left, b.box.left), h = Math.min(a.box.bottom, b.box.bottom) - Math.max(a.box.top, b.box.top);
|
|
95
|
-
if (w > 4 && h > 4 && w * h > 0.25 * Math.min(a.box.width * a.box.height, b.box.width * b.box.height))
|
|
107
|
+
if (w > 4 && h > 4 && w * h > 0.25 * Math.min(a.box.width * a.box.height, b.box.width * b.box.height)) {
|
|
96
108
|
overlap.add(`${name(a.el)} ↔ ${name(b.el)}`);
|
|
109
|
+
for (const c of [a, b])
|
|
110
|
+
mark(c.el, 'overlap', `${name(a.el)} ↔ ${name(b.el)}`);
|
|
111
|
+
}
|
|
97
112
|
}
|
|
98
113
|
// WCAG 2.2 target size (2.5.8): under 24 px fails unless a 24 px area centred on it touches no other target. Links in a sentence are exempt.
|
|
99
114
|
for (const { el } of controls) {
|
|
@@ -104,8 +119,10 @@ function measure({ root: rootSel, extras, design }) {
|
|
|
104
119
|
continue;
|
|
105
120
|
const cx = r.left + r.width / 2, cy = r.top + r.height / 2, hw = Math.max(12, r.width / 2), hh = Math.max(12, r.height / 2);
|
|
106
121
|
const crowded = controls.some((o) => { const t = o.el.getBoundingClientRect(); return o.el !== el && !o.el.contains(el) && !el.contains(o.el) && t.left < cx + hw && t.right > cx - hw && t.top < cy + hh && t.bottom > cy - hh; });
|
|
107
|
-
if (crowded)
|
|
122
|
+
if (crowded) {
|
|
108
123
|
small.add(`${name(el)} ${Math.round(r.width)}×${Math.round(r.height)}`);
|
|
124
|
+
mark(el, 'small', `${Math.round(r.width)}×${Math.round(r.height)} px`);
|
|
125
|
+
}
|
|
109
126
|
}
|
|
110
127
|
Object.assign(problems, { 'text is not cut off': [...cut], 'shortened text can be read in full': [...short], 'controls do not overlap': [...overlap], 'targets at least 24 px': [...small] });
|
|
111
128
|
const items = [], labels = [], off = [];
|
|
@@ -124,7 +141,7 @@ function measure({ root: rootSel, extras, design }) {
|
|
|
124
141
|
const heads = [...root.querySelectorAll('h1, h2, h3, h4, h5, h6')].filter(visible);
|
|
125
142
|
problems['no leaked placeholders'] = [...leaked];
|
|
126
143
|
problems['heading levels in order'] = heads.slice(1).flatMap((h, i) => (+h.tagName[1] > +heads[i].tagName[1] + 1 ? [`${heads[i].tagName.toLowerCase()} → ${h.tagName.toLowerCase()} "${txt(h)}"`] : []));
|
|
127
|
-
problems['images have alt text'] = [...root.querySelectorAll('img')].filter((i) => visible(i) && !i.hasAttribute('alt') && !i.getAttribute('aria-label')).map((i) => i.src.slice(-60));
|
|
144
|
+
problems['images have alt text'] = [...root.querySelectorAll('img')].filter((i) => visible(i) && !i.hasAttribute('alt') && !i.getAttribute('aria-label')).map((i) => { mark(i, 'alt', 'no alt text'); return i.src.slice(-60); });
|
|
128
145
|
// Controls by kind, with the look that should be the same wherever the kind is used.
|
|
129
146
|
for (const el of all) {
|
|
130
147
|
const tag = el.tagName.toLowerCase(), f = el;
|
|
@@ -263,15 +280,17 @@ export async function run(r) {
|
|
|
263
280
|
r.record({ suite: S, where: 'Jev', check: "Jev's look at each screen, menu and dialog", status: 'info', detail: `stopped at ${where}: ${e.message}` });
|
|
264
281
|
}
|
|
265
282
|
};
|
|
266
|
-
/** One finding per measured check; the problems also go to audit.json.
|
|
283
|
+
/** One finding per measured check; the problems also go to audit.json. With marks on, a check that knows its
|
|
284
|
+
* elements gets a marked screenshot of the page as it was measured (a menu still open, this viewport), put first. */
|
|
267
285
|
const emit = async (page, screen, view, where, problems, shots) => {
|
|
268
286
|
const bad = Object.values(problems).some((l) => l.length);
|
|
269
287
|
const shot = `${r.dir}/shots/audit-${slug(where)}.png`;
|
|
270
288
|
if (bad && !shots)
|
|
271
289
|
await page.screenshot({ path: shot });
|
|
272
290
|
for (const [check, list] of Object.entries(problems)) {
|
|
273
|
-
|
|
274
|
-
|
|
291
|
+
const status = !list.length ? 'pass' : WARN.has(check) ? 'warn' : 'fail', detail = list.length ? `${list.length}: ${list.slice(0, 5).join('; ')}` : undefined;
|
|
292
|
+
const drawn = list.length && r.cfg.marks && MARKS[check] ? await marked(r, page, `audit ${where} ${check}`, { status, title: check, detail: `${where} · ${detail}` }, [{ target: `[data-tapcheck-mark-${MARKS[check]}]` }]) : undefined;
|
|
293
|
+
r.record({ suite: S, where, check, status, detail, evidence: list.length ? [...(drawn ? [drawn] : []), ...(shots ?? [shot])] : undefined });
|
|
275
294
|
}
|
|
276
295
|
screen.views[view] = Object.fromEntries(Object.entries(problems).filter(([, l]) => l.length));
|
|
277
296
|
};
|
|
@@ -305,10 +324,11 @@ export async function run(r) {
|
|
|
305
324
|
for (const [i, label] of (await openers(page)).entries()) {
|
|
306
325
|
if (!label || opened >= MAX_POPUPS)
|
|
307
326
|
continue;
|
|
308
|
-
const
|
|
327
|
+
const at = (u) => (hashRoute(t.path) ? u : u.split('#')[0]); // on a hash-routed screen a new hash is another screen
|
|
328
|
+
const home = at(page.url());
|
|
309
329
|
await page.locator(`[data-tapcheck-opener="${i}"]`).click({ timeout: 2000 }).catch(() => { });
|
|
310
330
|
await page.waitForTimeout(300);
|
|
311
|
-
const found = page.url()
|
|
331
|
+
const found = at(page.url()) === home && await page.evaluate((POPUP) => {
|
|
312
332
|
const p = [...document.querySelectorAll(POPUP)].filter((el) => el.getClientRects().length > 0).at(-1);
|
|
313
333
|
p?.setAttribute('data-tapcheck-popup', '');
|
|
314
334
|
return p ? p.getAttribute('role') ?? p.tagName.toLowerCase() : '';
|
|
@@ -325,7 +345,7 @@ export async function run(r) {
|
|
|
325
345
|
await page.keyboard.press('Escape').catch(() => { });
|
|
326
346
|
await page.waitForTimeout(150);
|
|
327
347
|
// Still open, or the click went somewhere else: start again from the screen.
|
|
328
|
-
if (page.url()
|
|
348
|
+
if (at(page.url()) !== home || await page.evaluate((POPUP) => [...document.querySelectorAll(POPUP)].some((el) => el.getClientRects().length > 0), POPUP)) {
|
|
329
349
|
await open(r, page, t.path);
|
|
330
350
|
await openers(page);
|
|
331
351
|
}
|
package/dist/suites/crawl.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* missed-routes.json.
|
|
9
9
|
*/
|
|
10
10
|
import { writeFileSync } from 'node:fs';
|
|
11
|
-
import { abs, context, facts,
|
|
11
|
+
import { abs, context, facts, here, host, load, marked, signedIn, watch } from '../browser.js';
|
|
12
12
|
import { coverage, hasParams, routes } from '../routes.js';
|
|
13
13
|
const SLOW_MS = 3000;
|
|
14
14
|
function listen(r, page, current) {
|
|
@@ -71,35 +71,38 @@ export async function run(r) {
|
|
|
71
71
|
errors.length = 0;
|
|
72
72
|
const t0 = Date.now();
|
|
73
73
|
let download = false; // a link to a file (a PDF invoice): Playwright downloads it and goto throws
|
|
74
|
-
const res = await page
|
|
74
|
+
const res = await load(page, abs(r, path)).catch((e) => { download = /Download is starting/.test(e.message); return null; });
|
|
75
75
|
if (download)
|
|
76
76
|
continue; // not a page; "in-app links answer" still checks that it answers
|
|
77
77
|
await page.waitForLoadState('networkidle', { timeout: 15_000 }).catch(() => { });
|
|
78
78
|
const ms = Date.now() - t0;
|
|
79
|
-
const finalPath =
|
|
79
|
+
const finalPath = here(page.url(), path);
|
|
80
80
|
const st = res?.status() ?? 0;
|
|
81
81
|
// A route from the list that isn't this side's (refused, sent to sign in) or isn't a page (a download): not a finding.
|
|
82
82
|
if (route && (st === 0 || [401, 403, 404, 405].includes(st) || (r.cfg.loginPaths.test(finalPath) && !r.cfg.loginPaths.test(path))))
|
|
83
83
|
continue;
|
|
84
|
-
|
|
84
|
+
await signedIn(r, page, path);
|
|
85
85
|
const f = await facts(page).catch(() => null);
|
|
86
86
|
const links = [...new Set((f?.controls ?? []).map((c) => c.href).filter((h) => !!h && host(h) === own)
|
|
87
|
-
.map((h) => { const u = new URL(h); return u.pathname + u.search; }))];
|
|
87
|
+
.map((h) => { const u = new URL(h); return u.pathname + u.search + (/^#!?\//.test(u.hash) ? u.hash : ''); }))]; // #/orders is a route, #section a place on the page
|
|
88
88
|
r.crawl.pages.push({ path, status: st, finalPath, ms, errors: [...errors], links });
|
|
89
89
|
visits++;
|
|
90
90
|
const where = path;
|
|
91
|
-
r.record({ suite: S, where, check: 'page answers', status: st >= 200 && st < 400 ? 'pass' : 'fail', detail: `${st}${finalPath !== path.split('?')[0] ? ` → ${finalPath}` : ''}` });
|
|
91
|
+
r.record({ suite: S, where, check: 'page answers', status: st >= 200 && st < 400 ? 'pass' : 'fail', detail: `${st}${finalPath !== path.split('?')[0].replace(/#$/, '') ? ` → ${finalPath}` : ''}` });
|
|
92
92
|
r.record({ suite: S, where, check: `loads under ${SLOW_MS} ms`, status: ms < SLOW_MS ? 'pass' : 'warn', detail: `${ms} ms` });
|
|
93
93
|
r.record({ suite: S, where, check: 'no console or page errors', status: errors.length ? 'fail' : 'pass', detail: errors.slice(0, 3).join(' | ') || undefined });
|
|
94
|
+
// MARK=1: the elements a failing check tagged while it measured, boxed on the page as it is now.
|
|
95
|
+
const shot = async (check, detail, tag) => { const m = r.cfg.marks ? await marked(r, page, `crawl ${where} ${check}`, { status: 'fail', title: check, detail: `${where} · ${detail}` }, [{ target: `[data-tapcheck-mark-${tag}]` }]) : undefined; return m ? [m] : undefined; };
|
|
94
96
|
if (f?.brokenImages.length)
|
|
95
|
-
r.record({ suite: S, where, check: 'images load', status: 'fail', detail: f.brokenImages.slice(0, 5).join(', ') });
|
|
97
|
+
r.record({ suite: S, where, check: 'images load', status: 'fail', detail: f.brokenImages.slice(0, 5).join(', '), evidence: await shot('images load', f.brokenImages.slice(0, 5).join(', '), 'broken') });
|
|
96
98
|
const unlabelled = await page.$$eval('input:not([type=hidden]):not([type=submit]):not([type=button]), select, textarea', (els) => els.filter((el) => {
|
|
97
99
|
const e = el;
|
|
98
100
|
if (e.offsetParent === null || el.closest('[aria-hidden=true]'))
|
|
99
101
|
return false;
|
|
100
102
|
return !(e.labels?.length || e.getAttribute('aria-label') || e.getAttribute('aria-labelledby') || e.title);
|
|
101
|
-
}).map((el) => el.name || el.id || el.tagName.toLowerCase())).catch(() => []);
|
|
102
|
-
r.record({ suite: S, where, check: 'form fields labelled', status: unlabelled.length ? 'fail' : 'pass', detail: unlabelled.slice(0, 6).join(', ') || undefined
|
|
103
|
+
}).map((el) => { el.setAttribute('data-tapcheck-mark-unlabelled', 'no label'); return el.name || el.id || el.tagName.toLowerCase(); })).catch(() => []);
|
|
104
|
+
r.record({ suite: S, where, check: 'form fields labelled', status: unlabelled.length ? 'fail' : 'pass', detail: unlabelled.slice(0, 6).join(', ') || undefined,
|
|
105
|
+
evidence: unlabelled.length ? await shot('form fields labelled', unlabelled.slice(0, 6).join(', '), 'unlabelled') : undefined });
|
|
103
106
|
for (const l of links) {
|
|
104
107
|
if (skip.test(l.split('?')[0]))
|
|
105
108
|
continue;
|