@entifix/testing-e2e 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -63,6 +63,7 @@ import { resolveE2eProfile, isMockProfile, requireLiveUrl } from '@entifix/testi
63
63
  import { entityBackendHandlers, configurationHandler } from '@entifix/testing-e2e/fixtures';
64
64
  import { defineServiceE2e } from '@entifix/testing-e2e/service';
65
65
  import { defineEntifixE2eConfig, defineEntifixE2eTest, EntityTablePage } from '@entifix/testing-e2e/playwright';
66
+ import { expectNoNewA11yViolations, walkKeyboard, expectFocusKept } from '@entifix/testing-e2e/a11y';
66
67
  ```
67
68
 
68
69
  `.` carries no Playwright, no msw and no vitest, so a consumer pulls only what
@@ -99,6 +100,38 @@ Two stubs are always needed, not one: the entity endpoint _and_ the app's
99
100
  latter before they can issue the former. `configurationHandler` exists so that
100
101
  is not something each suite has to remember.
101
102
 
103
+ ### The accessibility gate on a screen (Playwright)
104
+
105
+ `@entifix/testing-e2e/a11y` needs `@axe-core/playwright` (an optional peer).
106
+
107
+ ```ts
108
+ // After the screen has rendered what it is for:
109
+ await expectNoNewA11yViolations(page, { screen: 'customers', baselinePath });
110
+ await walkKeyboard(page, { skipLink: true, mainIndexMax: 3 });
111
+
112
+ // After each write:
113
+ await page.getByRole('button', { name: 'Guardar' }).click();
114
+ await expectFocusKept(page);
115
+ ```
116
+
117
+ - **`expectNoNewA11yViolations`** runs axe against WCAG 2.2 AA and fails on a
118
+ serious or critical fingerprint the baseline does not accept, and on an
119
+ accepted one that is no longer there. Moderate and minor findings become test
120
+ annotations. `A11Y_BASELINE=update` rewrites the screen's entries — owners
121
+ kept, a new entry's left empty for a person to fill with the issue that
122
+ removes it; `unownedEntries(baseline)` lets a spec refuse an empty one.
123
+ - **`walkKeyboard`** tabs from the top and fails on a missing skip link, a first
124
+ stop inside `main` past `mainIndexMax`, a stop with no visible indicator or
125
+ with something covering it, and a stop that jumps back more than a row.
126
+ - **`expectFocusKept`** fails when focus fell back to `<body>`. A write known to
127
+ drop it passes `{ lostUntil: 'owner/repo#N' }`, and the check then fails once
128
+ focus is kept, so the fix has to remove the mark.
129
+
130
+ A baseline only shrinks: switch the gate on with today's fingerprints, each
131
+ against its issue, and tighten `mainIndexMax` the same way. The pure halves —
132
+ `findingsOf`, `compareWithBaseline`, `updateBaseline` and `assessWalk` — are
133
+ exported for a host that drives a browser some other way.
134
+
102
135
  ### Service e2e (Vitest)
103
136
 
104
137
  ```ts
@@ -0,0 +1,21 @@
1
+ import { type Page } from '@playwright/test';
2
+ export interface A11yGateOptions {
3
+ /** The screen's name in every fingerprint: stable, and one per screen. */
4
+ readonly screen: string;
5
+ /** The committed baseline, shared by every screen of one e2e project. */
6
+ readonly baselinePath: string;
7
+ /** Selectors axe skips, for third-party widgets the host does not render. */
8
+ readonly exclude?: readonly string[];
9
+ }
10
+ /**
11
+ * Runs axe over the page against WCAG 2.2 AA and fails on a serious or
12
+ * critical violation the baseline does not accept, or on an accepted one that
13
+ * is gone. Moderate and minor findings are attached to the test as an
14
+ * annotation and never fail it.
15
+ *
16
+ * With `A11Y_BASELINE=update` it rewrites this screen's entries instead: an
17
+ * owner is kept where the fingerprint survived and left empty where it is new,
18
+ * for a person to fill with the issue that removes it.
19
+ */
20
+ export declare function expectNoNewA11yViolations(page: Page, { screen, baselinePath, exclude }: A11yGateOptions): Promise<void>;
21
+ //# sourceMappingURL=axe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axe.d.ts","sourceRoot":"","sources":["../../src/a11y/axe.ts"],"names":[],"mappings":"AAUA,OAAO,EAAU,KAAK,IAAI,EAAQ,MAAM,kBAAkB,CAAC;AAY3D,MAAM,WAAW,eAAe;IAC9B,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AA+BD;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,IAAI,EACV,EAAE,MAAM,EAAE,YAAY,EAAE,OAAY,EAAE,EAAE,eAAe,GACtD,OAAO,CAAC,IAAI,CAAC,CAiCf"}
@@ -0,0 +1,70 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmdirSync, writeFileSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
3
+ import AxeBuilder from '@axe-core/playwright';
4
+ import { expect, test } from '@playwright/test';
5
+ import { compareWithBaseline, describeVerdict, findingsOf, updateBaseline, WCAG_22_AA_TAGS } from './baseline.js';
6
+ const readBaseline = (path)=>existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : {};
7
+ /**
8
+ * Runs `write` while holding a directory lock beside `path`. Playwright runs
9
+ * screens in parallel workers, and two of them rewriting one baseline at once
10
+ * would each drop the other's screen.
11
+ */ const underLock = (path, write)=>{
12
+ const lock = `${path}.lock`;
13
+ const wait = new Int32Array(new SharedArrayBuffer(4));
14
+ for(let attempt = 0;; attempt += 1){
15
+ try {
16
+ mkdirSync(lock);
17
+ break;
18
+ } catch (error) {
19
+ if (attempt > 400) throw error;
20
+ Atomics.wait(wait, 0, 0, 25);
21
+ }
22
+ }
23
+ try {
24
+ write();
25
+ } finally{
26
+ rmdirSync(lock);
27
+ }
28
+ };
29
+ /**
30
+ * Runs axe over the page against WCAG 2.2 AA and fails on a serious or
31
+ * critical violation the baseline does not accept, or on an accepted one that
32
+ * is gone. Moderate and minor findings are attached to the test as an
33
+ * annotation and never fail it.
34
+ *
35
+ * With `A11Y_BASELINE=update` it rewrites this screen's entries instead: an
36
+ * owner is kept where the fingerprint survived and left empty where it is new,
37
+ * for a person to fill with the issue that removes it.
38
+ */ export async function expectNoNewA11yViolations(page, { screen, baselinePath, exclude = [] }) {
39
+ let builder = new AxeBuilder({
40
+ page
41
+ }).withTags([
42
+ ...WCAG_22_AA_TAGS
43
+ ]);
44
+ for (const selector of exclude)builder = builder.exclude(selector);
45
+ const results = await builder.analyze();
46
+ const findings = findingsOf(screen, results.violations);
47
+ if (process.env['A11Y_BASELINE'] === 'update') {
48
+ underLock(baselinePath, ()=>{
49
+ const next = updateBaseline(screen, findings, readBaseline(baselinePath));
50
+ mkdirSync(dirname(baselinePath), {
51
+ recursive: true
52
+ });
53
+ writeFileSync(baselinePath, `${JSON.stringify(next, null, 2)}\n`);
54
+ });
55
+ return;
56
+ }
57
+ const verdict = compareWithBaseline(screen, findings, readBaseline(baselinePath));
58
+ for (const finding of verdict.reported){
59
+ test.info().annotations.push({
60
+ type: `a11y ${finding.impact}`,
61
+ description: `${finding.fingerprint} — ${finding.help}`
62
+ });
63
+ }
64
+ expect([
65
+ ...verdict.added.map((finding)=>finding.fingerprint),
66
+ ...verdict.stale
67
+ ], describeVerdict(screen, verdict)).toEqual([]);
68
+ }
69
+
70
+ //# sourceMappingURL=axe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/a11y/axe.ts"],"sourcesContent":["import {\n existsSync,\n mkdirSync,\n readFileSync,\n rmdirSync,\n writeFileSync,\n} from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport AxeBuilder from '@axe-core/playwright';\nimport { expect, type Page, test } from '@playwright/test';\n\nimport {\n type A11yBaseline,\n type A11yViolation,\n compareWithBaseline,\n describeVerdict,\n findingsOf,\n updateBaseline,\n WCAG_22_AA_TAGS,\n} from './baseline.js';\n\nexport interface A11yGateOptions {\n /** The screen's name in every fingerprint: stable, and one per screen. */\n readonly screen: string;\n /** The committed baseline, shared by every screen of one e2e project. */\n readonly baselinePath: string;\n /** Selectors axe skips, for third-party widgets the host does not render. */\n readonly exclude?: readonly string[];\n}\n\nconst readBaseline = (path: string): A11yBaseline =>\n existsSync(path)\n ? (JSON.parse(readFileSync(path, 'utf8')) as A11yBaseline)\n : {};\n\n/**\n * Runs `write` while holding a directory lock beside `path`. Playwright runs\n * screens in parallel workers, and two of them rewriting one baseline at once\n * would each drop the other's screen.\n */\nconst underLock = (path: string, write: () => void) => {\n const lock = `${path}.lock`;\n const wait = new Int32Array(new SharedArrayBuffer(4));\n for (let attempt = 0; ; attempt += 1) {\n try {\n mkdirSync(lock);\n break;\n } catch (error) {\n if (attempt > 400) throw error;\n Atomics.wait(wait, 0, 0, 25);\n }\n }\n try {\n write();\n } finally {\n rmdirSync(lock);\n }\n};\n\n/**\n * Runs axe over the page against WCAG 2.2 AA and fails on a serious or\n * critical violation the baseline does not accept, or on an accepted one that\n * is gone. Moderate and minor findings are attached to the test as an\n * annotation and never fail it.\n *\n * With `A11Y_BASELINE=update` it rewrites this screen's entries instead: an\n * owner is kept where the fingerprint survived and left empty where it is new,\n * for a person to fill with the issue that removes it.\n */\nexport async function expectNoNewA11yViolations(\n page: Page,\n { screen, baselinePath, exclude = [] }: A11yGateOptions,\n): Promise<void> {\n let builder = new AxeBuilder({ page }).withTags([...WCAG_22_AA_TAGS]);\n for (const selector of exclude) builder = builder.exclude(selector);\n const results = await builder.analyze();\n const findings = findingsOf(\n screen,\n results.violations as unknown as readonly A11yViolation[],\n );\n\n if (process.env['A11Y_BASELINE'] === 'update') {\n underLock(baselinePath, () => {\n const next = updateBaseline(screen, findings, readBaseline(baselinePath));\n mkdirSync(dirname(baselinePath), { recursive: true });\n writeFileSync(baselinePath, `${JSON.stringify(next, null, 2)}\\n`);\n });\n return;\n }\n\n const verdict = compareWithBaseline(\n screen,\n findings,\n readBaseline(baselinePath),\n );\n for (const finding of verdict.reported) {\n test.info().annotations.push({\n type: `a11y ${finding.impact}`,\n description: `${finding.fingerprint} — ${finding.help}`,\n });\n }\n expect(\n [...verdict.added.map(finding => finding.fingerprint), ...verdict.stale],\n describeVerdict(screen, verdict),\n ).toEqual([]);\n}\n"],"names":["existsSync","mkdirSync","readFileSync","rmdirSync","writeFileSync","dirname","AxeBuilder","expect","test","compareWithBaseline","describeVerdict","findingsOf","updateBaseline","WCAG_22_AA_TAGS","readBaseline","path","JSON","parse","underLock","write","lock","wait","Int32Array","SharedArrayBuffer","attempt","error","Atomics","expectNoNewA11yViolations","page","screen","baselinePath","exclude","builder","withTags","selector","results","analyze","findings","violations","process","env","next","recursive","stringify","verdict","finding","reported","info","annotations","push","type","impact","description","fingerprint","help","added","map","stale","toEqual"],"mappings":"AAAA,SACEA,UAAU,EACVC,SAAS,EACTC,YAAY,EACZC,SAAS,EACTC,aAAa,QACR,UAAU;AACjB,SAASC,OAAO,QAAQ,YAAY;AAEpC,OAAOC,gBAAgB,uBAAuB;AAC9C,SAASC,MAAM,EAAaC,IAAI,QAAQ,mBAAmB;AAE3D,SAGEC,mBAAmB,EACnBC,eAAe,EACfC,UAAU,EACVC,cAAc,EACdC,eAAe,QACV,gBAAgB;AAWvB,MAAMC,eAAe,CAACC,OACpBf,WAAWe,QACNC,KAAKC,KAAK,CAACf,aAAaa,MAAM,WAC/B,CAAC;AAEP;;;;CAIC,GACD,MAAMG,YAAY,CAACH,MAAcI;IAC/B,MAAMC,OAAO,GAAGL,KAAK,KAAK,CAAC;IAC3B,MAAMM,OAAO,IAAIC,WAAW,IAAIC,kBAAkB;IAClD,IAAK,IAAIC,UAAU,IAAKA,WAAW,EAAG;QACpC,IAAI;YACFvB,UAAUmB;YACV;QACF,EAAE,OAAOK,OAAO;YACd,IAAID,UAAU,KAAK,MAAMC;YACzBC,QAAQL,IAAI,CAACA,MAAM,GAAG,GAAG;QAC3B;IACF;IACA,IAAI;QACFF;IACF,SAAU;QACRhB,UAAUiB;IACZ;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,eAAeO,0BACpBC,IAAU,EACV,EAAEC,MAAM,EAAEC,YAAY,EAAEC,UAAU,EAAE,EAAmB;IAEvD,IAAIC,UAAU,IAAI1B,WAAW;QAAEsB;IAAK,GAAGK,QAAQ,CAAC;WAAIpB;KAAgB;IACpE,KAAK,MAAMqB,YAAYH,QAASC,UAAUA,QAAQD,OAAO,CAACG;IAC1D,MAAMC,UAAU,MAAMH,QAAQI,OAAO;IACrC,MAAMC,WAAW1B,WACfkB,QACAM,QAAQG,UAAU;IAGpB,IAAIC,QAAQC,GAAG,CAAC,gBAAgB,KAAK,UAAU;QAC7CtB,UAAUY,cAAc;YACtB,MAAMW,OAAO7B,eAAeiB,QAAQQ,UAAUvB,aAAagB;YAC3D7B,UAAUI,QAAQyB,eAAe;gBAAEY,WAAW;YAAK;YACnDtC,cAAc0B,cAAc,GAAGd,KAAK2B,SAAS,CAACF,MAAM,MAAM,GAAG,EAAE,CAAC;QAClE;QACA;IACF;IAEA,MAAMG,UAAUnC,oBACdoB,QACAQ,UACAvB,aAAagB;IAEf,KAAK,MAAMe,WAAWD,QAAQE,QAAQ,CAAE;QACtCtC,KAAKuC,IAAI,GAAGC,WAAW,CAACC,IAAI,CAAC;YAC3BC,MAAM,CAAC,KAAK,EAAEL,QAAQM,MAAM,EAAE;YAC9BC,aAAa,GAAGP,QAAQQ,WAAW,CAAC,GAAG,EAAER,QAAQS,IAAI,EAAE;QACzD;IACF;IACA/C,OACE;WAAIqC,QAAQW,KAAK,CAACC,GAAG,CAACX,CAAAA,UAAWA,QAAQQ,WAAW;WAAMT,QAAQa,KAAK;KAAC,EACxE/C,gBAAgBmB,QAAQe,UACxBc,OAAO,CAAC,EAAE;AACd"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The screen-level accessibility ratchet, as data: what axe found on one
3
+ * screen, reduced to fingerprints that survive a re-render, compared with what
4
+ * a committed baseline already accepts.
5
+ *
6
+ * A baseline maps each accepted fingerprint to the issue that removes it, so a
7
+ * host can switch the gate on with a backlog and the backlog can only shrink:
8
+ * a new serious or critical fingerprint fails, and so does an accepted one
9
+ * that is no longer there, which is how a fix is made to delete its entry.
10
+ */
11
+ /** axe's impact levels, least to most severe. */
12
+ export type A11yImpact = 'minor' | 'moderate' | 'serious' | 'critical';
13
+ /** The part of an axe node this module reads. */
14
+ export interface A11yNodeResult {
15
+ readonly target: readonly unknown[];
16
+ }
17
+ /** The part of an axe violation this module reads. */
18
+ export interface A11yViolation {
19
+ readonly id: string;
20
+ readonly impact?: A11yImpact | null;
21
+ readonly help?: string;
22
+ readonly nodes: readonly A11yNodeResult[];
23
+ }
24
+ /** One fingerprint found on a screen, with the severity it was found at. */
25
+ export interface A11yFinding {
26
+ readonly fingerprint: string;
27
+ readonly impact: A11yImpact;
28
+ readonly help: string;
29
+ }
30
+ /** Accepted fingerprints, each against the issue that removes it. */
31
+ export type A11yBaseline = Readonly<Record<string, string>>;
32
+ /** What a gate run decides for one screen. */
33
+ export interface A11yVerdict {
34
+ /** Serious or critical, and not in the baseline: these fail. */
35
+ readonly added: readonly A11yFinding[];
36
+ /** In the baseline for this screen, and no longer found: these fail too. */
37
+ readonly stale: readonly string[];
38
+ /** Moderate or minor: reported, never failing. */
39
+ readonly reported: readonly A11yFinding[];
40
+ }
41
+ /** The levels that fail the gate (ADR 0024). */
42
+ export declare const GATED: ReadonlySet<A11yImpact>;
43
+ /** The rule tags the gate runs: WCAG 2.2 AA, with 2.1's A level. */
44
+ export declare const WCAG_22_AA_TAGS: readonly ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"];
45
+ /**
46
+ * A selector stable across renders and across axe's own choices: generated ids
47
+ * written `#generated-id`; every `:nth-child(k)` and `:nth-of-type(k)` written
48
+ * with `n`, so a run of identical siblings is one fingerprint rather than one
49
+ * per row; and each compound's classes and attributes sorted, because axe
50
+ * orders them by how unique they happen to be on the page at the time.
51
+ */
52
+ export declare const normalizeTarget: (target: readonly unknown[]) => string;
53
+ /** `rule|target|screen`: the identity of one failing node. */
54
+ export declare const fingerprintOf: (rule: string, target: string, screen: string) => string;
55
+ /** The screen a fingerprint belongs to. */
56
+ export declare const screenOf: (fingerprint: string) => string;
57
+ /** Every distinct fingerprint in `violations`, at its rule's impact. */
58
+ export declare const findingsOf: (screen: string, violations: readonly A11yViolation[]) => A11yFinding[];
59
+ /** Judges one screen's findings against the baseline. */
60
+ export declare const compareWithBaseline: (screen: string, findings: readonly A11yFinding[], baseline: A11yBaseline) => A11yVerdict;
61
+ /**
62
+ * The baseline with this screen's entries replaced by what was found: owners
63
+ * kept for fingerprints still present, and an empty owner for a new one, which
64
+ * {@link unownedEntries} refuses until a person names its issue.
65
+ */
66
+ export declare const updateBaseline: (screen: string, findings: readonly A11yFinding[], baseline: A11yBaseline) => A11yBaseline;
67
+ /** An issue reference in the form GitHub links across repositories. */
68
+ export declare const ISSUE_REFERENCE: RegExp;
69
+ /** Every entry whose owner is not an `owner/repo#N` issue reference. */
70
+ export declare const unownedEntries: (baseline: A11yBaseline) => string[];
71
+ /** A failure message that names every fingerprint and what to do about it. */
72
+ export declare const describeVerdict: (screen: string, verdict: A11yVerdict) => string;
73
+ //# sourceMappingURL=baseline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseline.d.ts","sourceRoot":"","sources":["../../src/a11y/baseline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,iDAAiD;AACjD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAEvE,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CACrC;AAED,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;CAC3C;AAED,4EAA4E;AAC5E,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,M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cAAc,GAAI,UAAU,YAAY,KAAG,MAAM,EAGtB,CAAC;AAEzC,8EAA8E;AAC9E,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,SAAS,WAAW,WAUtD,CAAC"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The screen-level accessibility ratchet, as data: what axe found on one
3
+ * screen, reduced to fingerprints that survive a re-render, compared with what
4
+ * a committed baseline already accepts.
5
+ *
6
+ * A baseline maps each accepted fingerprint to the issue that removes it, so a
7
+ * host can switch the gate on with a backlog and the backlog can only shrink:
8
+ * a new serious or critical fingerprint fails, and so does an accepted one
9
+ * that is no longer there, which is how a fix is made to delete its entry.
10
+ */ /** axe's impact levels, least to most severe. */ /** The levels that fail the gate (ADR 0024). */ export const GATED = new Set([
11
+ 'serious',
12
+ 'critical'
13
+ ]);
14
+ /** The rule tags the gate runs: WCAG 2.2 AA, with 2.1's A level. */ export const WCAG_22_AA_TAGS = [
15
+ 'wcag2a',
16
+ 'wcag2aa',
17
+ 'wcag21a',
18
+ 'wcag21aa',
19
+ 'wcag22aa'
20
+ ];
21
+ /**
22
+ * Ids a framework mints per render: React's `useId` (`:r1:`, `«r1»`, and their
23
+ * CSS-escaped forms), Headless UI's `headlessui-<part>-<n>` and Radix's
24
+ * `radix-…`. Each is written `#generated-id`: the node is still there, its name is not.
25
+ */ const GENERATED_ID = /#(?:headlessui-[\w-]+|(?:\\:|:|«)r[\w]+(?:\\:|:|»)[\w-]*|radix-[\w:-]+)/g;
26
+ /**
27
+ * Splits `text` wherever `isBoundary` says a new token starts, ignoring
28
+ * anything inside brackets, parentheses or quotes and any escaped character —
29
+ * `[title="Open in a new tab"]` and Tailwind's `.bg-surface\/60` are one
30
+ * token each.
31
+ */ const tokenize = (text, isBoundary)=>{
32
+ const tokens = [];
33
+ let current = '';
34
+ let depth = 0;
35
+ let quote = '';
36
+ for(let at = 0; at < text.length; at += 1){
37
+ const char = text[at];
38
+ if (char === '\\') {
39
+ var _text_;
40
+ current += char + ((_text_ = text[at + 1]) != null ? _text_ : '');
41
+ at += 1;
42
+ continue;
43
+ }
44
+ if (quote === '' && depth === 0 && current !== '' && isBoundary(char, current.at(-1))) {
45
+ tokens.push(current);
46
+ current = '';
47
+ }
48
+ if (quote !== '') {
49
+ if (char === quote) quote = '';
50
+ } else if (char === '"' || char === "'") {
51
+ quote = char;
52
+ } else if (char === '[' || char === '(') {
53
+ depth += 1;
54
+ } else if (char === ']' || char === ')') {
55
+ depth -= 1;
56
+ }
57
+ current += char;
58
+ }
59
+ tokens.push(current);
60
+ return tokens;
61
+ };
62
+ const RANK = {
63
+ '#': 1,
64
+ '.': 2,
65
+ '[': 3,
66
+ ':': 4
67
+ };
68
+ /**
69
+ * One compound selector with its ids, classes and attributes in a fixed
70
+ * order. Pseudo-classes keep theirs: `:hover:not(…)` reads differently from
71
+ * `:not(…):hover` even where the engine treats them alike.
72
+ */ const canonicalCompound = (compound)=>tokenize(compound, (char, previous)=>char in RANK && previous !== ':').map((part)=>{
73
+ var _RANK_part_;
74
+ return {
75
+ part,
76
+ rank: (_RANK_part_ = RANK[part[0]]) != null ? _RANK_part_ : 0
77
+ };
78
+ }).sort((a, b)=>a.rank - b.rank || (a.rank === 4 ? 0 : a.part.localeCompare(b.part))).map(({ part })=>part).join('');
79
+ /** A complex selector, one canonical compound at a time. */ const canonicalSelector = (selector)=>tokenize(selector.trim(), (char)=>/[\s>+~]/.test(char)).map((token)=>token.trim()).filter((token)=>token !== '').map((token)=>/^[>+~]$/.test(token) ? token : canonicalCompound(token)).join(' ');
80
+ /**
81
+ * A selector stable across renders and across axe's own choices: generated ids
82
+ * written `#generated-id`; every `:nth-child(k)` and `:nth-of-type(k)` written
83
+ * with `n`, so a run of identical siblings is one fingerprint rather than one
84
+ * per row; and each compound's classes and attributes sorted, because axe
85
+ * orders them by how unique they happen to be on the page at the time.
86
+ */ export const normalizeTarget = (target)=>target.flatMap((part)=>Array.isArray(part) ? part : [
87
+ part
88
+ ]).map((part)=>canonicalSelector(String(part).replace(GENERATED_ID, '#generated-id').replace(/:nth-child\(\d+\)/g, ':nth-child(n)').replace(/:nth-of-type\(\d+\)/g, ':nth-of-type(n)'))).join(' >>> ');
89
+ /** `rule|target|screen`: the identity of one failing node. */ export const fingerprintOf = (rule, target, screen)=>`${rule}|${target}|${screen}`;
90
+ /** The screen a fingerprint belongs to. */ export const screenOf = (fingerprint)=>fingerprint.slice(fingerprint.lastIndexOf('|') + 1);
91
+ /** Every distinct fingerprint in `violations`, at its rule's impact. */ export const findingsOf = (screen, violations)=>{
92
+ const found = new Map();
93
+ for (const violation of violations){
94
+ for (const node of violation.nodes){
95
+ var _violation_impact, _violation_help;
96
+ const fingerprint = fingerprintOf(violation.id, normalizeTarget(node.target), screen);
97
+ found.set(fingerprint, {
98
+ fingerprint,
99
+ impact: (_violation_impact = violation.impact) != null ? _violation_impact : 'minor',
100
+ help: (_violation_help = violation.help) != null ? _violation_help : violation.id
101
+ });
102
+ }
103
+ }
104
+ return [
105
+ ...found.values()
106
+ ].sort((a, b)=>a.fingerprint.localeCompare(b.fingerprint));
107
+ };
108
+ /** Judges one screen's findings against the baseline. */ export const compareWithBaseline = (screen, findings, baseline)=>{
109
+ const gated = findings.filter((finding)=>GATED.has(finding.impact));
110
+ const present = new Set(gated.map((finding)=>finding.fingerprint));
111
+ return {
112
+ added: gated.filter((finding)=>!(finding.fingerprint in baseline)),
113
+ stale: Object.keys(baseline).filter((fingerprint)=>screenOf(fingerprint) === screen).filter((fingerprint)=>!present.has(fingerprint)).sort(),
114
+ reported: findings.filter((finding)=>!GATED.has(finding.impact))
115
+ };
116
+ };
117
+ /**
118
+ * The baseline with this screen's entries replaced by what was found: owners
119
+ * kept for fingerprints still present, and an empty owner for a new one, which
120
+ * {@link unownedEntries} refuses until a person names its issue.
121
+ */ export const updateBaseline = (screen, findings, baseline)=>{
122
+ const next = {};
123
+ for (const [fingerprint, owner] of Object.entries(baseline)){
124
+ if (screenOf(fingerprint) !== screen) next[fingerprint] = owner;
125
+ }
126
+ for (const finding of findings){
127
+ if (GATED.has(finding.impact)) {
128
+ var _baseline_finding_fingerprint;
129
+ next[finding.fingerprint] = (_baseline_finding_fingerprint = baseline[finding.fingerprint]) != null ? _baseline_finding_fingerprint : '';
130
+ }
131
+ }
132
+ return Object.fromEntries(Object.entries(next).sort(([a], [b])=>a.localeCompare(b)));
133
+ };
134
+ /** An issue reference in the form GitHub links across repositories. */ export const ISSUE_REFERENCE = /^[\w.-]+\/[\w.-]+#\d+$/;
135
+ /** Every entry whose owner is not an `owner/repo#N` issue reference. */ export const unownedEntries = (baseline)=>Object.entries(baseline).filter(([, owner])=>!ISSUE_REFERENCE.test(owner)).map(([fingerprint])=>fingerprint);
136
+ /** A failure message that names every fingerprint and what to do about it. */ export const describeVerdict = (screen, verdict)=>[
137
+ ...verdict.added.map((finding)=>`${screen}: new ${finding.impact} violation ${finding.fingerprint} — ${finding.help}`),
138
+ ...verdict.stale.map((fingerprint)=>`${screen}: ${fingerprint} is in the baseline but no longer found — delete its entry`)
139
+ ].join('\n');
140
+
141
+ //# sourceMappingURL=baseline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/a11y/baseline.ts"],"sourcesContent":["/**\n * The screen-level accessibility ratchet, as data: what axe found on one\n * screen, reduced to fingerprints that survive a re-render, compared with what\n * a committed baseline already accepts.\n *\n * A baseline maps each accepted fingerprint to the issue that removes it, so a\n * host can switch the gate on with a backlog and the backlog can only shrink:\n * a new serious or critical fingerprint fails, and so does an accepted one\n * that is no longer there, which is how a fix is made to delete its entry.\n */\n\n/** axe's impact levels, least to most severe. */\nexport type A11yImpact = 'minor' | 'moderate' | 'serious' | 'critical';\n\n/** The part of an axe node this module reads. */\nexport interface A11yNodeResult {\n readonly target: readonly unknown[];\n}\n\n/** The part of an axe violation this module reads. */\nexport interface A11yViolation {\n readonly id: string;\n readonly impact?: A11yImpact | null;\n readonly help?: string;\n readonly nodes: readonly A11yNodeResult[];\n}\n\n/** One fingerprint found on a screen, with the severity it was found at. */\nexport interface A11yFinding {\n readonly fingerprint: string;\n readonly impact: A11yImpact;\n readonly help: string;\n}\n\n/** Accepted fingerprints, each against the issue that removes it. */\nexport type A11yBaseline = Readonly<Record<string, string>>;\n\n/** What a gate run decides for one screen. */\nexport interface A11yVerdict {\n /** Serious or critical, and not in the baseline: these fail. */\n readonly added: readonly A11yFinding[];\n /** In the baseline for this screen, and no longer found: these fail too. */\n readonly stale: readonly string[];\n /** Moderate or minor: reported, never failing. */\n readonly reported: readonly A11yFinding[];\n}\n\n/** The levels that fail the gate (ADR 0024). */\nexport const GATED: ReadonlySet<A11yImpact> = new Set(['serious', 'critical']);\n\n/** The rule tags the gate runs: WCAG 2.2 AA, with 2.1's A level. */\nexport const WCAG_22_AA_TAGS = [\n 'wcag2a',\n 'wcag2aa',\n 'wcag21a',\n 'wcag21aa',\n 'wcag22aa',\n] as const;\n\n/**\n * Ids a framework mints per render: React's `useId` (`:r1:`, `«r1»`, and their\n * CSS-escaped forms), Headless UI's `headlessui-<part>-<n>` and Radix's\n * `radix-…`. Each is written `#generated-id`: the node is still there, its name is not.\n */\nconst GENERATED_ID =\n /#(?:headlessui-[\\w-]+|(?:\\\\:|:|«)r[\\w]+(?:\\\\:|:|»)[\\w-]*|radix-[\\w:-]+)/g;\n\n/**\n * Splits `text` wherever `isBoundary` says a new token starts, ignoring\n * anything inside brackets, parentheses or quotes and any escaped character —\n * `[title=\"Open in a new tab\"]` and Tailwind's `.bg-surface\\/60` are one\n * token each.\n */\nconst tokenize = (\n text: string,\n isBoundary: (char: string, previous: string) => boolean,\n): string[] => {\n const tokens: string[] = [];\n let current = '';\n let depth = 0;\n let quote = '';\n for (let at = 0; at < text.length; at += 1) {\n const char = text[at] as string;\n if (char === '\\\\') {\n current += char + (text[at + 1] ?? '');\n at += 1;\n continue;\n }\n if (\n quote === '' &&\n depth === 0 &&\n current !== '' &&\n isBoundary(char, current.at(-1) as string)\n ) {\n tokens.push(current);\n current = '';\n }\n if (quote !== '') {\n if (char === quote) quote = '';\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === '[' || char === '(') {\n depth += 1;\n } else if (char === ']' || char === ')') {\n depth -= 1;\n }\n current += char;\n }\n tokens.push(current);\n return tokens;\n};\n\nconst RANK: Readonly<Record<string, number>> = {\n '#': 1,\n '.': 2,\n '[': 3,\n ':': 4,\n};\n\n/**\n * One compound selector with its ids, classes and attributes in a fixed\n * order. Pseudo-classes keep theirs: `:hover:not(…)` reads differently from\n * `:not(…):hover` even where the engine treats them alike.\n */\nconst canonicalCompound = (compound: string): string =>\n tokenize(compound, (char, previous) => char in RANK && previous !== ':')\n .map(part => ({ part, rank: RANK[part[0] as string] ?? 0 }))\n .sort(\n (a, b) =>\n a.rank - b.rank || (a.rank === 4 ? 0 : a.part.localeCompare(b.part)),\n )\n .map(({ part }) => part)\n .join('');\n\n/** A complex selector, one canonical compound at a time. */\nconst canonicalSelector = (selector: string): string =>\n tokenize(selector.trim(), char => /[\\s>+~]/.test(char))\n .map(token => token.trim())\n .filter(token => token !== '')\n .map(token => (/^[>+~]$/.test(token) ? token : canonicalCompound(token)))\n .join(' ');\n\n/**\n * A selector stable across renders and across axe's own choices: generated ids\n * written `#generated-id`; every `:nth-child(k)` and `:nth-of-type(k)` written\n * with `n`, so a run of identical siblings is one fingerprint rather than one\n * per row; and each compound's classes and attributes sorted, because axe\n * orders them by how unique they happen to be on the page at the time.\n */\nexport const normalizeTarget = (target: readonly unknown[]): string =>\n target\n .flatMap(part => (Array.isArray(part) ? part : [part]))\n .map(part =>\n canonicalSelector(\n String(part)\n .replace(GENERATED_ID, '#generated-id')\n .replace(/:nth-child\\(\\d+\\)/g, ':nth-child(n)')\n .replace(/:nth-of-type\\(\\d+\\)/g, ':nth-of-type(n)'),\n ),\n )\n .join(' >>> ');\n\n/** `rule|target|screen`: the identity of one failing node. */\nexport const fingerprintOf = (rule: string, target: string, screen: string) =>\n `${rule}|${target}|${screen}`;\n\n/** The screen a fingerprint belongs to. */\nexport const screenOf = (fingerprint: string) =>\n fingerprint.slice(fingerprint.lastIndexOf('|') + 1);\n\n/** Every distinct fingerprint in `violations`, at its rule's impact. */\nexport const findingsOf = (\n screen: string,\n violations: readonly A11yViolation[],\n): A11yFinding[] => {\n const found = new Map<string, A11yFinding>();\n for (const violation of violations) {\n for (const node of violation.nodes) {\n const fingerprint = fingerprintOf(\n violation.id,\n normalizeTarget(node.target),\n screen,\n );\n found.set(fingerprint, {\n fingerprint,\n impact: violation.impact ?? 'minor',\n help: violation.help ?? violation.id,\n });\n }\n }\n return [...found.values()].sort((a, b) =>\n a.fingerprint.localeCompare(b.fingerprint),\n );\n};\n\n/** Judges one screen's findings against the baseline. */\nexport const compareWithBaseline = (\n screen: string,\n findings: readonly A11yFinding[],\n baseline: A11yBaseline,\n): A11yVerdict => {\n const gated = findings.filter(finding => GATED.has(finding.impact));\n const present = new Set(gated.map(finding => finding.fingerprint));\n return {\n added: gated.filter(finding => !(finding.fingerprint in baseline)),\n stale: Object.keys(baseline)\n .filter(fingerprint => screenOf(fingerprint) === screen)\n .filter(fingerprint => !present.has(fingerprint))\n .sort(),\n reported: findings.filter(finding => !GATED.has(finding.impact)),\n };\n};\n\n/**\n * The baseline with this screen's entries replaced by what was found: owners\n * kept for fingerprints still present, and an empty owner for a new one, which\n * {@link unownedEntries} refuses until a person names its issue.\n */\nexport const updateBaseline = (\n screen: string,\n findings: readonly A11yFinding[],\n baseline: A11yBaseline,\n): A11yBaseline => {\n const next: Record<string, string> = {};\n for (const [fingerprint, owner] of Object.entries(baseline)) {\n if (screenOf(fingerprint) !== screen) next[fingerprint] = owner;\n }\n for (const finding of findings) {\n if (GATED.has(finding.impact)) {\n next[finding.fingerprint] = baseline[finding.fingerprint] ?? '';\n }\n }\n return Object.fromEntries(\n Object.entries(next).sort(([a], [b]) => a.localeCompare(b)),\n );\n};\n\n/** An issue reference in the form GitHub links across repositories. */\nexport const ISSUE_REFERENCE = /^[\\w.-]+\\/[\\w.-]+#\\d+$/;\n\n/** Every entry whose owner is not an `owner/repo#N` issue reference. */\nexport const unownedEntries = (baseline: A11yBaseline): string[] =>\n Object.entries(baseline)\n .filter(([, owner]) => !ISSUE_REFERENCE.test(owner))\n .map(([fingerprint]) => fingerprint);\n\n/** A failure message that names every fingerprint and what to do about it. */\nexport const describeVerdict = (screen: string, verdict: A11yVerdict) =>\n [\n ...verdict.added.map(\n finding =>\n `${screen}: new ${finding.impact} violation ${finding.fingerprint} — ${finding.help}`,\n ),\n ...verdict.stale.map(\n fingerprint =>\n `${screen}: ${fingerprint} is in the baseline but no longer found — delete its entry`,\n ),\n ].join('\\n');\n"],"names":["GATED","Set","WCAG_22_AA_TAGS","GENERATED_ID","tokenize","text","isBoundary","tokens","current","depth","quote","at","length","char","push","RANK","canonicalCompound","compound","previous","map","part","rank","sort","a","b","localeCompare","join","canonicalSelector","selector","trim","test","token","filter","normalizeTarget","target","flatMap","Array","isArray","String","replace","fingerprintOf","rule","screen","screenOf","fingerprint","slice","lastIndexOf","findingsOf","violations","found","Map","violation","node","nodes","id","set","impact","help","values","compareWithBaseline","findings","baseline","gated","finding","has","present","added","stale","Object","keys","reported","updateBaseline","next","owner","entries","fromEntries","ISSUE_REFERENCE","unownedEntries","describeVerdict","verdict"],"mappings":"AAAA;;;;;;;;;CASC,GAED,+CAA+C,GAoC/C,8CAA8C,GAC9C,OAAO,MAAMA,QAAiC,IAAIC,IAAI;IAAC;IAAW;CAAW,EAAE;AAE/E,kEAAkE,GAClE,OAAO,MAAMC,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;CACD,CAAU;AAEX;;;;CAIC,GACD,MAAMC,eACJ;AAEF;;;;;CAKC,GACD,MAAMC,WAAW,CACfC,MACAC;IAEA,MAAMC,SAAmB,EAAE;IAC3B,IAAIC,UAAU;IACd,IAAIC,QAAQ;IACZ,IAAIC,QAAQ;IACZ,IAAK,IAAIC,KAAK,GAAGA,KAAKN,KAAKO,MAAM,EAAED,MAAM,EAAG;QAC1C,MA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,IAAI,CAAC,CAAC,CAACC,EAAE,EAAE,CAACC,EAAE,GAAKD,EAAEE,aAAa,CAACD;AAE5D,EAAE;AAEF,qEAAqE,GACrE,OAAO,MAAMoD,kBAAkB,yBAAyB;AAExD,sEAAsE,GACtE,OAAO,MAAMC,iBAAiB,CAAChB,WAC7BO,OAAOM,OAAO,CAACb,UACZ7B,MAAM,CAAC,CAAC,GAAGyC,MAAM,GAAK,CAACG,gBAAgB9C,IAAI,CAAC2C,QAC5CtD,GAAG,CAAC,CAAC,CAACyB,YAAY,GAAKA,aAAa;AAEzC,4EAA4E,GAC5E,OAAO,MAAMkC,kBAAkB,CAACpC,QAAgBqC,UAC9C;WACKA,QAAQb,KAAK,CAAC/C,GAAG,CAClB4C,CAAAA,UACE,GAAGrB,OAAO,MAAM,EAAEqB,QAAQP,MAAM,CAAC,WAAW,EAAEO,QAAQnB,WAAW,CAAC,GAAG,EAAEmB,QAAQN,IAAI,EAAE;WAEtFsB,QAAQZ,KAAK,CAAChD,GAAG,CAClByB,CAAAA,cACE,GAAGF,OAAO,EAAE,EAAEE,YAAY,0DAA0D,CAAC;KAE1F,CAAClB,IAAI,CAAC,MAAM"}
@@ -0,0 +1,5 @@
1
+ export * from './axe.js';
2
+ export * from './baseline.js';
3
+ export * from './keyboard.js';
4
+ export * from './walk.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/a11y/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './axe.js';
2
+ export * from './baseline.js';
3
+ export * from './keyboard.js';
4
+ export * from './walk.js';
5
+
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/a11y/index.ts"],"sourcesContent":["export * from './axe.js';\nexport * from './baseline.js';\nexport * from './keyboard.js';\nexport * from './walk.js';\n"],"names":[],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAC9B,cAAc,YAAY"}
@@ -0,0 +1,29 @@
1
+ import { type Page } from '@playwright/test';
2
+ import { type WalkExpectations } from './walk.js';
3
+ export interface WalkOptions extends Partial<WalkExpectations> {
4
+ /** How many Tab presses to make before giving up on reaching the end. */
5
+ readonly maxStops?: number;
6
+ }
7
+ /**
8
+ * Tabs through the page from the top and fails on what a keyboard user would
9
+ * hit (ADR 0024): no skip link first when `skipLink` is set, the first stop
10
+ * inside `main` past `mainIndexMax`, a stop with no visible indicator, a stop
11
+ * something else covers, and a stop that jumps back more than a row in its
12
+ * column.
13
+ */
14
+ export declare function walkKeyboard(page: Page, { maxStops, skipLink, mainIndexMax }?: WalkOptions): Promise<void>;
15
+ export interface FocusKeptOptions {
16
+ /**
17
+ * The issue that stops this write dropping focus, while it still does. The
18
+ * check then expects focus on `<body>` and fails once it is not, so the fix
19
+ * has to delete the option — the same ratchet as an axe baseline entry.
20
+ */
21
+ readonly lostUntil?: string;
22
+ }
23
+ /**
24
+ * After a write — a save, a delete, a submitted step — focus must land on
25
+ * something, not fall back to the document, where a screen reader loses its
26
+ * place and the next Tab starts from the top (2.4.3).
27
+ */
28
+ export declare function expectFocusKept(page: Page, { lostUntil }?: FocusKeptOptions): Promise<void>;
29
+ //# sourceMappingURL=keyboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/a11y/keyboard.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,WAAY,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC5D,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AA2FD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,IAAI,EACV,EAAE,QAAc,EAAE,QAAe,EAAE,YAAgB,EAAE,GAAE,WAAgB,GACtE,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,EACV,EAAE,SAAS,EAAE,GAAE,gBAAqB,GACnC,OAAO,CAAC,IAAI,CAAC,CAef"}
@@ -0,0 +1,115 @@
1
+ // `readStop` and the blur helpers are serialized by `page.evaluate` and run in
2
+ // the browser, so this file is checked against the DOM's types as well.
3
+ /// <reference lib="dom" />
4
+ import { expect } from '@playwright/test';
5
+ import { assessWalk } from './walk.js';
6
+ /**
7
+ * A focus ring animates in, and WCAG judges the settled state: each stop is
8
+ * read once every running transition has finished, and never sooner than
9
+ * `SETTLE_MS` after the focus moved.
10
+ */ const SETTLE_MS = 200;
11
+ /** Resolves once the page's animations and transitions have finished. */ const settled = async (page)=>{
12
+ await page.waitForTimeout(SETTLE_MS);
13
+ await page.evaluate(()=>Promise.all(document.getAnimations()// A spinner never finishes; only what eventually settles is awaited.
14
+ .filter((animation)=>{
15
+ var _animation_effect;
16
+ return ((_animation_effect = animation.effect) == null ? void 0 : _animation_effect.getTiming().iterations) !== Infinity;
17
+ }).map((animation)=>animation.finished)));
18
+ };
19
+ /** Reads the focused element in the page. Runs in the browser. */ const readStop = ()=>{
20
+ var _ref, _element_getAttribute;
21
+ var _element_textContent;
22
+ const element = document.activeElement;
23
+ if (element === null || element === document.body) return null;
24
+ const rect = element.getBoundingClientRect();
25
+ const style = getComputedStyle(element);
26
+ const outline = style.outlineStyle !== 'none' && parseFloat(style.outlineWidth) > 0;
27
+ const ring = style.boxShadow !== 'none' && style.boxShadow !== '';
28
+ const centre = document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
29
+ const obscured = rect.width > 0 && rect.height > 0 && centre !== null && !element.contains(centre) && !centre.contains(element);
30
+ const href = element.getAttribute('href');
31
+ const target = (href == null ? void 0 : href.startsWith('#')) && href.length > 1 ? document.getElementById(href.slice(1)) : null;
32
+ const main = document.querySelector('main');
33
+ const isSkipLink = element.tagName === 'A' && target !== null && main !== null && (target === main || main.contains(target));
34
+ const name = (_ref = (_element_getAttribute = element.getAttribute('aria-label')) != null ? _element_getAttribute : (_element_textContent = element.textContent) == null ? void 0 : _element_textContent.trim().slice(0, 40)) != null ? _ref : '';
35
+ const role = element.getAttribute('role');
36
+ return {
37
+ label: `${element.tagName.toLowerCase()}${role ? `[role=${role}]` : ''} "${name}"`,
38
+ rect: {
39
+ x: rect.x,
40
+ y: rect.y,
41
+ width: rect.width,
42
+ height: rect.height
43
+ },
44
+ inMain: element.closest('main') !== null,
45
+ isSkipLink,
46
+ indicatorVisible: outline || ring,
47
+ obscured
48
+ };
49
+ };
50
+ const tabThrough = async (page, maxStops)=>{
51
+ const stops = [];
52
+ let first;
53
+ for(let pressed = 0; pressed < maxStops; pressed += 1){
54
+ await page.keyboard.press('Tab');
55
+ await settled(page);
56
+ const stop = await page.evaluate(readStop);
57
+ if (stop === null) break;
58
+ const identity = `${stop.label}@${stop.rect.x},${stop.rect.y}`;
59
+ // Focus wrapped back to where it started: the walk is complete.
60
+ if (identity === first) break;
61
+ first != null ? first : first = identity;
62
+ stops.push(stop);
63
+ }
64
+ return stops;
65
+ };
66
+ /**
67
+ * Tabs through the page from the top and fails on what a keyboard user would
68
+ * hit (ADR 0024): no skip link first when `skipLink` is set, the first stop
69
+ * inside `main` past `mainIndexMax`, a stop with no visible indicator, a stop
70
+ * something else covers, and a stop that jumps back more than a row in its
71
+ * column.
72
+ */ export async function walkKeyboard(page, { maxStops = 120, skipLink = true, mainIndexMax = 3 } = {}) {
73
+ var _stops_;
74
+ await page.evaluate(()=>{
75
+ var _document_activeElement;
76
+ (_document_activeElement = document.activeElement) == null ? void 0 : _document_activeElement.blur();
77
+ window.scrollTo(0, 0);
78
+ });
79
+ const stops = await tabThrough(page, maxStops);
80
+ let walk = {
81
+ stops
82
+ };
83
+ if (skipLink && ((_stops_ = stops[0]) == null ? void 0 : _stops_.isSkipLink) === true) {
84
+ await page.evaluate(()=>{
85
+ var _document_activeElement;
86
+ (_document_activeElement = document.activeElement) == null ? void 0 : _document_activeElement.blur();
87
+ window.scrollTo(0, 0);
88
+ });
89
+ await page.keyboard.press('Tab');
90
+ await page.keyboard.press('Enter');
91
+ walk = {
92
+ stops,
93
+ afterSkip: await tabThrough(page, maxStops)
94
+ };
95
+ }
96
+ expect(assessWalk(walk, {
97
+ skipLink,
98
+ mainIndexMax
99
+ })).toEqual([]);
100
+ }
101
+ /**
102
+ * After a write — a save, a delete, a submitted step — focus must land on
103
+ * something, not fall back to the document, where a screen reader loses its
104
+ * place and the next Tab starts from the top (2.4.3).
105
+ */ export async function expectFocusKept(page, { lostUntil } = {}) {
106
+ await settled(page);
107
+ const kept = await page.evaluate(()=>document.activeElement !== null && document.activeElement !== document.body);
108
+ if (lostUntil === undefined) {
109
+ expect(kept, 'focus fell back to <body> after the write').toBe(true);
110
+ } else {
111
+ expect(kept, `focus is kept after this write now: delete the lostUntil for ${lostUntil}`).toBe(false);
112
+ }
113
+ }
114
+
115
+ //# sourceMappingURL=keyboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/a11y/keyboard.ts"],"sourcesContent":["// `readStop` and the blur helpers are serialized by `page.evaluate` and run in\n// the browser, so this file is checked against the DOM's types as well.\n/// <reference lib=\"dom\" />\nimport { expect, type Page } from '@playwright/test';\n\nimport {\n assessWalk,\n type FocusStop,\n type FocusWalk,\n type WalkExpectations,\n} from './walk.js';\n\nexport interface WalkOptions extends Partial<WalkExpectations> {\n /** How many Tab presses to make before giving up on reaching the end. */\n readonly maxStops?: number;\n}\n\n/**\n * A focus ring animates in, and WCAG judges the settled state: each stop is\n * read once every running transition has finished, and never sooner than\n * `SETTLE_MS` after the focus moved.\n */\nconst SETTLE_MS = 200;\n\n/** Resolves once the page's animations and transitions have finished. */\nconst settled = async (page: Page) => {\n await page.waitForTimeout(SETTLE_MS);\n await page.evaluate(() =>\n Promise.all(\n document\n .getAnimations()\n // A spinner never finishes; only what eventually settles is awaited.\n .filter(\n animation => animation.effect?.getTiming().iterations !== Infinity,\n )\n .map(animation => animation.finished),\n ),\n );\n};\n\n/** Reads the focused element in the page. Runs in the browser. */\nconst readStop = (): FocusStop | null => {\n const element = document.activeElement as HTMLElement | null;\n if (element === null || element === document.body) return null;\n\n const rect = element.getBoundingClientRect();\n const style = getComputedStyle(element);\n const outline =\n style.outlineStyle !== 'none' && parseFloat(style.outlineWidth) > 0;\n const ring = style.boxShadow !== 'none' && style.boxShadow !== '';\n\n const centre = document.elementFromPoint(\n rect.x + rect.width / 2,\n rect.y + rect.height / 2,\n );\n const obscured =\n rect.width > 0 &&\n rect.height > 0 &&\n centre !== null &&\n !element.contains(centre) &&\n !centre.contains(element);\n\n const href = element.getAttribute('href');\n const target =\n href?.startsWith('#') && href.length > 1\n ? document.getElementById(href.slice(1))\n : null;\n const main = document.querySelector('main');\n const isSkipLink =\n element.tagName === 'A' &&\n target !== null &&\n main !== null &&\n (target === main || main.contains(target));\n\n const name =\n element.getAttribute('aria-label') ??\n element.textContent?.trim().slice(0, 40) ??\n '';\n const role = element.getAttribute('role');\n return {\n label: `${element.tagName.toLowerCase()}${role ? `[role=${role}]` : ''} \"${name}\"`,\n rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },\n inMain: element.closest('main') !== null,\n isSkipLink,\n indicatorVisible: outline || ring,\n obscured,\n };\n};\n\nconst tabThrough = async (page: Page, maxStops: number) => {\n const stops: FocusStop[] = [];\n let first: string | undefined;\n for (let pressed = 0; pressed < maxStops; pressed += 1) {\n await page.keyboard.press('Tab');\n await settled(page);\n const stop = await page.evaluate(readStop);\n if (stop === null) break;\n const identity = `${stop.label}@${stop.rect.x},${stop.rect.y}`;\n // Focus wrapped back to where it started: the walk is complete.\n if (identity === first) break;\n first ??= identity;\n stops.push(stop);\n }\n return stops;\n};\n\n/**\n * Tabs through the page from the top and fails on what a keyboard user would\n * hit (ADR 0024): no skip link first when `skipLink` is set, the first stop\n * inside `main` past `mainIndexMax`, a stop with no visible indicator, a stop\n * something else covers, and a stop that jumps back more than a row in its\n * column.\n */\nexport async function walkKeyboard(\n page: Page,\n { maxStops = 120, skipLink = true, mainIndexMax = 3 }: WalkOptions = {},\n): Promise<void> {\n await page.evaluate(() => {\n (document.activeElement as HTMLElement | null)?.blur();\n window.scrollTo(0, 0);\n });\n const stops = await tabThrough(page, maxStops);\n\n let walk: FocusWalk = { stops };\n if (skipLink && stops[0]?.isSkipLink === true) {\n await page.evaluate(() => {\n (document.activeElement as HTMLElement | null)?.blur();\n window.scrollTo(0, 0);\n });\n await page.keyboard.press('Tab');\n await page.keyboard.press('Enter');\n walk = { stops, afterSkip: await tabThrough(page, maxStops) };\n }\n\n expect(assessWalk(walk, { skipLink, mainIndexMax })).toEqual([]);\n}\n\nexport interface FocusKeptOptions {\n /**\n * The issue that stops this write dropping focus, while it still does. The\n * check then expects focus on `<body>` and fails once it is not, so the fix\n * has to delete the option — the same ratchet as an axe baseline entry.\n */\n readonly lostUntil?: string;\n}\n\n/**\n * After a write — a save, a delete, a submitted step — focus must land on\n * something, not fall back to the document, where a screen reader loses its\n * place and the next Tab starts from the top (2.4.3).\n */\nexport async function expectFocusKept(\n page: Page,\n { lostUntil }: FocusKeptOptions = {},\n): Promise<void> {\n await settled(page);\n const kept = await page.evaluate(\n () =>\n document.activeElement !== null &&\n document.activeElement !== document.body,\n );\n if (lostUntil === undefined) {\n expect(kept, 'focus fell back to <body> after the write').toBe(true);\n } else {\n expect(\n kept,\n `focus is kept after this write now: delete the lostUntil for ${lostUntil}`,\n ).toBe(false);\n }\n}\n"],"names":["expect","assessWalk","SETTLE_MS","settled","page","waitForTimeout","evaluate","Promise","all","document","getAnimations","filter","animation","effect","getTiming","iterations","Infinity","map","finished","readStop","element","activeElement","body","rect","getBoundingClientRect","style","getComputedStyle","outline","outlineStyle","parseFloat","outlineWidth","ring","boxShadow","centre","elementFromPoint","x","width","y","height","obscured","contains","href","getAttribute","target","startsWith","length","getElementById","slice","main","querySelector","isSkipLink","tagName","name","textContent","trim","role","label","toLowerCase","inMain","closest","indicatorVisible","tabThrough","maxStops","stops","first","pressed","keyboard","press","stop","identity","push","walkKeyboard","skipLink","mainIndexMax","blur","window","scrollTo","walk","afterSkip","toEqual","expectFocusKept","lostUntil","kept","undefined","toBe"],"mappings":"AAAA,+EAA+E;AAC/E,wEAAwE;AACxE,2BAA2B;AAC3B,SAASA,MAAM,QAAmB,mBAAmB;AAErD,SACEC,UAAU,QAIL,YAAY;AAOnB;;;;CAIC,GACD,MAAMC,YAAY;AAElB,uEAAuE,GACvE,MAAMC,UAAU,OAAOC;IACrB,MAAMA,KAAKC,cAAc,CAACH;IAC1B,MAAME,KAAKE,QAAQ,CAAC,IAClBC,QAAQC,GAAG,CACTC,SACGC,aAAa,EACd,qEAAqE;SACpEC,MAAM,CACLC,CAAAA;gBAAaA;mBAAAA,EAAAA,oBAAAA,UAAUC,MAAM,qBAAhBD,kBAAkBE,SAAS,GAAGC,UAAU,MAAKC;WAE3DC,GAAG,CAACL,CAAAA,YAAaA,UAAUM,QAAQ;AAG5C;AAEA,gEAAgE,GAChE,MAAMC,WAAW;QAkCbC,MAAAA;QACAA;IAlCF,MAAMA,UAAUX,SAASY,aAAa;IACtC,IAAID,YAAY,QAAQA,YAAYX,SAASa,IAAI,EAAE,OAAO;IAE1D,MAAMC,OAAOH,QAAQI,qBAAqB;IAC1C,MAAMC,QAAQC,iBAAiBN;IAC/B,MAAMO,UACJF,MAAMG,YAAY,KAAK,UAAUC,WAAWJ,MAAMK,YAAY,IAAI;IACpE,MAAMC,OAAON,MAAMO,SAAS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AK,CAAC;QAC1BU,OAAO;YAAEd;YAAOe,WAAW,MAAMjB,WAAWzD,MAAM0D;QAAU;IAC9D;IAEA9D,OAAOC,WAAW4E,MAAM;QAAEL;QAAUC;IAAa,IAAIM,OAAO,CAAC,EAAE;AACjE;AAWA;;;;CAIC,GACD,OAAO,eAAeC,gBACpB5E,IAAU,EACV,EAAE6E,SAAS,EAAoB,GAAG,CAAC,CAAC;IAEpC,MAAM9E,QAAQC;IACd,MAAM8E,OAAO,MAAM9E,KAAKE,QAAQ,CAC9B,IACEG,SAASY,aAAa,KAAK,QAC3BZ,SAASY,aAAa,KAAKZ,SAASa,IAAI;IAE5C,IAAI2D,cAAcE,WAAW;QAC3BnF,OAAOkF,MAAM,6CAA6CE,IAAI,CAAC;IACjE,OAAO;QACLpF,OACEkF,MACA,CAAC,6DAA6D,EAAED,WAAW,EAC3EG,IAAI,CAAC;IACT;AACF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The deterministic part of what axe cannot see, as data: the stops a Tab walk
3
+ * visited, judged against focus order, a visible indicator and nothing
4
+ * covering the focused control (WCAG 2.4.1, 2.4.3, 2.4.7 and 2.4.11).
5
+ */
6
+ /** Where a stop sits on the page, in CSS pixels. */
7
+ export interface FocusRect {
8
+ readonly x: number;
9
+ readonly y: number;
10
+ readonly width: number;
11
+ readonly height: number;
12
+ }
13
+ /** One element focus rested on during the walk. */
14
+ export interface FocusStop {
15
+ /** A short description for the failure message: tag, role and name. */
16
+ readonly label: string;
17
+ readonly rect: FocusRect;
18
+ readonly inMain: boolean;
19
+ /** An in-page link to `main`, or to something inside it. */
20
+ readonly isSkipLink: boolean;
21
+ /** An outline or a ring could be seen once the focus transition settled. */
22
+ readonly indicatorVisible: boolean;
23
+ /** Something else is on top of the stop's centre. */
24
+ readonly obscured: boolean;
25
+ }
26
+ /** A walk's stops: from the top, and after activating the skip link. */
27
+ export interface FocusWalk {
28
+ readonly stops: readonly FocusStop[];
29
+ /** Present when the walk activated a skip link and kept going. */
30
+ readonly afterSkip?: readonly FocusStop[];
31
+ }
32
+ export interface WalkExpectations {
33
+ /** The first stop must be a skip link, and activating it must reach `main`. */
34
+ readonly skipLink: boolean;
35
+ /**
36
+ * The highest 1-based position the first stop inside `main` may have —
37
+ * counted after the skip link when there is one, from the top otherwise.
38
+ */
39
+ readonly mainIndexMax: number;
40
+ }
41
+ /** Every failure the walk shows, one message per failure; empty is a pass. */
42
+ export declare const assessWalk: (walk: FocusWalk, expectations: WalkExpectations) => string[];
43
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/a11y/walk.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,mDAAmD;AACnD,MAAM,WAAW,SAAS;IACxB,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,4EAA4E;IAC5E,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,wEAAwE;AACxE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;IACrC,kEAAkE;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAqBD,8EAA8E;AAC9E,eAAO,MAAM,UAAU,GACrB,MAAM,SAAS,EACf,cAAc,gBAAgB,KAC7B,MAAM,EAwCR,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The deterministic part of what axe cannot see, as data: the stops a Tab walk
3
+ * visited, judged against focus order, a visible indicator and nothing
4
+ * covering the focused control (WCAG 2.4.1, 2.4.3, 2.4.7 and 2.4.11).
5
+ */ /** Where a stop sits on the page, in CSS pixels. */ const describe = (stop, position)=>`stop ${position} (${stop.label})`;
6
+ /** The stops are in an order a sighted keyboard user can follow (2.4.3). */ const outOfOrder = (stops)=>stops.slice(1).flatMap((stop, index)=>{
7
+ const previous = stops[index];
8
+ const sameColumn = stop.rect.x < previous.rect.x + previous.rect.width && previous.rect.x < stop.rect.x + stop.rect.width;
9
+ const rowAbove = stop.rect.y + stop.rect.height <= previous.rect.y;
10
+ const moreThanARow = stop.rect.y < previous.rect.y - previous.rect.height;
11
+ return sameColumn && rowAbove && moreThanARow ? [
12
+ `${describe(stop, index + 2)} sits more than a row above ${describe(previous, index + 1)} in the same column`
13
+ ] : [];
14
+ });
15
+ /** Every failure the walk shows, one message per failure; empty is a pass. */ export const assessWalk = (walk, expectations)=>{
16
+ const failures = [];
17
+ const first = walk.stops[0];
18
+ if (first === undefined) {
19
+ return [
20
+ 'the walk reached no focusable element'
21
+ ];
22
+ }
23
+ let counted = walk.stops;
24
+ if (expectations.skipLink) {
25
+ if (!first.isSkipLink) {
26
+ failures.push(`the first stop is ${first.label}, not a skip link`);
27
+ } else if (walk.afterSkip === undefined) {
28
+ failures.push('the skip link was found but not activated');
29
+ } else {
30
+ counted = walk.afterSkip;
31
+ }
32
+ }
33
+ const mainAt = counted.findIndex((stop)=>stop.inMain) + 1;
34
+ if (mainAt === 0) {
35
+ failures.push(`no stop inside main in the first ${counted.length}`);
36
+ } else if (mainAt > expectations.mainIndexMax) {
37
+ failures.push(`the first stop inside main is number ${mainAt}, over the limit of ${expectations.mainIndexMax}`);
38
+ }
39
+ walk.stops.forEach((stop, index)=>{
40
+ if (!stop.indicatorVisible) {
41
+ failures.push(`${describe(stop, index + 1)} shows no focus indicator`);
42
+ }
43
+ if (stop.obscured) {
44
+ failures.push(`${describe(stop, index + 1)} is covered by another element`);
45
+ }
46
+ });
47
+ return [
48
+ ...failures,
49
+ ...outOfOrder(walk.stops)
50
+ ];
51
+ };
52
+
53
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/a11y/walk.ts"],"sourcesContent":["/**\n * The deterministic part of what axe cannot see, as data: the stops a Tab walk\n * visited, judged against focus order, a visible indicator and nothing\n * covering the focused control (WCAG 2.4.1, 2.4.3, 2.4.7 and 2.4.11).\n */\n\n/** Where a stop sits on the page, in CSS pixels. */\nexport interface FocusRect {\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n}\n\n/** One element focus rested on during the walk. */\nexport interface FocusStop {\n /** A short description for the failure message: tag, role and name. */\n readonly label: string;\n readonly rect: FocusRect;\n readonly inMain: boolean;\n /** An in-page link to `main`, or to something inside it. */\n readonly isSkipLink: boolean;\n /** An outline or a ring could be seen once the focus transition settled. */\n readonly indicatorVisible: boolean;\n /** Something else is on top of the stop's centre. */\n readonly obscured: boolean;\n}\n\n/** A walk's stops: from the top, and after activating the skip link. */\nexport interface FocusWalk {\n readonly stops: readonly FocusStop[];\n /** Present when the walk activated a skip link and kept going. */\n readonly afterSkip?: readonly FocusStop[];\n}\n\nexport interface WalkExpectations {\n /** The first stop must be a skip link, and activating it must reach `main`. */\n readonly skipLink: boolean;\n /**\n * The highest 1-based position the first stop inside `main` may have —\n * counted after the skip link when there is one, from the top otherwise.\n */\n readonly mainIndexMax: number;\n}\n\nconst describe = (stop: FocusStop, position: number) =>\n `stop ${position} (${stop.label})`;\n\n/** The stops are in an order a sighted keyboard user can follow (2.4.3). */\nconst outOfOrder = (stops: readonly FocusStop[]): string[] =>\n stops.slice(1).flatMap((stop, index) => {\n const previous = stops[index] as FocusStop;\n const sameColumn =\n stop.rect.x < previous.rect.x + previous.rect.width &&\n previous.rect.x < stop.rect.x + stop.rect.width;\n const rowAbove = stop.rect.y + stop.rect.height <= previous.rect.y;\n const moreThanARow = stop.rect.y < previous.rect.y - previous.rect.height;\n return sameColumn && rowAbove && moreThanARow\n ? [\n `${describe(stop, index + 2)} sits more than a row above ${describe(previous, index + 1)} in the same column`,\n ]\n : [];\n });\n\n/** Every failure the walk shows, one message per failure; empty is a pass. */\nexport const assessWalk = (\n walk: FocusWalk,\n expectations: WalkExpectations,\n): string[] => {\n const failures: string[] = [];\n const first = walk.stops[0];\n\n if (first === undefined) {\n return ['the walk reached no focusable element'];\n }\n\n let counted = walk.stops;\n if (expectations.skipLink) {\n if (!first.isSkipLink) {\n failures.push(`the first stop is ${first.label}, not a skip link`);\n } else if (walk.afterSkip === undefined) {\n failures.push('the skip link was found but not activated');\n } else {\n counted = walk.afterSkip;\n }\n }\n\n const mainAt = counted.findIndex(stop => stop.inMain) + 1;\n if (mainAt === 0) {\n failures.push(`no stop inside main in the first ${counted.length}`);\n } else if (mainAt > expectations.mainIndexMax) {\n failures.push(\n `the first stop inside main is number ${mainAt}, over the limit of ${expectations.mainIndexMax}`,\n );\n }\n\n walk.stops.forEach((stop, index) => {\n if (!stop.indicatorVisible) {\n failures.push(`${describe(stop, index + 1)} shows no focus indicator`);\n }\n if (stop.obscured) {\n failures.push(\n `${describe(stop, index + 1)} is covered by another element`,\n );\n }\n });\n\n return [...failures, ...outOfOrder(walk.stops)];\n};\n"],"names":["describe","stop","position","label","outOfOrder","stops","slice","flatMap","index","previous","sameColumn","rect","x","width","rowAbove","y","height","moreThanARow","assessWalk","walk","expectations","failures","first","undefined","counted","skipLink","isSkipLink","push","afterSkip","mainAt","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kB,EAAEL,MAAMnB,KAAK,CAAC,iBAAiB,CAAC;QACnE,OAAO,IAAIgB,KAAKS,SAAS,KAAKL,WAAW;YACvCF,SAASM,IAAI,CAAC;QAChB,OAAO;YACLH,UAAUL,KAAKS,SAAS;QAC1B;IACF;IAEA,MAAMC,SAASL,QAAQM,SAAS,CAAC7B,CAAAA,OAAQA,KAAK8B,MAAM,IAAI;IACxD,IAAIF,WAAW,GAAG;QAChBR,SAASM,IAAI,CAAC,CAAC,iCAAiC,EAAEH,QAAQQ,MAAM,EAAE;IACpE,OAAO,IAAIH,SAAST,aAAaa,YAAY,EAAE;QAC7CZ,SAASM,IAAI,CACX,CAAC,qCAAqC,EAAEE,OAAO,oBAAoB,EAAET,aAAaa,YAAY,EAAE;IAEpG;IAEAd,KAAKd,KAAK,CAAC6B,OAAO,CAAC,CAACjC,MAAMO;QACxB,IAAI,CAACP,KAAKkC,gBAAgB,EAAE;YAC1Bd,SAASM,IAAI,CAAC,GAAG3B,SAASC,MAAMO,QAAQ,GAAG,yBAAyB,CAAC;QACvE;QACA,IAAIP,KAAKmC,QAAQ,EAAE;YACjBf,SAASM,IAAI,CACX,GAAG3B,SAASC,MAAMO,QAAQ,GAAG,8BAA8B,CAAC;QAEhE;IACF;IAEA,OAAO;WAAIa;WAAajB,WAAWe,KAAKd,KAAK;KAAE;AACjD,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/testing-e2e",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "End-to-end testing with one set of journeys and two profiles: mocked backends by default, real infrastructure on demand.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -41,6 +41,11 @@
41
41
  "types": "./dist/playwright/index.d.ts",
42
42
  "import": "./dist/playwright/index.js",
43
43
  "default": "./dist/playwright/index.js"
44
+ },
45
+ "./a11y": {
46
+ "types": "./dist/a11y/index.d.ts",
47
+ "import": "./dist/a11y/index.js",
48
+ "default": "./dist/a11y/index.js"
44
49
  }
45
50
  },
46
51
  "nx": {
@@ -67,11 +72,12 @@
67
72
  },
68
73
  "dependencies": {
69
74
  "@swc/helpers": "0.5.23",
70
- "@entifix/business": "0.18.0",
71
- "@entifix/core": "0.18.0",
72
- "@entifix/testing-unit": "0.18.0"
75
+ "@entifix/business": "0.18.1",
76
+ "@entifix/core": "0.18.1",
77
+ "@entifix/testing-unit": "0.18.1"
73
78
  },
74
79
  "peerDependencies": {
80
+ "@axe-core/playwright": ">=4.14 <5",
75
81
  "@msw/playwright": ">=0.7",
76
82
  "@nx/devkit": ">=24 <25",
77
83
  "@nx/playwright": ">=24 <25",
@@ -80,30 +86,33 @@
80
86
  "effect": "^4.0.7",
81
87
  "msw": ">=3",
82
88
  "vitest": "*",
83
- "@entifix/amqp": "0.18.0",
84
- "@entifix/mongo": "0.18.0",
85
- "@entifix/redis": "0.18.0"
89
+ "@entifix/mongo": "0.18.1",
90
+ "@entifix/redis": "0.18.1",
91
+ "@entifix/amqp": "0.18.1"
86
92
  },
87
93
  "peerDependenciesMeta": {
88
- "@msw/playwright": {
94
+ "@axe-core/playwright": {
89
95
  "optional": true
90
96
  },
91
- "@nx/devkit": {
97
+ "@entifix/amqp": {
92
98
  "optional": true
93
99
  },
94
- "@nx/playwright": {
100
+ "@entifix/mongo": {
95
101
  "optional": true
96
102
  },
97
- "@playwright/test": {
103
+ "@entifix/redis": {
98
104
  "optional": true
99
105
  },
100
- "@entifix/amqp": {
106
+ "@msw/playwright": {
101
107
  "optional": true
102
108
  },
103
- "@entifix/mongo": {
109
+ "@nx/devkit": {
104
110
  "optional": true
105
111
  },
106
- "@entifix/redis": {
112
+ "@nx/playwright": {
113
+ "optional": true
114
+ },
115
+ "@playwright/test": {
107
116
  "optional": true
108
117
  },
109
118
  "axios": {
@@ -120,8 +129,8 @@
120
129
  "@nx/devkit": "24.0.3",
121
130
  "@nx/playwright": "24.0.3",
122
131
  "effect": "4.0.7",
123
- "@entifix/amqp": "0.18.0",
124
- "@entifix/mongo": "0.18.0",
125
- "@entifix/redis": "0.18.0"
132
+ "@entifix/amqp": "0.18.1",
133
+ "@entifix/mongo": "0.18.1",
134
+ "@entifix/redis": "0.18.1"
126
135
  }
127
136
  }