### Non-Optimal Configuration with `configurations` for Int Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md This example demonstrates the less optimal way of defining configurations for integers by explicitly setting both name and value, leading to unnecessary ceremony. ```swift // ⚠️ This works but isn't optimal @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(configurations: [ SnapshotConfiguration(name: "1", value: 1), SnapshotConfiguration(name: "2", value: 2) ]) func myView(int: Int) -> some View { Text("value: \(int)") } } ``` -------------------------------- ### Pass Configurations Function to SnapshotTest Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md Pass a function that returns configurations to the `configurations` parameter for cleaner call sites and more complex setups. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(configurations: configurations) // ⬅️ Pass in the configurations() function to make our configurations func myView(int: Int, string: String) -> some View { Text("value: \(int) is typed as: \(string)") } } private func configurations() -> [SnapshotConfiguration<(Int, String)>] { [ SnapshotConfiguration(name: "Name 1", value: (1, "one")), SnapshotConfiguration(name: "Name 2", value: (2, "two")), ] } ``` -------------------------------- ### Non-Optimal Configuration with `configurations` for Enum Cases Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md This example shows the less preferred method of manually mapping enum cases to `SnapshotConfiguration` objects, which requires explicit name and value definitions. ```swift // ⚠️ This works but isn't optimal enum Compass: CaseIterable { case north, east, south, west } @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest( configurations: Compass.allCases.map { SnapshotConfiguration(name: "\($0)", value: $0) // ⬅️ This might be tempting } ) func myView(compass: Compass) -> some View { Text("Pointing \(compass)") } } ``` -------------------------------- ### Optimal Configuration with `configurationValues` for Enum Cases Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md Leverage `configurationValues` with enum cases to automatically infer configuration names from the enum's values, simplifying the setup. ```swift // ✅ This is preferred enum Compass: CaseIterable { case north, east, south, west } @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(configurationValues: Compass.allCases) // ⬅️ Use configurationValues when the name can be computed func myView(compass: Compass) -> some View { Text("Pointing \(compass)") } } ``` -------------------------------- ### Run Unit Tests Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/CONTRIBUTING.md Execute the project's unit tests using either `mise` or the standard `swift test` command. ```bash mise run test ``` ```bash swift test ``` -------------------------------- ### Create Basic Snapshot Test Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Usage.md Use `@SnapshotSuite` and `@SnapshotTest` to mark functions returning views for snapshot testing. `@Suite` is recommended for Xcode visibility. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest func myView() -> some View { Text("Some text") } } ``` -------------------------------- ### Apply Code Formatting Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/CONTRIBUTING.md Automatically format the code to meet project standards using `mise` or a direct script execution. ```bash mise run format ``` ```bash ./Tools/format ``` -------------------------------- ### Run Integration Tests Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/CONTRIBUTING.md Execute integration tests, which require a specific simulator configuration. Use `mise` for convenience or `xcodebuild` for direct control. ```bash mise run test-integration ``` ```bash xcodebuild \ -scheme SnapshotsIntegrationTests \ -destination "platform=iOS Simulator,name=iPhone 17,OS=26.2,arch=arm64" ``` -------------------------------- ### Define Parameterised Snapshots with Basic Values Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md Use `SnapshotConfiguration` to define multiple test cases for a single snapshot function. Each configuration runs the function once with its specified value, creating prefixed snapshot files. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest( configurations: [ SnapshotConfiguration(name: "Name 1", value: 1), SnapshotConfiguration(name: "Name 2", value: 2), ] ) func myView(value: Int) -> some View { Text("value: \(value)") } } ``` -------------------------------- ### Create Simple SwiftUI Snapshot Test Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/README.md Use `@SnapshotSuite` and `@SnapshotTest` to mark up functions returning SwiftUI Views for snapshot testing. Xcode requires `@Suite` to detect generated Suites within macro expansions. ```swift // ✅ Create a simple snapshot test for some SwiftUI text. @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest func myView() -> some View { Text("Some text") } } ``` -------------------------------- ### Use Static Function for Configurations Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md Utilize a static function within a struct to generate configurations, suitable for more complex generation logic. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(configurations: MyConfigurationGenerator.generateConfigurations) func myView(int: Int) -> some View { Text("value: \(int)") } } private struct MyConfigurationGenerator { static func generateConfigurations() -> [SnapshotConfiguration] { // Some really complex logic ... return [] } } ``` -------------------------------- ### Check Code Format Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/CONTRIBUTING.md Verify that the code adheres to the project's formatting standards using `mise` or a direct script execution. ```bash mise run lint ``` ```bash ./Tools/format-check ``` -------------------------------- ### Optimal Configuration with `configurationValues` for Int Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md Use `configurationValues` to automatically infer configuration names from integer values, avoiding manual duplication of names and values. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(configurationValues: [1, 2]) func myView(int: Int) -> some View { Text("value: \(int)") } } ``` -------------------------------- ### Set Fitting Size for Device Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Configure the `.sizes` trait with the `fitting` parameter to control how the view's dimensions interact with the device size. Options include `widthAndHeight`, `widthButMinimumHeight`, and `heightButMinimumWidth`. ```swift @Suite @MainActor @SnapshotSuite( .sizes(devices: .iPhoneX, fitting: .widthButMinimumHeight) // ⬅️ Use device width with minimum height ) struct MySnapshots { @SnapshotTest func myListRow() -> some View { HStack { Image(systemName: "person.fill") Text("My account") Spacer() } .padding() } } ``` -------------------------------- ### Set Custom Width and Height for Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the .sizes trait to specify explicit width and height values in points, or use .minimum for the smallest possible size. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(.sizes(width: 320, height: 480)) func size320x480() -> some View { Text("320x480 size") } @SnapshotTest(.sizes(width: 320)) func width320() -> some View { Text("320 width") } @SnapshotTest(.sizes(.minimum)) func minimumSize() -> some View { Text("Minimum size") } } ``` -------------------------------- ### Specify Theme for Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the `.theme` trait to explicitly set the snapshot to light mode, dark mode, or both. This is useful for testing how views adapt to different visual themes. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(.theme(.light)) func light() -> some View { Text("Light theme") } @SnapshotTest(.theme(.dark)) func dark() -> some View { Text("Dark theme") } @SnapshotTest(.theme(.all)) func all() -> some View { Text("Both light and dark") } } ``` -------------------------------- ### Apply Device Sizes to All Tests in a Suite Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the `.sizes` trait with specific device presets to set the snapshot dimensions for all tests within a suite. Individual tests can override this setting. ```swift @Suite @SnapshotSuite( .sizes(devices: .iPhoneX, .iPadPro11) // ⬅️ Set the devices for all the tests in this suite ) struct MySnapshots { @SnapshotTest func myView() -> some View { Text("Some text") } @SnapshotTest func anotherView() -> some View { Text("Some other text") } @SnapshotTest( .sizes(devices: .iPhoneX) // ⬅️ Set this test to be iPhone sized ) func myPhoneView() -> some View { Text("I'm the size of a phone") } } ``` -------------------------------- ### Apply Default Padding to Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the .padding trait without arguments to apply the system's default padding around the view. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(.padding) func paddingDefault() -> some View { Text("Add system default padding to all sides") } } ``` -------------------------------- ### Unpack Tuple Values in Parameterised Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Parameterised.md When using tuples as values for configurations, the macro library unpacks them and passes them to the function's parameters. This allows for more complex data structures to be used in parameterised tests. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest( configurations: [ SnapshotConfiguration(name: "Name 1", value: (1, "one")), SnapshotConfiguration(name: "Name 2", value: (2, "two")), ] ) func myView(int: Int, string: String) -> some View { // ⬅️ Note how the tuple values from 'value:' are unpacked in this function's parameters Text("value: \(int) is typed as: \(string)") } } ``` -------------------------------- ### Specify Multiple Sizes for Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md The .sizes trait can accept multiple Size objects to render the view in various dimensions. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest( .sizes( SizesSnapshotTrait.Size(width: 320, height: 480), SizesSnapshotTrait.Size(width: 600, height: 200) ) ) func testMultipleSizes() -> some View { Text("Will render in different sizes") } } ``` -------------------------------- ### Apply Fixed Padding to Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the .padding(value) trait to add a specific amount of padding to all sides of the view. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(.padding(20)) func padding20() -> some View { Text("Add 20 padding to all sides") } } ``` -------------------------------- ### Apply Horizontal Padding to Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use .padding(.horizontal, value) to apply a specific amount of padding to the leading and trailing edges of the view. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(.padding(.horizontal, 15)) func paddingSpecificSides() -> some View { Text("Add 15 padding to horizontal sides") } } ``` -------------------------------- ### Set Background Color for Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the `.backgroundColor` trait to specify a background color for snapshot tests. This can be applied to individual tests or an entire suite. Defaults to `UIColor.systemBackground`. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest( .backgroundColor(.red) ) func red() -> some View { Text("Red") } @SnapshotTest( .backgroundColor(.blue) ) func blue() -> some View { Text("Blue") } @SnapshotTest( .backgroundColor(.green) ) func green() -> some View { Text("Green") } } ``` -------------------------------- ### Change Snapshot Comparison Strategy Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the `.strategy` trait to alter how snapshots are compared. Supported strategies include `.image` for pixel equality (default) and `.recursiveDescription` for comparing view hierarchies. ```swift @Suite @SnapshotSuite struct StrategySnapshots { @SnapshotTest( .strategy(.image) ) func image() -> some View { Text("generates an image file") } @SnapshotTest( .strategy(.recursiveDescription) ) func recursiveDescription() -> some View { Text("generates a recursive description text file") } } ``` -------------------------------- ### Apply EdgeInsets Padding to Snapshots Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Use the .padding(EdgeInsets) trait to apply custom padding values to each specific edge (top, leading, bottom, trailing) of the view. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest( .padding( EdgeInsets( top: 20, leading: 30, bottom: 10, trailing: 40 ) ) ) func paddingEdgeInsets() -> some View { Text("Add specific edge inset padding") } } ``` -------------------------------- ### Use Test Scoping Trait with @SnapshotTest Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md Demonstrates how to apply an existing Swift Testing trait like `.testScopingTrait` to a specific test case within a `@SnapshotSuite`. Ensure you are using version 1.1.0 or later. ```swift @Suite @SnapshotSuite struct Example { @SnapshotTest( /// Use an existing `TestScoping` trait with `@SnapshotTest` .testScopingTrait(value: "TestScoping") ) func testScoping() -> some View { Text(MyExampleTrait.current) } } ``` -------------------------------- ### Async and Throws Snapshot Test Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Usage.md Snapshot tests can be marked as `async` and `throws` to handle asynchronous operations or errors during view generation. ```swift @Suite @SnapshotSuite struct AsyncSnapshots { @SnapshotTest func asyncView() async throws -> some View { let data = try await fetchData() return MyView(data: data) } } ``` -------------------------------- ### Snapshot Test with Explicit Name Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Usage.md Provide an explicit display name as the first argument to `@SnapshotTest` to customize the test name and generated snapshot filenames. ```swift // ✅ Use explicit names for test @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest("Sample text") // ⬅️ Added display name func myView() -> some View { Text("Some text") } } ``` -------------------------------- ### Force Snapshot Re-rendering Source: https://github.com/adammcarter/swift-snapshot-testing-macros/blob/main/Documentation/Traits.md The `.record` trait forces snapshots to re-render their images. Use `.record(true)` for explicit control or `.record` as a shorthand. `.record(false)` is the default behavior and does not re-render. ```swift @Suite @SnapshotSuite struct MySnapshots { @SnapshotTest(.record(true)) // ← Force snapshots in to record mode func recordTrue() -> some View { Text("Force record (explicit)") } @SnapshotTest(.record) // ← Shorthand version of '.record(true)' func record() -> some View { Text("Force record") } @SnapshotTest(.record(false)) // ← Default value so not needed func recordFalse() -> some View { Text("Doesn't re-record") } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.