Prefire

Instant snapshots from SwiftUI #Previews

Prefire turns your #Preview blocks into snapshot tests, living docs & playbooks — automatically.

iOS playbook previews snapshot-testing Swift 6 SwiftUI tvOS UIKit Xcode Plugins iOS playbook previews snapshot-testing Swift 6 SwiftUI tvOS UIKit Xcode Plugins iOS playbook previews snapshot-testing Swift 6 SwiftUI tvOS UIKit Xcode Plugins

🔥 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.

  1. Add Prefire via File → Add Packages…
  2. Select your unit test target.
  3. Attach PrefireTestsPlugin under Build Tool Plugins.
  4. 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

  1. Add Prefire to your Package.swift (see Installation).
  2. Create a #Preview, e.g. #Preview { Button("Submit") }
  3. Run the test target — Prefire will generate & run snapshot tests.

🔍 How Prefire Works

1

Parse SourceFiles

Scans all Swift files, detecting #Preview blocks and PreviewProviders with modifiers like .prefireEnabled() or .prefireIgnored().

2

Cache Models

Fingerprints AST & preview bodies (SHA‑256 + timestamps) to skip work on unchanged files.

3

Generate Snapshot Tests

Uses Stencil templates & your .prefire.yml to emit Swift tests executed via PrefireTestsPlugin.

4

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 ⭐️!