ultra11y 7.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.opencode/plugins/ultra11y.js +1 -1
- package/README.md +111 -374
- package/dist/cypress-plugin.mjs +6 -3
- package/dist/jest.cjs +199 -0
- package/dist/jest.d.ts +24 -0
- package/dist/jest.mjs +167 -0
- package/dist/playwright.mjs +6 -3
- package/dist/unit-C7c8k68J.d.ts +51 -0
- package/dist/vitest.d.ts +25 -0
- package/dist/vitest.mjs +167 -0
- package/package.json +12 -1
- package/scripts/ultra11y.mjs +1016 -485
- package/skills/review-a11y/SKILL.md +1 -1
- package/skills/review-a11y/scripts/ultra11y.mjs +1016 -485
- package/skills/ultra11y/SKILL.md +1 -1
- package/skills/ultra11y/references/e2e.md +6 -0
- package/skills/ultra11y/references/full-audit.md +16 -0
- package/skills/ultra11y/references/rendered.md +46 -1
- package/skills/ultra11y/scripts/ultra11y.mjs +1016 -485
- package/src/adjudicate.ts +17 -2
- package/src/audit.ts +50 -3
- package/src/auditor.ts +4 -0
- package/src/capture.ts +88 -0
- package/src/cli.ts +78 -3
- package/src/discover.ts +16 -4
- package/src/fix.ts +4 -0
- package/src/glob.ts +62 -2
- package/src/graph/build.ts +7 -1
- package/src/integrations/core.ts +12 -2
- package/src/integrations/jest.ts +34 -0
- package/src/integrations/payload.ts +20 -2
- package/src/integrations/unit.ts +210 -0
- package/src/integrations/vitest.ts +35 -0
- package/src/output.ts +5 -1
- package/src/parse/html.ts +14 -0
- package/src/parse/snap.ts +460 -0
- package/src/parse/source.ts +8 -0
- package/src/report.ts +8 -0
- package/src/rules/cross-rule.ts +2 -2
- package/src/rules/rule.ts +16 -1
- package/src/site-data.ts +0 -2
- package/src/standards/pack-rules.ts +2 -2
- package/src/types.ts +10 -2
package/dist/jest.cjs
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/integrations/jest.ts
|
|
21
|
+
var jest_exports = {};
|
|
22
|
+
__export(jest_exports, {
|
|
23
|
+
checkA11y: () => checkA11y,
|
|
24
|
+
toBeAccessible: () => toBeAccessible
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(jest_exports);
|
|
27
|
+
|
|
28
|
+
// node_modules/.pnpm/tsup@8.5.1_postcss@8.5.15_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
|
|
29
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
30
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
31
|
+
|
|
32
|
+
// src/integrations/unit.ts
|
|
33
|
+
var import_node_path = require("path");
|
|
34
|
+
|
|
35
|
+
// src/integrations/core.ts
|
|
36
|
+
var import_node_child_process = require("child_process");
|
|
37
|
+
var import_node_module = require("module");
|
|
38
|
+
|
|
39
|
+
// src/integrations/payload.ts
|
|
40
|
+
var RANK = { bloquant: 0, majeur: 1, mineur: 2 };
|
|
41
|
+
var THRESHOLD = { blocking: 0, bloquant: 0, major: 1, majeur: 1, minor: 2, mineur: 2 };
|
|
42
|
+
function failingFindings(result, failOn) {
|
|
43
|
+
const max = THRESHOLD[failOn];
|
|
44
|
+
if (max === void 0) throw new Error(`ultra11y: failOn must be blocking|major|minor (got "${failOn}")`);
|
|
45
|
+
return (result.findings ?? []).filter((f) => !f.advisory && (RANK[f.severity] ?? 99) <= max);
|
|
46
|
+
}
|
|
47
|
+
function formatFailure(pageName, failing, where = ".ultra11y/pages/") {
|
|
48
|
+
const lines = [`ultra11y: ${failing.length} accessibility non-conformity(ies) on "${pageName}":`];
|
|
49
|
+
for (const f of failing.slice(0, 20)) {
|
|
50
|
+
lines.push(` [${f.severity}] ${f.ruleId} (WCAG ${f.criteriaId}) \u2014 ${f.origin?.sourceFile ?? f.file} \u2014 ${f.message}`);
|
|
51
|
+
}
|
|
52
|
+
if (failing.length > 20) lines.push(` \u2026 and ${failing.length - 20} more.`);
|
|
53
|
+
lines.push(`Full detail: ${where} \u2014 re-audit offline with \`ultra11y audit\`.`);
|
|
54
|
+
return lines.join("\n");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/integrations/core.ts
|
|
58
|
+
function enginePath() {
|
|
59
|
+
if (process.env.ULTRA11Y) return process.env.ULTRA11Y;
|
|
60
|
+
try {
|
|
61
|
+
return (0, import_node_module.createRequire)(importMetaUrl).resolve("ultra11y/scripts/ultra11y.mjs");
|
|
62
|
+
} catch {
|
|
63
|
+
return new URL("../scripts/ultra11y.mjs", importMetaUrl).pathname;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function auditCapture(payload, opts = {}, engine = enginePath()) {
|
|
67
|
+
return pipeToEngine(["capture", "write", "--json", ...opts.root ? ["--root", opts.root] : []], payload, engine);
|
|
68
|
+
}
|
|
69
|
+
function pipeToEngine(args, payload, engine) {
|
|
70
|
+
const res = (0, import_node_child_process.spawnSync)(process.execPath, [engine, ...args], {
|
|
71
|
+
input: JSON.stringify(payload),
|
|
72
|
+
encoding: "utf8",
|
|
73
|
+
maxBuffer: 192 * 1024 * 1024
|
|
74
|
+
});
|
|
75
|
+
if (res.error) throw new Error(`ultra11y: could not run the engine at ${engine} \u2014 ${res.error.message}`);
|
|
76
|
+
if (!res.stdout) throw new Error(`ultra11y: the engine produced no output (exit ${res.status})
|
|
77
|
+
${res.stderr || ""}`);
|
|
78
|
+
try {
|
|
79
|
+
return JSON.parse(res.stdout);
|
|
80
|
+
} catch {
|
|
81
|
+
throw new Error(`ultra11y: could not parse the engine output
|
|
82
|
+
${res.stdout.slice(0, 500)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/integrations/unit.ts
|
|
87
|
+
var escText = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
88
|
+
function nodeHtml(n) {
|
|
89
|
+
if (n.nodeType === 1 && typeof n.outerHTML === "string") return n.outerHTML;
|
|
90
|
+
if (n.nodeType === 3) return escText(n.textContent ?? "");
|
|
91
|
+
if (n.nodeType === 8) return `<!--${n.data ?? ""}-->`;
|
|
92
|
+
return "";
|
|
93
|
+
}
|
|
94
|
+
function serializeRender(target) {
|
|
95
|
+
if (typeof target === "string") return target;
|
|
96
|
+
if (target && typeof target === "object") {
|
|
97
|
+
if ("container" in target && target.container) return serializeRender(target.container);
|
|
98
|
+
const n = target;
|
|
99
|
+
if (n.nodeType === 9) return n.body?.innerHTML ?? "";
|
|
100
|
+
if (n.nodeType === 11) return Array.from(n.childNodes ?? [], nodeHtml).join("");
|
|
101
|
+
if (typeof n.outerHTML === "string") return n.outerHTML;
|
|
102
|
+
}
|
|
103
|
+
throw new TypeError(
|
|
104
|
+
"ultra11y: checkA11y expects an Element, a Document, a DocumentFragment, a Testing Library render result ({ container }) or an HTML string."
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function domEnv(target) {
|
|
108
|
+
let node;
|
|
109
|
+
if (typeof target === "object" && target) node = "container" in target ? target.container : target;
|
|
110
|
+
const g = globalThis;
|
|
111
|
+
const ua = node?.ownerDocument?.defaultView?.navigator?.userAgent ?? node?.defaultView?.navigator?.userAgent ?? g.navigator?.userAgent ?? "";
|
|
112
|
+
if (/jsdom/i.test(ua)) return "jsdom";
|
|
113
|
+
if (/happy-?dom/i.test(ua) || g.happyDOM) return "happy-dom";
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
function currentTest() {
|
|
117
|
+
const g = globalThis;
|
|
118
|
+
const ex = g.expect ?? g[/* @__PURE__ */ Symbol.for("expect-global")];
|
|
119
|
+
try {
|
|
120
|
+
return ex?.getState?.() ?? {};
|
|
121
|
+
} catch {
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function idSlug(s) {
|
|
126
|
+
const slug = s.normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
127
|
+
if (slug.length <= 80) return slug;
|
|
128
|
+
let h = 5381;
|
|
129
|
+
for (let i = 0; i < slug.length; i++) h = (h << 5) + h + slug.charCodeAt(i) >>> 0;
|
|
130
|
+
return `${slug.slice(0, 72).replace(/-+$/, "")}-${h.toString(36)}`;
|
|
131
|
+
}
|
|
132
|
+
var seen = /* @__PURE__ */ new Map();
|
|
133
|
+
function capturePayload(target, opts, runner, ctx = currentTest()) {
|
|
134
|
+
const html = serializeRender(target);
|
|
135
|
+
const root = opts.root ?? process.cwd();
|
|
136
|
+
const rel = (p) => {
|
|
137
|
+
if (!(0, import_node_path.isAbsolute)(p)) return p;
|
|
138
|
+
const fromRoot = (0, import_node_path.relative)(root, p);
|
|
139
|
+
return fromRoot.startsWith("..") ? (0, import_node_path.relative)(process.cwd(), p) : fromRoot;
|
|
140
|
+
};
|
|
141
|
+
const test = ctx.testPath ? rel(ctx.testPath).split("\\").join("/") : void 0;
|
|
142
|
+
const title = ctx.currentTestName;
|
|
143
|
+
let id = opts.as;
|
|
144
|
+
if (!id) {
|
|
145
|
+
const stem = test ? test.replace(/\.(test|spec)\.[cm]?[jt]sx?$|\.[cm]?[jt]sx?$/i, "") : "";
|
|
146
|
+
const base = idSlug([stem, title].filter(Boolean).join(" ")) || "capture";
|
|
147
|
+
const n = (seen.get(base) ?? 0) + 1;
|
|
148
|
+
seen.set(base, n);
|
|
149
|
+
id = n === 1 ? base : `${base}-${n}`;
|
|
150
|
+
}
|
|
151
|
+
const env = domEnv(target);
|
|
152
|
+
return {
|
|
153
|
+
meta: {
|
|
154
|
+
id,
|
|
155
|
+
...opts.name ?? title ? { name: opts.name ?? title } : {},
|
|
156
|
+
...opts.component ? { component: opts.component } : {},
|
|
157
|
+
...opts.source ? { source: opts.source } : {},
|
|
158
|
+
...test ? { test } : {},
|
|
159
|
+
runner,
|
|
160
|
+
...env ? { env } : {}
|
|
161
|
+
},
|
|
162
|
+
html
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
var CAPTURES = ".ultra11y/captures/";
|
|
166
|
+
function createUnitIntegration(runner) {
|
|
167
|
+
function record(target, opts, ctx) {
|
|
168
|
+
const payload = capturePayload(target, opts, runner, ctx ?? currentTest());
|
|
169
|
+
const result = auditCapture(payload, opts.root ? { root: opts.root } : {});
|
|
170
|
+
const failOn = opts.failOn === void 0 ? "blocking" : opts.failOn;
|
|
171
|
+
const failing = failOn === false ? [] : failingFindings(result, failOn);
|
|
172
|
+
return { result, failing, name: payload.meta.name ?? payload.meta.id };
|
|
173
|
+
}
|
|
174
|
+
async function checkA11y2(target, opts = {}) {
|
|
175
|
+
const { result, failing, name } = record(target, opts);
|
|
176
|
+
if (failing.length) throw new Error(formatFailure(name, failing, CAPTURES));
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
function toBeAccessible2(received, opts = {}) {
|
|
180
|
+
const ctx = this?.testPath || this?.currentTestName ? { testPath: this.testPath, currentTestName: this.currentTestName } : currentTest();
|
|
181
|
+
const { failing, name } = record(received, opts, ctx);
|
|
182
|
+
const pass = failing.length === 0;
|
|
183
|
+
return {
|
|
184
|
+
pass,
|
|
185
|
+
message: () => pass ? `ultra11y: expected "${name}" to carry a non-conformity at failOn "${opts.failOn ?? "blocking"}", and it carries none.` : formatFailure(name, failing, CAPTURES)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return { checkA11y: checkA11y2, toBeAccessible: toBeAccessible2 };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/integrations/jest.ts
|
|
192
|
+
var unit = createUnitIntegration("jest");
|
|
193
|
+
var checkA11y = unit.checkA11y;
|
|
194
|
+
var toBeAccessible = unit.toBeAccessible;
|
|
195
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
196
|
+
0 && (module.exports = {
|
|
197
|
+
checkA11y,
|
|
198
|
+
toBeAccessible
|
|
199
|
+
});
|
package/dist/jest.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { U as UnitCheckOptions, R as Renderable, T as TestContext } from './unit-C7c8k68J.js';
|
|
2
|
+
import { A as AuditLike } from './payload-BrdH5eEV.js';
|
|
3
|
+
export { F as FindingLike } from './payload-BrdH5eEV.js';
|
|
4
|
+
|
|
5
|
+
/** Audit a rendered component; throws when a finding reaches `failOn` (default `blocking`). */
|
|
6
|
+
declare const checkA11y: (target: Renderable, opts?: UnitCheckOptions) => Promise<AuditLike>;
|
|
7
|
+
/** The matcher, for `expect.extend({ toBeAccessible })`. */
|
|
8
|
+
declare const toBeAccessible: (this: (TestContext & {
|
|
9
|
+
isNot?: boolean;
|
|
10
|
+
}) | undefined, received: Renderable, opts?: UnitCheckOptions) => {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message: () => string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
declare global {
|
|
16
|
+
namespace jest {
|
|
17
|
+
interface Matchers<R> {
|
|
18
|
+
/** Audit the rendered component with ultra11y; fails when a finding reaches `failOn`. */
|
|
19
|
+
toBeAccessible(opts?: UnitCheckOptions): R;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { AuditLike, Renderable, UnitCheckOptions, checkA11y, toBeAccessible };
|
package/dist/jest.mjs
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// src/integrations/unit.ts
|
|
2
|
+
import { isAbsolute, relative } from "path";
|
|
3
|
+
|
|
4
|
+
// src/integrations/core.ts
|
|
5
|
+
import { spawnSync } from "child_process";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
|
|
8
|
+
// src/integrations/payload.ts
|
|
9
|
+
var RANK = { bloquant: 0, majeur: 1, mineur: 2 };
|
|
10
|
+
var THRESHOLD = { blocking: 0, bloquant: 0, major: 1, majeur: 1, minor: 2, mineur: 2 };
|
|
11
|
+
function failingFindings(result, failOn) {
|
|
12
|
+
const max = THRESHOLD[failOn];
|
|
13
|
+
if (max === void 0) throw new Error(`ultra11y: failOn must be blocking|major|minor (got "${failOn}")`);
|
|
14
|
+
return (result.findings ?? []).filter((f) => !f.advisory && (RANK[f.severity] ?? 99) <= max);
|
|
15
|
+
}
|
|
16
|
+
function formatFailure(pageName, failing, where = ".ultra11y/pages/") {
|
|
17
|
+
const lines = [`ultra11y: ${failing.length} accessibility non-conformity(ies) on "${pageName}":`];
|
|
18
|
+
for (const f of failing.slice(0, 20)) {
|
|
19
|
+
lines.push(` [${f.severity}] ${f.ruleId} (WCAG ${f.criteriaId}) \u2014 ${f.origin?.sourceFile ?? f.file} \u2014 ${f.message}`);
|
|
20
|
+
}
|
|
21
|
+
if (failing.length > 20) lines.push(` \u2026 and ${failing.length - 20} more.`);
|
|
22
|
+
lines.push(`Full detail: ${where} \u2014 re-audit offline with \`ultra11y audit\`.`);
|
|
23
|
+
return lines.join("\n");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/integrations/core.ts
|
|
27
|
+
function enginePath() {
|
|
28
|
+
if (process.env.ULTRA11Y) return process.env.ULTRA11Y;
|
|
29
|
+
try {
|
|
30
|
+
return createRequire(import.meta.url).resolve("ultra11y/scripts/ultra11y.mjs");
|
|
31
|
+
} catch {
|
|
32
|
+
return new URL("../scripts/ultra11y.mjs", import.meta.url).pathname;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function auditCapture(payload, opts = {}, engine = enginePath()) {
|
|
36
|
+
return pipeToEngine(["capture", "write", "--json", ...opts.root ? ["--root", opts.root] : []], payload, engine);
|
|
37
|
+
}
|
|
38
|
+
function pipeToEngine(args, payload, engine) {
|
|
39
|
+
const res = spawnSync(process.execPath, [engine, ...args], {
|
|
40
|
+
input: JSON.stringify(payload),
|
|
41
|
+
encoding: "utf8",
|
|
42
|
+
maxBuffer: 192 * 1024 * 1024
|
|
43
|
+
});
|
|
44
|
+
if (res.error) throw new Error(`ultra11y: could not run the engine at ${engine} \u2014 ${res.error.message}`);
|
|
45
|
+
if (!res.stdout) throw new Error(`ultra11y: the engine produced no output (exit ${res.status})
|
|
46
|
+
${res.stderr || ""}`);
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(res.stdout);
|
|
49
|
+
} catch {
|
|
50
|
+
throw new Error(`ultra11y: could not parse the engine output
|
|
51
|
+
${res.stdout.slice(0, 500)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/integrations/unit.ts
|
|
56
|
+
var escText = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
57
|
+
function nodeHtml(n) {
|
|
58
|
+
if (n.nodeType === 1 && typeof n.outerHTML === "string") return n.outerHTML;
|
|
59
|
+
if (n.nodeType === 3) return escText(n.textContent ?? "");
|
|
60
|
+
if (n.nodeType === 8) return `<!--${n.data ?? ""}-->`;
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
function serializeRender(target) {
|
|
64
|
+
if (typeof target === "string") return target;
|
|
65
|
+
if (target && typeof target === "object") {
|
|
66
|
+
if ("container" in target && target.container) return serializeRender(target.container);
|
|
67
|
+
const n = target;
|
|
68
|
+
if (n.nodeType === 9) return n.body?.innerHTML ?? "";
|
|
69
|
+
if (n.nodeType === 11) return Array.from(n.childNodes ?? [], nodeHtml).join("");
|
|
70
|
+
if (typeof n.outerHTML === "string") return n.outerHTML;
|
|
71
|
+
}
|
|
72
|
+
throw new TypeError(
|
|
73
|
+
"ultra11y: checkA11y expects an Element, a Document, a DocumentFragment, a Testing Library render result ({ container }) or an HTML string."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function domEnv(target) {
|
|
77
|
+
let node;
|
|
78
|
+
if (typeof target === "object" && target) node = "container" in target ? target.container : target;
|
|
79
|
+
const g = globalThis;
|
|
80
|
+
const ua = node?.ownerDocument?.defaultView?.navigator?.userAgent ?? node?.defaultView?.navigator?.userAgent ?? g.navigator?.userAgent ?? "";
|
|
81
|
+
if (/jsdom/i.test(ua)) return "jsdom";
|
|
82
|
+
if (/happy-?dom/i.test(ua) || g.happyDOM) return "happy-dom";
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
function currentTest() {
|
|
86
|
+
const g = globalThis;
|
|
87
|
+
const ex = g.expect ?? g[/* @__PURE__ */ Symbol.for("expect-global")];
|
|
88
|
+
try {
|
|
89
|
+
return ex?.getState?.() ?? {};
|
|
90
|
+
} catch {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function idSlug(s) {
|
|
95
|
+
const slug = s.normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
96
|
+
if (slug.length <= 80) return slug;
|
|
97
|
+
let h = 5381;
|
|
98
|
+
for (let i = 0; i < slug.length; i++) h = (h << 5) + h + slug.charCodeAt(i) >>> 0;
|
|
99
|
+
return `${slug.slice(0, 72).replace(/-+$/, "")}-${h.toString(36)}`;
|
|
100
|
+
}
|
|
101
|
+
var seen = /* @__PURE__ */ new Map();
|
|
102
|
+
function capturePayload(target, opts, runner, ctx = currentTest()) {
|
|
103
|
+
const html = serializeRender(target);
|
|
104
|
+
const root = opts.root ?? process.cwd();
|
|
105
|
+
const rel = (p) => {
|
|
106
|
+
if (!isAbsolute(p)) return p;
|
|
107
|
+
const fromRoot = relative(root, p);
|
|
108
|
+
return fromRoot.startsWith("..") ? relative(process.cwd(), p) : fromRoot;
|
|
109
|
+
};
|
|
110
|
+
const test = ctx.testPath ? rel(ctx.testPath).split("\\").join("/") : void 0;
|
|
111
|
+
const title = ctx.currentTestName;
|
|
112
|
+
let id = opts.as;
|
|
113
|
+
if (!id) {
|
|
114
|
+
const stem = test ? test.replace(/\.(test|spec)\.[cm]?[jt]sx?$|\.[cm]?[jt]sx?$/i, "") : "";
|
|
115
|
+
const base = idSlug([stem, title].filter(Boolean).join(" ")) || "capture";
|
|
116
|
+
const n = (seen.get(base) ?? 0) + 1;
|
|
117
|
+
seen.set(base, n);
|
|
118
|
+
id = n === 1 ? base : `${base}-${n}`;
|
|
119
|
+
}
|
|
120
|
+
const env = domEnv(target);
|
|
121
|
+
return {
|
|
122
|
+
meta: {
|
|
123
|
+
id,
|
|
124
|
+
...opts.name ?? title ? { name: opts.name ?? title } : {},
|
|
125
|
+
...opts.component ? { component: opts.component } : {},
|
|
126
|
+
...opts.source ? { source: opts.source } : {},
|
|
127
|
+
...test ? { test } : {},
|
|
128
|
+
runner,
|
|
129
|
+
...env ? { env } : {}
|
|
130
|
+
},
|
|
131
|
+
html
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
var CAPTURES = ".ultra11y/captures/";
|
|
135
|
+
function createUnitIntegration(runner) {
|
|
136
|
+
function record(target, opts, ctx) {
|
|
137
|
+
const payload = capturePayload(target, opts, runner, ctx ?? currentTest());
|
|
138
|
+
const result = auditCapture(payload, opts.root ? { root: opts.root } : {});
|
|
139
|
+
const failOn = opts.failOn === void 0 ? "blocking" : opts.failOn;
|
|
140
|
+
const failing = failOn === false ? [] : failingFindings(result, failOn);
|
|
141
|
+
return { result, failing, name: payload.meta.name ?? payload.meta.id };
|
|
142
|
+
}
|
|
143
|
+
async function checkA11y2(target, opts = {}) {
|
|
144
|
+
const { result, failing, name } = record(target, opts);
|
|
145
|
+
if (failing.length) throw new Error(formatFailure(name, failing, CAPTURES));
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
function toBeAccessible2(received, opts = {}) {
|
|
149
|
+
const ctx = this?.testPath || this?.currentTestName ? { testPath: this.testPath, currentTestName: this.currentTestName } : currentTest();
|
|
150
|
+
const { failing, name } = record(received, opts, ctx);
|
|
151
|
+
const pass = failing.length === 0;
|
|
152
|
+
return {
|
|
153
|
+
pass,
|
|
154
|
+
message: () => pass ? `ultra11y: expected "${name}" to carry a non-conformity at failOn "${opts.failOn ?? "blocking"}", and it carries none.` : formatFailure(name, failing, CAPTURES)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return { checkA11y: checkA11y2, toBeAccessible: toBeAccessible2 };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/integrations/jest.ts
|
|
161
|
+
var unit = createUnitIntegration("jest");
|
|
162
|
+
var checkA11y = unit.checkA11y;
|
|
163
|
+
var toBeAccessible = unit.toBeAccessible;
|
|
164
|
+
export {
|
|
165
|
+
checkA11y,
|
|
166
|
+
toBeAccessible
|
|
167
|
+
};
|
package/dist/playwright.mjs
CHANGED
|
@@ -1325,13 +1325,13 @@ function failingFindings(result, failOn) {
|
|
|
1325
1325
|
if (max === void 0) throw new Error(`ultra11y: failOn must be blocking|major|minor (got "${failOn}")`);
|
|
1326
1326
|
return (result.findings ?? []).filter((f) => !f.advisory && (RANK[f.severity] ?? 99) <= max);
|
|
1327
1327
|
}
|
|
1328
|
-
function formatFailure(pageName, failing) {
|
|
1328
|
+
function formatFailure(pageName, failing, where = ".ultra11y/pages/") {
|
|
1329
1329
|
const lines = [`ultra11y: ${failing.length} accessibility non-conformity(ies) on "${pageName}":`];
|
|
1330
1330
|
for (const f of failing.slice(0, 20)) {
|
|
1331
1331
|
lines.push(` [${f.severity}] ${f.ruleId} (WCAG ${f.criteriaId}) \u2014 ${f.origin?.sourceFile ?? f.file} \u2014 ${f.message}`);
|
|
1332
1332
|
}
|
|
1333
1333
|
if (failing.length > 20) lines.push(` \u2026 and ${failing.length - 20} more.`);
|
|
1334
|
-
lines.push(
|
|
1334
|
+
lines.push(`Full detail: ${where} \u2014 re-audit offline with \`ultra11y audit\`.`);
|
|
1335
1335
|
return lines.join("\n");
|
|
1336
1336
|
}
|
|
1337
1337
|
function slugify(url) {
|
|
@@ -1421,7 +1421,10 @@ function enginePath() {
|
|
|
1421
1421
|
}
|
|
1422
1422
|
}
|
|
1423
1423
|
function auditSnapshot(payload, engine = enginePath()) {
|
|
1424
|
-
|
|
1424
|
+
return pipeToEngine(["snapshot", "write", "--json"], payload, engine);
|
|
1425
|
+
}
|
|
1426
|
+
function pipeToEngine(args, payload, engine) {
|
|
1427
|
+
const res = spawnSync(process.execPath, [engine, ...args], {
|
|
1425
1428
|
input: JSON.stringify(payload),
|
|
1426
1429
|
encoding: "utf8",
|
|
1427
1430
|
maxBuffer: 192 * 1024 * 1024
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Options of `checkA11y` and `toBeAccessible`. */
|
|
2
|
+
interface UnitCheckOptions {
|
|
3
|
+
/** Capture id — the file stem under `.ultra11y/captures/`. Defaults to the test file's repo-relative path and title. */
|
|
4
|
+
as?: string;
|
|
5
|
+
/** Human name for the capture. Defaults to the current test's title. */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** The component rendered, when the test file's name does not say it. */
|
|
8
|
+
component?: string;
|
|
9
|
+
/** Repo-relative source of the component, so findings are reported against YOUR code.
|
|
10
|
+
* Defaults to the test file without `.test`/`.spec`, when that file exists. */
|
|
11
|
+
source?: string;
|
|
12
|
+
/** Severity at which the check fails (default `blocking`), or `false` to record only. */
|
|
13
|
+
failOn?: "blocking" | "major" | "minor" | false;
|
|
14
|
+
/** Project root the capture is written under (default: the current directory). */
|
|
15
|
+
root?: string;
|
|
16
|
+
}
|
|
17
|
+
/** What can be checked: an element (`container`, `baseElement`), a Document, a DocumentFragment
|
|
18
|
+
* (`asFragment()`), a Testing Library render result, or an HTML string you rendered yourself. */
|
|
19
|
+
type Renderable = string | NodeLike | {
|
|
20
|
+
container: NodeLike;
|
|
21
|
+
};
|
|
22
|
+
interface NodeLike {
|
|
23
|
+
nodeType?: number;
|
|
24
|
+
outerHTML?: string;
|
|
25
|
+
textContent?: string | null;
|
|
26
|
+
data?: string;
|
|
27
|
+
childNodes?: ArrayLike<NodeLike>;
|
|
28
|
+
body?: NodeLike | null;
|
|
29
|
+
innerHTML?: string;
|
|
30
|
+
documentElement?: NodeLike | null;
|
|
31
|
+
ownerDocument?: {
|
|
32
|
+
defaultView?: {
|
|
33
|
+
navigator?: {
|
|
34
|
+
userAgent?: string;
|
|
35
|
+
};
|
|
36
|
+
} | null;
|
|
37
|
+
} | null;
|
|
38
|
+
defaultView?: {
|
|
39
|
+
navigator?: {
|
|
40
|
+
userAgent?: string;
|
|
41
|
+
};
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
/** The running test, as the runner's own `expect` state reports it. Vitest installs its `expect`
|
|
45
|
+
* under `Symbol.for("expect-global")` whether or not globals are on; Jest exposes `expect`. */
|
|
46
|
+
interface TestContext {
|
|
47
|
+
testPath?: string;
|
|
48
|
+
currentTestName?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type { Renderable as R, TestContext as T, UnitCheckOptions as U };
|
package/dist/vitest.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { U as UnitCheckOptions, R as Renderable, T as TestContext } from './unit-C7c8k68J.js';
|
|
2
|
+
import { A as AuditLike } from './payload-BrdH5eEV.js';
|
|
3
|
+
export { F as FindingLike } from './payload-BrdH5eEV.js';
|
|
4
|
+
|
|
5
|
+
/** Audit a rendered component; throws when a finding reaches `failOn` (default `blocking`). */
|
|
6
|
+
declare const checkA11y: (target: Renderable, opts?: UnitCheckOptions) => Promise<AuditLike>;
|
|
7
|
+
/** The matcher, for `expect.extend({ toBeAccessible })`. */
|
|
8
|
+
declare const toBeAccessible: (this: (TestContext & {
|
|
9
|
+
isNot?: boolean;
|
|
10
|
+
}) | undefined, received: Renderable, opts?: UnitCheckOptions) => {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message: () => string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
declare module "vitest" {
|
|
16
|
+
interface Assertion<T = any> {
|
|
17
|
+
/** Audit the rendered component with ultra11y; fails when a finding reaches `failOn`. */
|
|
18
|
+
toBeAccessible(opts?: UnitCheckOptions): T;
|
|
19
|
+
}
|
|
20
|
+
interface AsymmetricMatchersContaining {
|
|
21
|
+
toBeAccessible(opts?: UnitCheckOptions): unknown;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { AuditLike, Renderable, UnitCheckOptions, checkA11y, toBeAccessible };
|
package/dist/vitest.mjs
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// src/integrations/unit.ts
|
|
2
|
+
import { isAbsolute, relative } from "path";
|
|
3
|
+
|
|
4
|
+
// src/integrations/core.ts
|
|
5
|
+
import { spawnSync } from "child_process";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
|
|
8
|
+
// src/integrations/payload.ts
|
|
9
|
+
var RANK = { bloquant: 0, majeur: 1, mineur: 2 };
|
|
10
|
+
var THRESHOLD = { blocking: 0, bloquant: 0, major: 1, majeur: 1, minor: 2, mineur: 2 };
|
|
11
|
+
function failingFindings(result, failOn) {
|
|
12
|
+
const max = THRESHOLD[failOn];
|
|
13
|
+
if (max === void 0) throw new Error(`ultra11y: failOn must be blocking|major|minor (got "${failOn}")`);
|
|
14
|
+
return (result.findings ?? []).filter((f) => !f.advisory && (RANK[f.severity] ?? 99) <= max);
|
|
15
|
+
}
|
|
16
|
+
function formatFailure(pageName, failing, where = ".ultra11y/pages/") {
|
|
17
|
+
const lines = [`ultra11y: ${failing.length} accessibility non-conformity(ies) on "${pageName}":`];
|
|
18
|
+
for (const f of failing.slice(0, 20)) {
|
|
19
|
+
lines.push(` [${f.severity}] ${f.ruleId} (WCAG ${f.criteriaId}) \u2014 ${f.origin?.sourceFile ?? f.file} \u2014 ${f.message}`);
|
|
20
|
+
}
|
|
21
|
+
if (failing.length > 20) lines.push(` \u2026 and ${failing.length - 20} more.`);
|
|
22
|
+
lines.push(`Full detail: ${where} \u2014 re-audit offline with \`ultra11y audit\`.`);
|
|
23
|
+
return lines.join("\n");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/integrations/core.ts
|
|
27
|
+
function enginePath() {
|
|
28
|
+
if (process.env.ULTRA11Y) return process.env.ULTRA11Y;
|
|
29
|
+
try {
|
|
30
|
+
return createRequire(import.meta.url).resolve("ultra11y/scripts/ultra11y.mjs");
|
|
31
|
+
} catch {
|
|
32
|
+
return new URL("../scripts/ultra11y.mjs", import.meta.url).pathname;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function auditCapture(payload, opts = {}, engine = enginePath()) {
|
|
36
|
+
return pipeToEngine(["capture", "write", "--json", ...opts.root ? ["--root", opts.root] : []], payload, engine);
|
|
37
|
+
}
|
|
38
|
+
function pipeToEngine(args, payload, engine) {
|
|
39
|
+
const res = spawnSync(process.execPath, [engine, ...args], {
|
|
40
|
+
input: JSON.stringify(payload),
|
|
41
|
+
encoding: "utf8",
|
|
42
|
+
maxBuffer: 192 * 1024 * 1024
|
|
43
|
+
});
|
|
44
|
+
if (res.error) throw new Error(`ultra11y: could not run the engine at ${engine} \u2014 ${res.error.message}`);
|
|
45
|
+
if (!res.stdout) throw new Error(`ultra11y: the engine produced no output (exit ${res.status})
|
|
46
|
+
${res.stderr || ""}`);
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(res.stdout);
|
|
49
|
+
} catch {
|
|
50
|
+
throw new Error(`ultra11y: could not parse the engine output
|
|
51
|
+
${res.stdout.slice(0, 500)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/integrations/unit.ts
|
|
56
|
+
var escText = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
57
|
+
function nodeHtml(n) {
|
|
58
|
+
if (n.nodeType === 1 && typeof n.outerHTML === "string") return n.outerHTML;
|
|
59
|
+
if (n.nodeType === 3) return escText(n.textContent ?? "");
|
|
60
|
+
if (n.nodeType === 8) return `<!--${n.data ?? ""}-->`;
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
function serializeRender(target) {
|
|
64
|
+
if (typeof target === "string") return target;
|
|
65
|
+
if (target && typeof target === "object") {
|
|
66
|
+
if ("container" in target && target.container) return serializeRender(target.container);
|
|
67
|
+
const n = target;
|
|
68
|
+
if (n.nodeType === 9) return n.body?.innerHTML ?? "";
|
|
69
|
+
if (n.nodeType === 11) return Array.from(n.childNodes ?? [], nodeHtml).join("");
|
|
70
|
+
if (typeof n.outerHTML === "string") return n.outerHTML;
|
|
71
|
+
}
|
|
72
|
+
throw new TypeError(
|
|
73
|
+
"ultra11y: checkA11y expects an Element, a Document, a DocumentFragment, a Testing Library render result ({ container }) or an HTML string."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function domEnv(target) {
|
|
77
|
+
let node;
|
|
78
|
+
if (typeof target === "object" && target) node = "container" in target ? target.container : target;
|
|
79
|
+
const g = globalThis;
|
|
80
|
+
const ua = node?.ownerDocument?.defaultView?.navigator?.userAgent ?? node?.defaultView?.navigator?.userAgent ?? g.navigator?.userAgent ?? "";
|
|
81
|
+
if (/jsdom/i.test(ua)) return "jsdom";
|
|
82
|
+
if (/happy-?dom/i.test(ua) || g.happyDOM) return "happy-dom";
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
function currentTest() {
|
|
86
|
+
const g = globalThis;
|
|
87
|
+
const ex = g.expect ?? g[/* @__PURE__ */ Symbol.for("expect-global")];
|
|
88
|
+
try {
|
|
89
|
+
return ex?.getState?.() ?? {};
|
|
90
|
+
} catch {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function idSlug(s) {
|
|
95
|
+
const slug = s.normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
96
|
+
if (slug.length <= 80) return slug;
|
|
97
|
+
let h = 5381;
|
|
98
|
+
for (let i = 0; i < slug.length; i++) h = (h << 5) + h + slug.charCodeAt(i) >>> 0;
|
|
99
|
+
return `${slug.slice(0, 72).replace(/-+$/, "")}-${h.toString(36)}`;
|
|
100
|
+
}
|
|
101
|
+
var seen = /* @__PURE__ */ new Map();
|
|
102
|
+
function capturePayload(target, opts, runner, ctx = currentTest()) {
|
|
103
|
+
const html = serializeRender(target);
|
|
104
|
+
const root = opts.root ?? process.cwd();
|
|
105
|
+
const rel = (p) => {
|
|
106
|
+
if (!isAbsolute(p)) return p;
|
|
107
|
+
const fromRoot = relative(root, p);
|
|
108
|
+
return fromRoot.startsWith("..") ? relative(process.cwd(), p) : fromRoot;
|
|
109
|
+
};
|
|
110
|
+
const test = ctx.testPath ? rel(ctx.testPath).split("\\").join("/") : void 0;
|
|
111
|
+
const title = ctx.currentTestName;
|
|
112
|
+
let id = opts.as;
|
|
113
|
+
if (!id) {
|
|
114
|
+
const stem = test ? test.replace(/\.(test|spec)\.[cm]?[jt]sx?$|\.[cm]?[jt]sx?$/i, "") : "";
|
|
115
|
+
const base = idSlug([stem, title].filter(Boolean).join(" ")) || "capture";
|
|
116
|
+
const n = (seen.get(base) ?? 0) + 1;
|
|
117
|
+
seen.set(base, n);
|
|
118
|
+
id = n === 1 ? base : `${base}-${n}`;
|
|
119
|
+
}
|
|
120
|
+
const env = domEnv(target);
|
|
121
|
+
return {
|
|
122
|
+
meta: {
|
|
123
|
+
id,
|
|
124
|
+
...opts.name ?? title ? { name: opts.name ?? title } : {},
|
|
125
|
+
...opts.component ? { component: opts.component } : {},
|
|
126
|
+
...opts.source ? { source: opts.source } : {},
|
|
127
|
+
...test ? { test } : {},
|
|
128
|
+
runner,
|
|
129
|
+
...env ? { env } : {}
|
|
130
|
+
},
|
|
131
|
+
html
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
var CAPTURES = ".ultra11y/captures/";
|
|
135
|
+
function createUnitIntegration(runner) {
|
|
136
|
+
function record(target, opts, ctx) {
|
|
137
|
+
const payload = capturePayload(target, opts, runner, ctx ?? currentTest());
|
|
138
|
+
const result = auditCapture(payload, opts.root ? { root: opts.root } : {});
|
|
139
|
+
const failOn = opts.failOn === void 0 ? "blocking" : opts.failOn;
|
|
140
|
+
const failing = failOn === false ? [] : failingFindings(result, failOn);
|
|
141
|
+
return { result, failing, name: payload.meta.name ?? payload.meta.id };
|
|
142
|
+
}
|
|
143
|
+
async function checkA11y2(target, opts = {}) {
|
|
144
|
+
const { result, failing, name } = record(target, opts);
|
|
145
|
+
if (failing.length) throw new Error(formatFailure(name, failing, CAPTURES));
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
function toBeAccessible2(received, opts = {}) {
|
|
149
|
+
const ctx = this?.testPath || this?.currentTestName ? { testPath: this.testPath, currentTestName: this.currentTestName } : currentTest();
|
|
150
|
+
const { failing, name } = record(received, opts, ctx);
|
|
151
|
+
const pass = failing.length === 0;
|
|
152
|
+
return {
|
|
153
|
+
pass,
|
|
154
|
+
message: () => pass ? `ultra11y: expected "${name}" to carry a non-conformity at failOn "${opts.failOn ?? "blocking"}", and it carries none.` : formatFailure(name, failing, CAPTURES)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return { checkA11y: checkA11y2, toBeAccessible: toBeAccessible2 };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/integrations/vitest.ts
|
|
161
|
+
var unit = createUnitIntegration("vitest");
|
|
162
|
+
var checkA11y = unit.checkA11y;
|
|
163
|
+
var toBeAccessible = unit.toBeAccessible;
|
|
164
|
+
export {
|
|
165
|
+
checkA11y,
|
|
166
|
+
toBeAccessible
|
|
167
|
+
};
|