Swiftpack.co - BarredEwe/Prefire as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by BarredEwe.
BarredEwe/Prefire 0.1.0
🔥 A library based on SwiftUI Preview, for easy generation: Playbook view, Snapshot and Accessibility tests
⭐️ 14
🕓 6 weeks ago
iOS
.package(url: "https://github.com/BarredEwe/Prefire.git", from: "0.1.0")

Prefire

A library for easy automatic Playbook (Demo) view and Test generation using SwiftUI Preview

Works with: UI-components, screens and flows

Prefire

Playbook

Swift5 Swift Package Manager

Do you like SwiftUI Preview and use it? Then you must trying 🔥Prefire!

You can try 🔥Prefire starting from example project.

  • Easy to use
  • Fully automatic generation based on Sourcery
  • Generation:


Installation

  1. Install Sourcery using Homebrew
brew install sourcery
  1. Install Prefire using Swift Package Manager

    Select Xcode menu File > Swift Packages > Add Package Dependency... and enter repository URL with GUI.

https://github.com/BarredEwe/Prefire

Setup

Playbook (Demo) View

For generating Playbook you should first:

  • Add Build Phase to main target for generating Demo App:
export PATH="$PATH:${BUILD_DIR%Build/*}SourcePackages/checkouts/Prefire"
prefire playbook --sources <sources path> --output <output path>
  • Fill <sources path> and <output path>. Example:
prefire playbook --sources ./ -- output Sources/PreviewModel.generated.swift
  • Uncheck mark ✅ Based on dependecy analysis.
  • Build your project
  • Add genereted file to your project

Snapshot tests

For generating tests you should first:

  • Add Build Phase to test target for generating Snapshot tests:
export PATH="$PATH:${BUILD_DIR%Build/*}SourcePackages/checkouts/Prefire"
prefire tests --sources <sources path> --output <output path> --target <test target>
  • Fill <sources path>, <output path> and <test target>. Example:
prefire tests --sources ./ -- output Tests/PrefireTests.generated.swift --target MyProject
  • Uncheck mark ✅ Based on dependecy analysis.
  • Build (CMD + B) your project
  • For runnug test you should add genereted file to your project in testTarget.

Usage

For generating tests and playbook, just mark your preview using protocol PrefireProvider:

struct Text_Previews: PreviewProvider, PrefireProvider {
    static var previews: some View { ... }
}

Playbook (Demo) View

For using Playbook just use PlaybookView

import Prefire 

struct ContentView: View {
    var body: some View {
        PlaybookView(isComponent: true, previewModels: PreviewModels.models)
    }
}

Snapshot tests

Just run generated test 🚀

For detailed instruction you can see swift-snapshot-testing


API

New commands for previews:

  • Function for connecting preview together in one Flow:

    .previewUserStory(.auth)
    

    For example Authorization flow (LoginView, OTPView, PincodeView)

  • If a preview contains more than one View, you can mark State for these views.

    .previewState(.loading)
    
    static var previews: some View {
        Text("Default")
    
        Text("Loading")
            .previewState(.loading)
    }
    

Config

prefire script configs:

  • --sources* - Path to a source swift files or directories with Views.
  • --output* - Path to output file.
  • --target - Your project Target for Snapshot tests. Default: empty
  • --sourcery - Custom path to Sourcery. Default: path from brew.
  • --device - Device for Snapshot testing. Default: iPhone 12
  • --os_version - iOS version for Snapshot testing. Default: iOS 15 ```

Requirements

  • Swift 5.1+
  • Xcode 11.0+
  • iOS 14+

Previews Troubleshooting

  • Don't forget remove #IF DEBUG for yours SwiftUI Previews. Xcode automatically removed Preview code, when you build release version.
  • NavigationView in Preview is not supported

GitHub

link
Stars: 14
Last commit: 5 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

The first release of Prefire 🔥
6 weeks ago

The first release of Prefire 🔥 I hope, you enjoy it!

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics