Skip to content

Commit 1458d70

Browse files
authored
Merge pull request #1565 from coseeian/a11y-playwright-home
feat: setup local a11y playwright test for homepage
2 parents 53e14a6 + 6047fd2 commit 1458d70

7 files changed

Lines changed: 94 additions & 1 deletion

File tree

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ public/p5.min.js
3131
# optional local preferences for vscode
3232
local.code-workspace
3333
.zed
34+
35+
# Playwright accessibility test output
36+
test-results/
37+
playwright-report/

‎astro.config.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ if (shouldSkipCompress) {
1616
console.log("WILL SKIP COMPRESS BUILD STEP");
1717
}
1818

19+
const isA11yTest = Boolean(process.env.A11Y_TEST);
20+
1921
// https://astro.build/config
2022
export default defineConfig({
2123
site: 'https://p5js.org',
2224
compressHTML: false,
25+
devToolbar: {
26+
enabled: !isA11yTest,
27+
},
2328
integrations: [
2429
mermaid({autoTheme: true}),
2530
preact({

‎package-lock.json‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"deploy": "wrangler deploy --env beta",
1414
"astro": "astro",
1515
"test": "vitest",
16+
"test:a11y": "playwright test",
1617
"build:contributor-docs": "tsx ./src/scripts/builders/contribute.ts",
1718
"build:contributors": "tsx ./src/scripts/builders/people.ts",
1819
"build:reference": "tsx ./src/scripts/builders/reference.ts",
@@ -59,6 +60,7 @@
5960
"vite": "^7"
6061
},
6162
"devDependencies": {
63+
"@axe-core/playwright": "^4.12.1",
6264
"@codemirror/lang-javascript": "^6.2.2",
6365
"@playwright/test": "^1.54.1",
6466
"@preact/preset-vite": "^2.10.5",

‎playwright.config.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
const PORT = 4321;
4+
const BASE_URL = `http://localhost:${PORT}`;
5+
6+
export default defineConfig({
7+
testDir: "./test/a11y",
8+
testMatch: "**/*.spec.ts",
9+
outputDir: "./test-results",
10+
fullyParallel: true,
11+
reporter: [
12+
["list"],
13+
['html', { outputFolder: 'playwright-report', open: 'never' }]
14+
],
15+
16+
use: {
17+
baseURL: BASE_URL,
18+
trace: "on-first-retry",
19+
},
20+
21+
// One engine, two viewports. axe-core inspects the DOM and computed styles,
22+
// which agree across engines, so a browser matrix mostly re-runs the same
23+
// assertions; a responsive layout can ship genuinely different markup per
24+
// breakpoint, so that is the axis worth covering.
25+
projects: [
26+
{
27+
name: "desktop",
28+
use: { ...devices["Desktop Chrome"] },
29+
},
30+
{
31+
name: "mobile",
32+
use: { ...devices["Pixel 5"] },
33+
},
34+
],
35+
36+
webServer: {
37+
command: "npm run dev",
38+
url: BASE_URL,
39+
reuseExistingServer: true,
40+
timeout: 180_000,
41+
env: {
42+
A11Y_TEST: "1",
43+
},
44+
},
45+
});

‎test/a11y/homepage.spec.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import AxeBuilder from "@axe-core/playwright";
2+
import { expect, test } from "@playwright/test";
3+
4+
test.describe("a11y-home-page", () => {
5+
test("should not have any automatically detectable accessibility issues", async ({
6+
page,
7+
}) => {
8+
await page.goto("/");
9+
const accessibilityScanResults = await new AxeBuilder({ page }).analyze();
10+
expect(accessibilityScanResults.violations).toEqual([]);
11+
});
12+
});

‎vitest.config.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default getViteConfig({
2121
exclude: [
2222
"test/api/OpenProcessing.test.ts",
2323
"test/pages/*",
24-
"test/mocks/*"
24+
"test/mocks/*",
25+
"test/a11y/**"
2526
]
2627
}
2728
},

0 commit comments

Comments
 (0)