Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Add @axe-core/playwright for accessibility testing (#1318)

Rajat Bhatt4ff00fac17be
diff --git a/apps/web/package.json b/apps/web/package.json
index 87feb642..2cae672d 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -13,10 +13,11 @@
"lint:fix": "eslint . --fix --cache --cache-location \"node_modules/.cache/.eslintcache\" --max-warnings 0",
"start": "dotenv -e ../../.env next start",
"test:e2e": "playwright test",
- "test:e2e:ui": "playwright test --ui",
+ "test:e2e:ui": "playwright test --ui --ui-port=8080",
"typecheck": "tsc --noEmit"
},
"dependencies": {
+ "@axe-core/playwright": "^4.8.2",
"@hookform/error-message": "^2.0.1",
"@hookform/resolvers": "^3.1.1",
"@mailchimp/mailchimp_marketing": "^3.0.80",
diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.css
index c93760bd..a7cae76b 100644
--- a/apps/web/src/styles/globals.css
+++ b/apps/web/src/styles/globals.css
@@ -10,7 +10,7 @@
--foreground: 240 10% 3.9%;
--muted: 240 4.8% 95.9%;
- --muted-foreground: 240 3.8% 46.1%;
+ --muted-foreground: 240 3.8% 45%;
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
diff --git a/apps/web/tests/e2e/constant.ts b/apps/web/tests/e2e/constant.ts
index e83b8ba4..10a424c5 100644
--- a/apps/web/tests/e2e/constant.ts
+++ b/apps/web/tests/e2e/constant.ts
@@ -3,3 +3,6 @@ export const USER = {
sessionToken: 'd4d6a53d-b2e0-42c7-a4b3-2d246ce2f54a',
};
+
+// These tags are required to test if we have any WCAG A or AA violations
+export const A11YTAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'];
diff --git a/apps/web/tests/e2e/unauthenticated/home.test.ts b/apps/web/tests/e2e/unauthenticated/home.test.ts
index 800c5444..ac237c52 100644
--- a/apps/web/tests/e2e/unauthenticated/home.test.ts
+++ b/apps/web/tests/e2e/unauthenticated/home.test.ts
@@ -1,9 +1,38 @@
import { test, expect } from '@playwright/test';
+import AxeBuilder from '@axe-core/playwright';
+import { A11YTAGS } from '../constant';
test.use({ storageState: 'playwright/.auth/unauthenticated.json' });
-test('home page', async ({ page }) => {
+test.beforeEach(async ({ page }) => {
+ // Go to the starting url before each test.
await page.goto('/');
+});
+test('home page', async ({ page }) => {
await expect(page.getByRole('heading', { name: 'type hero' })).toBeVisible();
});
+
+test.describe('homepage a11y', () => {
+ test('homepage should not have any automatically detectable WCAG A or AA violations in light mode', async ({
+ page,
+ }) => {
+ const a11yScanResults = await new AxeBuilder({ page }).withTags(A11YTAGS).analyze();
+
+ expect(a11yScanResults.violations).toEqual([]);
+ });
+
+ test('homepage should not have any automatically detectable WCAG A or AA violations in dark Mode', async ({
+ page,
+ }) => {
+ await page
+ .getByRole('button', {
+ name: /theme button/i,
+ })
+ .click();
+
+ const a11yScanResults = await new AxeBuilder({ page }).withTags(A11YTAGS).analyze();
+
+ expect(a11yScanResults.violations).toEqual([]);
+ });
+});
diff --git a/packages/ui/src/components/markdown.tsx b/packages/ui/src/components/markdown.tsx
index 5e41c58e..f129dea0 100644
--- a/packages/ui/src/components/markdown.tsx
+++ b/packages/ui/src/components/markdown.tsx
@@ -83,6 +83,9 @@ export function Markdown({ children, className }: { children: string; className?
fontSize: 'inherit',
lineHeight: 'inherit',
},
+ // This is required make it WCAG 2 compliant for scrolling through keyboard if the code overflows and have a scrollbar
+ // https://dequeuniversity.com/rules/axe/4.8/scrollable-region-focusable
+ tabIndex: 0,
}}
{...props}
>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8b676dac..6b66dd12 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -216,6 +216,9 @@ importers:
apps/web:
dependencies:
+ '@axe-core/playwright':
+ specifier: ^4.8.2
+ version: 4.8.2([email protected])
'@hookform/error-message':
specifier: ^2.0.1
@@ -981,6 +984,15 @@ packages:
- nodemailer
dev: false
+ resolution: {integrity: sha512-9KOhX2tNuvqn9DzpBNyqoqNKRZBrexeSiN9irQ0sEdq8zH13JnatepCJxobuXn4UopNy6iIpP4342beMiH+MSQ==}
+ peerDependencies:
+ playwright-core: '>= 1.0.0'
+ dependencies:
+ axe-core: 4.8.2
+ playwright-core: 1.38.0
+ dev: false
+
resolution: {integrity: sha512-/KKIMG4UEL35WmI9OlvMhurwtytjvXoFcGNrOvyG9zIzA8YmPjVtIZUf7b05+TPO7G7/GEmLHDaoCgACHl9hhA==}
engines: {node: '>=6.9.0'}
@@ -5688,6 +5700,11 @@ packages:
resolution: {integrity: sha512-zIURGIS1E1Q4pcrMjp+nnEh+16G56eG/MUllJH8yEvw7asDo7Ac9uhC9KIH5jzpITueEZolfYglnCGIuSBz39g==}
engines: {node: '>=4'}
+ resolution: {integrity: sha512-/dlp0fxyM3R8YW7MFzaHWXrf4zzbr0vaYb23VBFCl83R7nWNPg/yaQw2Dc8jzCMmDVLhSdzH8MjrsuIUuvX+6g==}
+ engines: {node: '>=4'}
+ dev: false
+
resolution: {integrity: sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==}
dependencies: