Skip to main content

Overview

The Bitwarden clients repository uses Storybook as the primary tool for component-level E2E testing and visual regression testing. Storybook provides an isolated environment for developing and testing UI components.

Storybook Configuration

Available Commands

Storybook Dependencies

From package.json:

Storybook Features

1. Component Development

Storybook provides an isolated environment to develop components:
  • Live preview of component variations
  • Interactive controls for component props
  • Documentation alongside components
  • Accessibility testing via a11y addon

2. Visual Regression Testing

Using Chromatic for visual testing:
The repository includes chromatic as a dependency for automated visual regression testing.

3. Accessibility Testing

The @storybook/addon-a11y addon automatically checks components for accessibility issues:
  • WCAG compliance violations
  • Color contrast issues
  • ARIA attribute problems
  • Keyboard navigation issues

Writing Stories

While the source files weren’t provided, typical Storybook stories in Angular projects follow this pattern:

Basic Component Story

Interactive Story with Actions

Story with Multiple Components

Test Runner

The Storybook test runner uses @storybook/test-runner to run automated tests:

Basic Test Configuration

Create a .storybook/test-runner.ts file:

Running Tests

Testing Strategies

1. Visual Testing

Capture visual snapshots of components in different states:

2. Interaction Testing

Test user interactions with the @storybook/test library:

3. Responsive Testing

Test components at different viewport sizes:

4. Theme Testing

Test components with different themes using @storybook/addon-themes:

Accessibility Testing

Using the A11y Addon

The @storybook/addon-a11y automatically runs accessibility checks:

Programmatic A11y Testing

Using axe-playwright in test runner:

Component Testing Workflow

1. Develop Component

2. Create Stories

Create a .stories.ts file alongside your component:

3. Write Interaction Tests

Add play functions to test user interactions.

4. Run Tests

5. Visual Review

Use Chromatic or manual review to catch visual regressions.

Best Practices

1. Story Organization

  • Use clear story names: Primary, Disabled, WithError
  • Group related stories under the same title
  • Use autodocs tag to generate documentation

2. Component Variations

Create stories for all important states:

3. Interaction Testing

  • Test happy paths
  • Test error states
  • Test form validation
  • Test async operations

4. Accessibility

  • Always enable a11y addon
  • Test keyboard navigation
  • Verify ARIA labels
  • Check color contrast

CI/CD Integration

GitHub Actions Example

Troubleshooting

Storybook Won’t Start

  1. Clear cache: rm -rf node_modules/.cache/storybook
  2. Reinstall dependencies: npm ci
  3. Check for port conflicts (default: 6006)

Test Runner Failing

  1. Ensure Storybook is running: npm run storybook
  2. Check the test URL: http://localhost:6006
  3. Increase timeout for slow tests

Accessibility Violations

  1. Review the a11y panel in Storybook UI
  2. Fix violations in component code
  3. Re-run tests to verify fixes

Alternative E2E Approaches

While Storybook is the primary E2E tool, other approaches include:

Browser Extension Testing

For the browser extension (apps/browser):
  • Manual testing in browser environments
  • Extension-specific test utilities
  • Browser automation with Puppeteer/Playwright (if configured)

Desktop App Testing

For Electron app (apps/desktop):
  • Spectron or Playwright Electron (if configured)
  • Manual testing in development mode

CLI Testing

For CLI app (apps/cli):
  • Integration tests with real commands
  • Mock API responses for offline testing

Resources