How pointfreeco/swift-snapshot-testing works
Main Components
• SnapshotTesting Core Module: Represented by the “Sources/SnapshotTesting” directory. This module contains the heart of the snapshot testing functionality including strategies for image, text, data (e.g. JSON, plist) as well as diffing logic.
• InlineSnapshotTesting Module: Found under “Sources/InlineSnapshotTesting”. This module provides support for inline snapshots, which is an alternative assertion style.
• Documentation & Guides: Documentation is included as DocC files (see “Documentation.docc” in both modules) and related Articles. Although not part of runtime, they inform the design and usage.
• Test Suite: The “Tests” directory contains unit tests for both inline and standard snapshot testing functions, ensuring that each component behaves as expected.
• Build & CI Configuration: Files such as Package.swift, Makefile, and the GitHub workflows (in “.github/workflows”) indicate the project’s integration with CI/CD and its use as a Swift Package.
• Utility and Internal Helpers: Within “Sources/SnapshotTesting/Common” and “Sources/SnapshotTesting/Internal”, you find helper components—for diffing, encoding, and view handling. These support the core strategies and engine.
Relationships and Interactions
• The core SnapshotTesting module provides the main API (e.g. assertSnapshot, assertInlineSnapshot) that client test code calls.
• Diff logic sits as a helper component beneath the strategies, taking the recorded snapshot and comparing it to a new rendering.
• The InlineSnapshotTesting module works closely with the core testing API, adding specialized functionality to record inline assertions.
• The tests exercise all these components, ensuring that they function together. A separate “Tests” component should be drawn to illustrate testing flows.
• Build scripts and configuration files (e.g. Package.swift, Makefile) are external to the runtime modules but critical for building and continuous integration.
Architectural Patterns and Design Principles
• Modular Design: The separation into distinct modules (SnapshotTesting and InlineSnapshotTesting) demonstrates clear modularization.
• Extensibility: The library supports dozens of snapshot strategies and allows users to add their own. Represent this by noting “custom strategies” or “extensibility” points that feed into the core snapshot engine.
• Testability: With a dedicated test suite and minimal configuration required, the design is test-driven.
• Decoupling: Helper utilities (e.g., diffing, encoders) are placed in subdirectories to support the main functionalities, ensuring that each part is focused and easier to maintain.
Relevant Technologies, Frameworks, or Libraries
• Swift and Swift Package Manager: Since the project is managed via Package.swift and integrated with Xcode and SwiftPM.
• XCTest: As seen in the example usage and tests (found in the “Tests” directory).
• GitHub Actions: For continuous integration (the GitHub workflows illustrate build, format, and release workflows).
• Optional: Integration with custom plug-ins and external tools (e.g., diff viewers like Kaleidoscope).