A team running 500+ SwiftUI snapshot tests discovered their tests passed locally but failed on GitHub Actions CI. After ruling out resolution mismatches, font rendering differences, and non-deterministic animations, they found the root cause: swift-snapshot-testing renders views inside an NSWindow, and the title bar height differs between physical Macs and headless CI VMs, causing images to be 167 pixels shorter on CI. The fix was to bypass NSWindow entirely and render directly to an NSHostingView using cacheDisplay(in:to:), eliminating the environment-dependent offset. As a bonus, they also migrated from iOS Simulator to macOS for testing, cutting local test time from 170s to 7s and CI time from ~30 to ~17 minutes. Key diagnostic tip: use sips to compare pixel dimensions of reference vs failure images before tuning precision thresholds.
Table of contents
Why we moved from iOS Simulator to macOSWhat we tried (and why it didn't work)The root causeThe fixA subtle gotcha: cacheDisplay vs displayIgnoringOpacityThe takeawayRelevant linksSort: