A library for easy automatic Playbook (Demo) view and Test generation using SwiftUI Preview
Works with: UI-components, screens and flows
Do you like SwiftUI Preview and use it? Then you must trying 🔥Prefire!
You can try 🔥Prefire starting from example project.
Prefire can be install for all your Xcode Project
or only for one Package
.
You can integrate SwiftLint as a Xcode Build Tool Plug-in if you're working with a project in Xcode.
Prefire
as a package dependency to your project without linking any of the products.Build Phases
inspector.
Open Run Build Tool Plug-ins
and select the +
button.
Select PrefirePlaybookPlugin
or PrefireTestsPlugin
from the list and add it to the project.You can integrate Prefire as a Swift Package Manager Plug-in if you're working with
a Swift Package with a Package.swift
manifest.
Package.swift
file.dependencies: [
.package(url: "https://github.com/BarredEwe/Prefire", from: "1.0.0")
]
plugins
parameter..target(
plugins: [
// For Playbook (Demo) view
.plugin(name: "PrefirePlaybookPlugin", package: "Prefire")
// For Snapshot Tests
.plugin(name: "PrefireTestsPlugin", package: "Prefire")
]
),
For generating tests and playbook, just mark your preview using protocol - PrefireProvider
:
struct Text_Previews: PreviewProvider, PrefireProvider {
static var previews: some View { ... }
}
For using Playbook just use PlaybookView
isComponent: true
isComponent: false
import Prefire
struct ContentView: View {
var body: some View {
PlaybookView(isComponent: true, previewModels: PreviewModels.models)
}
}
Just run generated tests 🚀
For detailed instruction you can see swift-snapshot-testing
New commands for previews:
Function for connecting preview together in one Flow:
.previewUserStory(.auth)
static var previews: some View {
PrefireView()
.previewUserStory(.auth)
}
static var previews: some View {
AuthView()
.previewUserStory(.auth)
}
For example Authorization flow: LoginView
, OTPView
and PincodeView
If a preview contains more than one View
, you can mark State
for these views.
.previewState(.loading)
static var previews: some View {
TestView("Default")
TestView("Loading")
.previewState(.loading)
}
You can additionaly configure Prefire. Just add .prefire.yml
file to root folder. Example:
test_configuration:
- target: PrefireExample
- test_file_path: PrefireExampleTests/PreviewTests.generated.swift
- simulator_device: "iPhone15,2"
- required_os: 16
target
- Your project Target for Snapshot tests. Default: FirstTargettest_file_path
- Filepath to generated file. Default: DeriveDatasimulator_device
- Device for Snapshot testing. Default: iPhone 14 Prorequired_os
- iOS version for Snapshot testing. Default: iOS 16#IF DEBUG
for yours SwiftUI Previews. Xcode automatically removed Preview code, when you build release version.link |
Stars: 23 |
Last commit: 3 hours ago |
Full Changelog: https://github.com/BarredEwe/Prefire/compare/1.0.0...1.0.1
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics