Accessibility Testing Setup
Overview
This demo project now includes comprehensive accessibility testing at multiple levels:
π§ͺ Test Types
1. Unit Tests (Jest + jest-axe)
- Location:
__tests__/accessibility.test.tsx
- What it tests: Component-level accessibility violations
- Run:
npm test
- Coverage:
npm test -- --coverage
Tests include:
- Automated axe-core scanning
- Heading hierarchy validation
- Skip link functionality
- Form label associations
- ARIA attributes
- Button accessibility
2. End-to-End Tests (Playwright + axe-playwright)
- Location:
e2e/accessibility.spec.ts
- What it tests: Full application accessibility in real browsers
- Run:
npm run test:e2e
- UI Mode:
npm run test:e2e:ui
Tests include:
- WCAG 2.1 AA compliance
- Keyboard navigation
- Focus management
- Dark mode accessibility
- Color contrast
- Table accessibility
- Link descriptiveness
- Form controls
3. Automated Scans (Pa11y CI)
- Location:
.pa11yci.json
- What it tests: Page-level accessibility issues
- Run:
npm run test:a11y
Features:
- Tests multiple color schemes
- Captures screenshots
- Tests both light and dark modes
- HTMLCS and axe runners
4. Lighthouse CI
- Location:
lighthouse-ci.config.js
- What it tests: Overall site quality and accessibility
- Run:
npm run lighthouse
Metrics:
- Accessibility score (min 90%)
- Best practices
- SEO
- Performance indicators
π Quick Start
Install Dependencies
Install Playwright Browsers
Run All Tests
# Unit tests
npm test
# E2E tests
npm run test:e2e
# Pa11y scan
npm run test:a11y
# Lighthouse audit
npm run lighthouse
π Test Coverage
The test suite covers all WCAG 2.1 AA requirements:
β
Perceivable
β
Operable
β
Understandable
β
Robust
π CI/CD Integration
A GitHub Actions workflow is configured at .github/workflows/accessibility-tests.yml:
On every push/PR:
- Runs unit tests with coverage
- Builds the application
- Runs E2E Playwright tests
- Performs Pa11y accessibility scan
- Generates Lighthouse reports
- Comments results on PRs
π Test Reports
Unit Tests
- Terminal output with pass/fail
- Coverage report in
coverage/ directory
- Open
coverage/lcov-report/index.html in browser
E2E Tests
- HTML report:
npx playwright show-report
- Screenshots on failure
- Video recordings (if enabled)
Pa11y
- Terminal output with violations
- Screenshots in
pa11y-screenshots/
Lighthouse
- HTML reports in
.lighthouseci/
- Accessibility score breakdown
π οΈ Development Workflow
Before Committing
# Run quick test
npm test
# Full accessibility check
npm run test:e2e
During Development
# Watch mode for unit tests
npm test -- --watch
# UI mode for E2E tests
npm run test:e2e:ui
Before Deploying
# Full test suite
npm test && npm run test:e2e && npm run test:a11y
π Debugging Failed Tests
Unit Test Failures
- Check the violation details in terminal
- Run specific test:
npm test -- -t "test name"
- Add
console.log for debugging
- Check
__tests__/accessibility.test.tsx
E2E Test Failures
- View screenshot in test report
- Run in debug mode:
npm run test:e2e:debug
- Use UI mode:
npm run test:e2e:ui
- Check browser console logs in report
Pa11y Failures
- Review terminal output for specific violations
- Check screenshots in
pa11y-screenshots/
- Test manually with browser DevTools
- Verify with screen reader
π Additional Resources
Accessibility Standards
π― Best Practices
- Run tests frequently - Donβt wait until the end
- Fix violations immediately - Technical debt grows quickly
- Test with real users - Automated tests canβt catch everything
- Use multiple tools - Each tool catches different issues
- Manual testing is essential - Use keyboard and screen readers
- Keep learning - Accessibility standards evolve
π€ Contributing
When adding new features:
- Write accessibility tests first (TDD)
- Ensure all tests pass
- Test manually with keyboard and screen reader
- Update test documentation if needed
π Notes
- Tests run on every PR via GitHub Actions
- Minimum accessibility score: 90%
- Tests cover both light and dark modes
- Mobile viewports included in E2E tests
- All test output is preserved in CI artifacts