Skip to content

Latest commit

 

History

History
120 lines (86 loc) · 6.94 KB

testing.md

File metadata and controls

120 lines (86 loc) · 6.94 KB

Testing Strategy

The Govie Design System uses a comprehensive, multi-layered testing strategy to ensure the stability, accessibility, and visual integrity of the HTML, React, Angular and Vue component libraries.

1. Unit Testing

Unit tests are utilised to verify core logic, utility functions, and component behaviours in isolation.

Coverage

Coverage counts the code consumers can reach through each library's published entry points. Stories, the shared Storybook metas and generated icon components are excluded. Angular also excludes the generated atoms whose gi-* components render the native element themselves instead of the core-* tag.

2. Interaction Testing (Storybook Play Functions)

Storybook serves as both a documentation platform and an isolated environment for End-to-End (E2E) component testing.

  • Tooling: Storybook Interaction Testing via play functions.
  • Methodology: Within *.stories.tsx files, play functions simulate user interactions (e.g., clicks, keyboard input) and assert DOM state changes.
  • Example: Refer to the Tabs component stories.
  • Verification: Every story runs in headless Chromium through @storybook/addon-vitest as part of pnpm run test.

3. Visual Regression Testing

A dual-tool approach is utilised to detect and prevent visual regressions across various browsers and viewports.

Chromatic (Cloud-based Review)

Chromatic is a cloud-based visual testing service integrated with Storybook that captures snapshots of every component state.

Playwright Visual Regression (Automated Snapshots)

An automated testing suite using Playwright for generating and comparing visual snapshots in the CI environment.

Local execution (Makefile)

Use the provided Makefile targets to run visual regression tests locally. These commands build the Playwright Docker image, start Storybook, execute tests, and manage snapshots.

Prerequisites:

  • Docker installed and running

Commands:

  • Build the Playwright image (uses Dockerfile.playwright)
    make build-visual-tests-image
  • Run the visual regression tests (builds Storybook and runs Playwright in Docker)
    make react-visual-tests
  • Update baseline screenshots after intentional visual changes
    make react-visual-update
  • Run or update the Angular visual regression tests
    make angular-visual-tests
    make angular-visual-update

Running a subset of tests

To run or update only a subset of stories, append Playwright's -g flag (grep on test title) to the command inside the react-visual-tests / react-visual-update Makefile targets. The flag accepts a regex, so you can match multiple components at once:

# Run only Autocomplete stories
... test -g "Autocomplete"

# Update snapshots for Autocomplete and Select
... test --update-snapshots -g "Autocomplete|Select"

This speeds up iteration when debugging a specific flaky component without re-running the full suite.

Reference: Makefile

4. CI/CD Integration

Regression testing is fully integrated into Azure DevOps Pipelines to ensure continuous quality assurance:

  1. Core Pipeline (pipeline.yaml):
    • Enforces linting and formatting standards (pnpm run lint, pnpm run format:check).
    • Executes library builds and unit tests.
    • Conducts security vulnerability scans.
  2. Visual Regression Pipeline (visual-regression.yaml):
    • Triggered by changes in the component libraries (react, html/ds, angular), the design packages and the themes.
    • Automates the build of libraries and Storybook instances.
    • Runs parallel Chromatic and Playwright visual suites across multiple browsers (Chromium, Firefox, Webkit) and mobile emulators (Android, iOS).

5. Test Exclusion Policy

Components or specific states that are unsuitable for visual testing (e.g. those containing persistent animations, loaders, or spinners) should be excluded:

  • Playwright: Apply the skip-playwright tag to the story.
  • Slow stories: For stories with play functions that need extra settle time before the screenshot, apply the slow tag — the test adds an additional wait of 3 seconds before capturing.