-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha11y.ts
41 lines (32 loc) · 1.09 KB
/
a11y.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import AxeBuilder from "@axe-core/playwright";
import { type Page, expect, test } from "@playwright/test";
import type axe from "axe-core";
import { createHtmlReport } from "axe-html-reporter";
import { attachReport, clientCredentials, throwOnConsoleError } from "./utils";
const htmlReport = async (name: string, results: axe.AxeResults) => {
const reportFileName = `${test.info().project.name}-${name}.html`;
createHtmlReport({
results,
options: {
outputDir: "reports/a11y",
reportFileName
}
});
return `reports/a11y/${reportFileName}`;
};
const a11y = async (name: string, page: Page) => {
const results = await new AxeBuilder({ page }).analyze();
const path = await htmlReport(name, results);
await attachReport("axe-report", path);
return results;
};
test.describe("accessibility", () => {
test.describe.configure({ mode: "serial" });
test("home", async ({ page }) => {
throwOnConsoleError(page);
await clientCredentials(page);
await page.goto("/");
const results = await a11y("home", page);
expect(results.violations).toEqual([]);
});
});