Swiftpack.co - aegzorz/stilleben as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by aegzorz.
aegzorz/stilleben v0.4.0
Modern snapshotting
⭐️ 0
🕓 2 weeks ago
iOS
.package(url: "https://github.com/aegzorz/stilleben.git", from: "v0.4.0")

Build License Version

Stilleben

Modern snapshot testing written in Swift.

Used to for testing snapshots of mostly UI components but also models and other types.

It comes with a few predefined matchers:

  • UIMatcher for SwiftUI and UIKit snapshots.
  • EncodableMatcher for snapshots of models encoded to JSON.
  • ReflectionMatcher for snapshots of any type in the form of a reflection description.

Snapshots can be configured to use the following:

  • RecordingStrategy determines how snapshots are saved and read.
  • DiffingStrategy how to diff the recorded snapshot against the one generated by the test.
  • RenderingStrategy strategy used for rendering UI snapshots.
  • SizingStrategy strategy used for sizing views before snapshotting.

Examples

Example of snapshot testing a SwiftUI view:

import XCTest
import Stilleben

final class SomeViewTests: XCTestCase {
    private let matcher = UIMatcher()
        .assertSimulator(modelIdentifier: "iPhone14,7")
        .sizing(.dynamicHeight)
        .dynamicTypeSizes(.large)

    func testSomeView() async throws {
        await matcher
            .colorSchemes(.light)
            .match {
                NavigationView {
                    SomeView()
                }
            }
    }
}
Generated snapshot

It also supports snapshot testing UIKit view controllers or views:

import XCTest
import Stilleben

final class SomeViewControllerTests: XCTestCase {
    private let matcher = UIMatcher()
        .assertSimulator(modelIdentifier: "iPhone14,7")
        .sizing(.screen)
    
    func testSomeViewController() async throws {
        await matcher
            .match { @MainActor () -> UIViewController in
                SomeViewController()
            }
    }
    
    func testSomeView() async throws {
        await matcher
            .sizing(.intrinsic)
            .match { @MainActor () -> UIView in
                SomeView()
            }
    }
}

Support for snapshotting reflections of your models:

import XCTest
import Stilleben

final class ReflectionTests: XCTestCase {
    let matcher = ReflectionMatcher()

    func testSimpleModel() async {
        struct Model {
            let text = "Hello World!"
        }

        await matcher.match {
            Model()
        }
    }
}

Which yields a text file snapshot:

  ▿ StillebenTests.ReflectionTests.?.?.Model
    - text: "Hello World!"

GitHub

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

Release Notes

📦 Release 0.4.0
2 weeks ago

What's Changed

Full Changelog: https://github.com/aegzorz/stilleben/compare/v0.3.0...v0.4.0

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