Instant snapshots from SwiftUI #Previews
Prefire turns your #Preview
blocks into snapshot tests, living docs & playbooks — automatically.
🔥 Why Prefire?
Snapshot tests from your #Preview
blocks — no boilerplate.
Living documentation that's always in sync with your UI.
Ultra‑fast caching system prevents redundant parsing.
Works seamlessly with both SwiftUI and UIKit.
Integrates via CLI, SPM plugin, Xcode plugin, or CI.
Understand flows: user stories, states, variants & more.
🚀 Key Features
Smart Preview Parsing
Understands #Preview
, @Previewable
, flows & variations.
Automatic Snapshot Tests
Generates & executes pixel tests on every build.
Interactive Playbook View
A browsable catalog for designers & QA.
CLI & CI Integration
Runs in pipelines with zero configuration.
📦 Installation
Pick the method that fits your workflow.
- Add
Prefire
via File → Add Packages… - Select your unit test target.
- Attach
PrefireTestsPlugin
under Build Tool Plugins. - Build the target — snapshot tests are auto‑generated.
dependencies: [ .package(url: "https://github.com/BarredEwe/Prefire", from: "4.0.0") ], .testTarget( plugins: [ .plugin(name: "PrefireTestsPlugin", package: "Prefire") ] )
brew tap barredewe/prefire brew install prefire prefire tests prefire playbook
⚡️ Quick Start
- Add Prefire to your
Package.swift
(see Installation). - Create a
#Preview
, e.g.#Preview { Button("Submit") }
- Run the test target — Prefire will generate & run snapshot tests.
🔍 How Prefire Works
Parse SourceFiles
Scans all Swift files, detecting #Preview
blocks and PreviewProvider
s with modifiers like .prefireEnabled()
or .prefireIgnored()
.
Cache Models
Fingerprints AST & preview bodies (SHA‑256 + timestamps) to skip work on unchanged files.
Generate Snapshot Tests
Uses Stencil
templates & your .prefire.yml
to emit Swift tests executed via PrefireTestsPlugin
.
Build Playbook Models
Creates PreviewModels.generated.swift
grouping previews by UserStory and State for the interactive Playbook view.
🧠 Internal Architecture
- PrefireCore — AST parsing, preview detection & caching layer
- PrefireGenerator — Stencil‑based code generator for tests & models
- PrefireCacheManager — Unifies fingerprint & file‑cache logic
- PrefireTestsPlugin / PrefirePlaybookPlugin — Xcode & SPM integrations
- prefire CLI — Entry point for manual
tests
/playbook
commands
🧠 Usage Examples
#Preview { Text("Hello") } #Preview { LoginView() .previewUserStory(.auth) .previewState(.loading) .snapshot(delay: 0.3, precision: 0.95) }
Combine .previewUserStory()
, .previewState()
& .snapshot()
to define rich visual flows & quality checks.
🗂 Configuration
Customize generation with .prefire.yml
at your project root:
Show Example
test_configuration: target: MyApp test_file_path: Tests/Generated/PreviewTests.swift simulator_device: "iPhone15,2" preview_default_enabled: true sources: - {PROJECT_DIR}/Sources/ snapshot_devices: - iPhone 14 - iPad imports: - SwiftUI - UIKit testable_imports: - MyApp playbook_configuration: template_file_path: Templates/PreviewModels.stencil preview_default_enabled: true
Open Source
Prefire is fully open source and built by the community. Contributions, issues and stars are always welcome!
PRs, issues and feedback are highly appreciated — or just drop us a ⭐️!