πŸ”βŒ˜K

Start typing to search docs.

Visual Testing

1.0.0

Screenshot diffs and regression workflows for landing and dashboard apps.

🎨 Visual Regression Testing Implementation Complete

βœ… What's Been Implemented

1. Playwright Visual Testing for Storybook

  • Configuration: playwright.config.ts with multi-browser support
  • Test Suite: tests/visual/storybook.spec.ts covering all UI components
  • Coverage: 50+ visual tests across Button, Card, Input, List, Navigation, etc.
  • Responsive: Mobile, tablet, desktop viewports
  • Themes: Light and dark mode variations
  • Browsers: Chrome, Firefox, Safari, Mobile Chrome, Mobile Safari

2. Detox Visual Testing for React Native

  • Configuration: .detoxrc.js for Focus AI and Health Tracker apps
  • Test Suites: Separate test files for each mobile app
  • Coverage: Home, Settings, Paywall screens with component showcases
  • Orientations: Portrait and landscape testing
  • Themes: Light and dark mode support
  • Platform: Android emulator with screenshot capabilities

3. CI/CD Integration

  • GitHub Actions: .github/workflows/visual-regression.yml
  • Automated Testing: Runs on PRs and main branch pushes
  • Artifact Upload: Screenshots, reports, and test results
  • PR Comments: Automated visual diff reporting
  • Multi-Stage: Web and mobile tests run in parallel

4. Developer Tools

  • Helper Script: scripts/visual-tests.mjs for easy management
  • Package Scripts: Convenient npm/pnpm commands
  • Turbo Integration: Build pipeline optimization
  • Documentation: Comprehensive guide in VISUAL_TESTING_GUIDE.md

πŸš€ Quick Start Commands

# Setup everything
pnpm visual-tests setup

# Run web tests
pnpm visual-tests run-web

# Run mobile tests  
pnpm visual-tests run-mobile

# Update baselines when UI changes
pnpm visual-tests update-baselines

πŸ“Š Test Coverage

Web Components (Playwright + Storybook)

  • βœ… Button: 12 stories (variants, sizes, states, icons)
  • βœ… Card: 8 stories (variants, padding, interactive, custom content)
  • βœ… Input: 15 stories (variants, sizes, validation, forms)
  • βœ… List: 5 stories (icons, sections, interactive)
  • βœ… Navigation: 3 stories (horizontal, vertical, with icons)
  • βœ… Onboarding: 2 stories (default, with progress)
  • βœ… Paywall: 2 stories (default, premium)
  • βœ… PricingTable: 2 stories (default, highlighted)
  • βœ… Settings: 2 stories (default, with sections)
  • βœ… ThemeSwitcher: 2 stories (default, compact)

Mobile Screens (Detox + React Native)

  • βœ… Focus AI: Home, Settings, Paywall screens
  • βœ… Health Tracker: Home, Settings, Paywall screens
  • βœ… Component Showcases: Button, Card, Input variations
  • βœ… Dark Mode: All screens in dark theme
  • βœ… Orientations: Portrait and landscape

πŸ”„ CI Workflow

  1. Trigger: PR created/updated or push to main/develop
  2. Setup: Install dependencies, browsers, Android SDK
  3. Build: Compile UI packages and mobile apps
  4. Test Web: Run Playwright tests against Storybook
  5. Test Mobile: Run Detox tests on Android emulator
  6. Report: Upload artifacts and comment on PR
  7. Diff: Show visual differences for review

πŸ“ File Structure

app-factory/
β”œβ”€β”€ .github/workflows/visual-regression.yml    # CI configuration
β”œβ”€β”€ playwright.config.ts                       # Playwright config
β”œβ”€β”€ .detoxrc.js                                # Detox configuration
β”œβ”€β”€ tests/visual/storybook.spec.ts            # Web visual tests
β”œβ”€β”€ e2e/
β”‚   β”œβ”€β”€ jest.config.js                         # Jest config for Detox
β”‚   β”œβ”€β”€ init.ts                               # Detox setup
β”‚   β”œβ”€β”€ focus-ai-visual.test.ts              # Focus AI tests
β”‚   └── health-tracker-visual.test.ts        # Health Tracker tests
β”œβ”€β”€ scripts/visual-tests.mjs                  # Helper script
β”œβ”€β”€ VISUAL_TESTING_GUIDE.md                   # Comprehensive guide
└── README_VISUAL_TESTING.md                  # This summary

🎯 Benefits

For Developers

  • Early Detection: Catch UI regressions before they reach production
  • Confidence: Know that UI changes don't break existing components
  • Documentation: Visual documentation of all component states
  • Automation: No manual testing needed for visual consistency

For QA/Design

  • Visual Diffs: Clear before/after comparisons
  • Cross-Browser: Ensure consistency across all browsers
  • Mobile Testing: Automated mobile app screenshot testing
  • Baseline Management: Easy approval of intentional changes

For CI/CD

  • Automated: Runs automatically on every PR
  • Fast Feedback: Quick visual regression detection
  • Artifacts: Screenshots and reports for debugging
  • Integration: Works with existing GitHub workflow

πŸ”§ Maintenance

Updating Baselines

When you make intentional UI changes:

  1. Review Changes: Check what visual differences exist
  2. Validate: Ensure changes are correct and intentional
  3. Update: Run pnpm visual-tests update-baselines
  4. Commit: Add updated baseline images to git

Adding New Tests

For new components or screens:

  1. Storybook: Add comprehensive stories for web components
  2. Test IDs: Add testID props to React Native screens
  3. Test Files: Update test files with new scenarios
  4. Baselines: Run tests to generate initial baselines

Troubleshooting

  • Flaky Tests: Increase threshold or wait times
  • Browser Issues: Update Playwright browsers
  • Mobile Issues: Check Android emulator setup
  • CI Failures: Review logs and artifacts

πŸŽ‰ Success Metrics

With this implementation, you now have:

  • βœ… 50+ Visual Tests covering all key UI components
  • βœ… Multi-Platform testing (web + mobile)
  • βœ… Multi-Browser support (5 different browsers/viewports)
  • βœ… Automated CI with PR diff reporting
  • βœ… Developer Tools for easy management
  • βœ… Comprehensive Documentation for team onboarding

πŸ”— Next Steps

  1. Install Dependencies: Run pnpm install to get new packages
  2. Setup Environment: Run pnpm visual-tests setup
  3. Generate Baselines: Run initial tests to create baseline images
  4. Team Training: Share VISUAL_TESTING_GUIDE.md with the team
  5. CI Integration: Merge and watch CI run visual tests on PRs

Your visual regression testing infrastructure is now complete! πŸš€