Testing & Verification

Visual Regression Testing & Deterministic Rasterization

Screenshot diffs generated on macOS Retina fail in Linux CI because CoreText and FreeType rasterize subpixel glyph edges differently; pinning container rasterizers and fonts eliminates false diffs.

About this page
READ
2 min
Interactive Simulator

Deterministic Rasterization for Visual Snapshots

Trace how OS font hinting and async web fonts cause false diffs, and how containerization stabilizes pixels.

Host Rasterizer
Web Fonts
Pixel Diff (3.2% FAIL)
Step 1 / 3: 1. Host-OS Divergence (macOS vs Linux)

macOS CoreText and Linux FreeType rasterize anti-aliased glyph edges differently, causing false diffs.

// macOS Retina DPR=2 vs Linux CI DPR=1 produces 3.2% pixel diff
Internal State / Memory
os
macOS vs Linux
dpr
2 vs 1
diffRatio
0.032
Deterministic Rasterization for Visual Snapshots

Under the Hood#

Blink's Skia backend delegates font shaping and glyph rasterization to the host OS text stack unless constrained by a uniform container environment.

  1. OS Font Hinting Divergence: macOS CoreText applies grayscale anti-aliasing at devicePixelRatio: 2, whereas Linux FreeType applies different hinting and LCD subpixel filtering at devicePixelRatio: 1.
  2. Font & Image Readiness: Capturing a frame before await document.fonts.ready or image decode causes FOUT fallback diffs across runs.
  3. Animation & Caret Freezing: Passing animations: 'disabled' and reducedMotion: 'reduce' (prefers-reduced-motion) fast-forwards CSS transitions to their final keyframe and hides blinking text carets.
TS
await page.emulateMedia({ reducedMotion: 'reduce' });
await page.evaluate(() => document.fonts.ready);

await expect(page.getByTestId('pricing-card')).toHaveScreenshot({
  animations: 'disabled',
  maxDiffPixelRatio: 0.005,
});

Problem Genealogy#

  • 2014 (PhantomJS / Host-OS Screenshots): Teams committed macOS baselines that failed 100% of Linux CI builds due to 1px-2px font baseline shifts.
  • 2018 (High threshold: 0.2 Workarounds): Raising pixel tolerance to silence font noise let real 2px border regressions and broken icons pass undetected.
  • 2022 (Pinned Docker Chromium + animations: 'disabled'): Standardizing on identical Linux container images cut false-positive visual diffs below 0.5% while preserving strict pixel thresholds.

Production Pitfalls#

  • Non-Deterministic <video> and WebGL Frames: Hardware-accelerated <canvas> and <video> elements decode at variable frame timestamps and GPU driver tolerances across runs.
  • Dynamic Timestamps & Avatars: Unmasked relative times (2 minutes ago) or external CDN images trigger constant pixel churn unless stubbed or passed in mask: [].

Where this connects

Prerequisites

Network & Performance

Font Loading & CLS Mechanics

Capturing screenshots before document.fonts.ready produces fallback-font diffs and layout shifts.

Security & Accessibility

User Preference Media Queries

Forcing prefers-reduced-motion disables mid-frame CSS transitions during screenshot capture.