code-society-25-2

Accessibility Testing Setup

Overview

This demo project now includes comprehensive accessibility testing at multiple levels:

πŸ§ͺ Test Types

1. Unit Tests (Jest + jest-axe)

Tests include:

2. End-to-End Tests (Playwright + axe-playwright)

Tests include:

3. Automated Scans (Pa11y CI)

Features:

4. Lighthouse CI

Metrics:

πŸš€ Quick Start

Install Dependencies

npm install

Install Playwright Browsers

npx playwright install

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:

  1. Runs unit tests with coverage
  2. Builds the application
  3. Runs E2E Playwright tests
  4. Performs Pa11y accessibility scan
  5. Generates Lighthouse reports
  6. Comments results on PRs

πŸ“Š Test Reports

Unit Tests

E2E Tests

Pa11y

Lighthouse

πŸ› οΈ 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

  1. Check the violation details in terminal
  2. Run specific test: npm test -- -t "test name"
  3. Add console.log for debugging
  4. Check __tests__/accessibility.test.tsx

E2E Test Failures

  1. View screenshot in test report
  2. Run in debug mode: npm run test:e2e:debug
  3. Use UI mode: npm run test:e2e:ui
  4. Check browser console logs in report

Pa11y Failures

  1. Review terminal output for specific violations
  2. Check screenshots in pa11y-screenshots/
  3. Test manually with browser DevTools
  4. Verify with screen reader

πŸ“š Additional Resources

Testing Tools

Accessibility Standards

🎯 Best Practices

  1. Run tests frequently - Don’t wait until the end
  2. Fix violations immediately - Technical debt grows quickly
  3. Test with real users - Automated tests can’t catch everything
  4. Use multiple tools - Each tool catches different issues
  5. Manual testing is essential - Use keyboard and screen readers
  6. Keep learning - Accessibility standards evolve

🀝 Contributing

When adding new features:

  1. Write accessibility tests first (TDD)
  2. Ensure all tests pass
  3. Test manually with keyboard and screen reader
  4. Update test documentation if needed

πŸ“ Notes