diff --git a/Binaries/PrefireBinary.artifactbundle/prefire-5.3.0-macos/bin/prefire b/Binaries/PrefireBinary.artifactbundle/prefire-5.3.0-macos/bin/prefire index e5efdf0..5ff7fa3 100755 Binary files a/Binaries/PrefireBinary.artifactbundle/prefire-5.3.0-macos/bin/prefire and b/Binaries/PrefireBinary.artifactbundle/prefire-5.3.0-macos/bin/prefire differ diff --git a/Configuration.md b/Configuration.md index ec982b5..87ba1c6 100644 --- a/Configuration.md +++ b/Configuration.md @@ -39,20 +39,21 @@ playbook_configuration: ### 🧾 Configuration Keys -| Key | Description | -| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | -| `target` | Target name used for snapshot generation. Default: *FirstTarget* | -| `test_target_path` | Path to unit test directory. Snapshots will be written to its `__Snapshots__` folder. Default: target name folder | -| `test_file_path` | Output file path for generated tests. Default: DerivedData or resolved via plugin | -| `template_file_path` | Custom template path relative to target. Optional. Defaults:‣ *PreviewTests.stencil* for test plugin‣ *PreviewModels.stencil* for playbook plugin| -| `simulator_device` | Device identifier used to run tests (e.g. `iPhone15,2`). Optional | -| `required_os` | Minimal iOS version required for preview rendering. Optional | -| `snapshot_devices` | List of logical snapshot "targets" (used as trait collections). Each will snapshot separately. Optional | -| `preview_default_enabled` | Should all detected previews be included by default? Set `false` if you want to require `.prefireEnabled()` manually. Default: `true` | -| `use_grouped_snapshots` | Generate a single test file with all previews (`true`) or separate test files per source file (`false`). When `false`, use `{PREVIEW_FILE_NAME}` placeholder in `test_file_path`. Default: `true` | -| `sources` | List of Swift files or folders to scan for previews. Defaults to inferred from the target | -| `imports` | Extra imports added to the generated test or playbook file | -| `testable_imports` | Extra `@testable` imports added to allow test visibility | +| Key | Description | +| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `target` | Target name used for snapshot generation. Default: _FirstTarget_ | +| `test_target_path` | Path to unit test directory. Snapshots will be written to its `__Snapshots__` folder. Default: target name folder | +| `test_file_path` | Output file path for generated tests. Default: DerivedData or resolved via plugin | +| `template_file_path` | Custom template path relative to target. Optional. Defaults:‣ _PreviewTests.stencil_ for test plugin‣ _PreviewModels.stencil_ for playbook plugin | +| `simulator_device` | Device identifier used to run tests (e.g. `iPhone15,2`). Optional | +| `required_os` | Minimal iOS version required for preview rendering. Optional | +| `snapshot_devices` | List of logical snapshot "targets" (used as trait collections). Each will snapshot separately. Optional | +| `preview_default_enabled` | Should all detected previews be included by default? Set `false` if you want to require `.prefireEnabled()` manually. Default: `true` | +| `use_grouped_snapshots` | Generate a single test file with all previews (`true`) or separate test files per source file (`false`). When `false`, use `{PREVIEW_FILE_NAME}` placeholder in `test_file_path`. Default: `true` | +| `sources` | List of Swift files or folders to scan for previews. Defaults to inferred from the target | +| `imports` | Extra imports added to the generated test or playbook file | +| `testable_imports` | Extra `@testable` imports added to allow test visibility | +| `draw_hierarchy_in_key_window_default_enabled` | Specifies whether to use the simulator's key window to snapshot the UI, rendering `UIAppearance` and `UIVisualEffect`. This option requires a host application for testing and does not work with framework test targets. Optional. If omitted, uses swift-snapshot-testing's default value. | --- diff --git a/PrefireExecutable/Sources/PrefireCore/Templates/PreviewTestsTemplate.swift b/PrefireExecutable/Sources/PrefireCore/Templates/PreviewTestsTemplate.swift index bca632f..3530dee 100644 --- a/PrefireExecutable/Sources/PrefireCore/Templates/PreviewTestsTemplate.swift +++ b/PrefireExecutable/Sources/PrefireCore/Templates/PreviewTestsTemplate.swift @@ -130,6 +130,9 @@ import SnapshotTesting as: .wait( for: preferences.delay, on: .image( + {% if argument.drawHierarchyInKeyWindowDefaultEnabled %} + drawHierarchyInKeyWindow: {{ argument.drawHierarchyInKeyWindowDefaultEnabled }}, + {% endif %} precision: preferences.precision, perceptualPrecision: preferences.perceptualPrecision, layout: prefireSnapshot.isScreen ? .device(config: prefireSnapshot.device.imageConfig) : .sizeThatFits, diff --git a/PrefireExecutable/Sources/prefire/Commands/Tests/GenerateTestsCommand.swift b/PrefireExecutable/Sources/prefire/Commands/Tests/GenerateTestsCommand.swift index 8a9f5ba..da02a89 100644 --- a/PrefireExecutable/Sources/prefire/Commands/Tests/GenerateTestsCommand.swift +++ b/PrefireExecutable/Sources/prefire/Commands/Tests/GenerateTestsCommand.swift @@ -22,6 +22,7 @@ struct GeneratedTestsOptions { var imports: [String]? var testableImports: [String]? var useGroupedSnapshots: Bool + var drawHierarchyInKeyWindowDefaultEnabled: Bool? init( target: String?, @@ -57,6 +58,7 @@ struct GeneratedTestsOptions { snapshotDevices = config?.tests.snapshotDevices imports = config?.tests.imports testableImports = config?.tests.testableImports + drawHierarchyInKeyWindowDefaultEnabled = config?.tests.drawHierarchyInKeyWindowDefaultEnabled } } @@ -77,6 +79,7 @@ enum GenerateTestsCommand { static let testableImports = "testableImports" static let previewsMacros = "previewsMacros" static let previewsMacrosDict = "previewsMacrosDict" + static let drawHierarchyInKeyWindowDefaultEnabled = "drawHierarchyInKeyWindowDefaultEnabled" } static func run(_ options: GeneratedTestsOptions) async throws { @@ -104,6 +107,7 @@ enum GenerateTestsCommand { ➜ Generated test path: \(options.output) ➜ Snapshot resources path: \(snapshotOutput ?? "nil") ➜ Preview default enabled: \(options.prefireEnabledMarker) + ➜ drawHierarchyInKeyWindow default enabled: \(String(describing: options.drawHierarchyInKeyWindowDefaultEnabled)) """ ) @@ -115,6 +119,7 @@ enum GenerateTestsCommand { Keys.testableImports: options.testableImports as? NSArray, Keys.mainTarget: options.target as? NSString, Keys.file: snapshotOutput?.string as? NSString, + Keys.drawHierarchyInKeyWindowDefaultEnabled: options.drawHierarchyInKeyWindowDefaultEnabled?.description as? NSString, ].filter({ $0.value != nil }) as? [String: NSObject] ?? [:] } } diff --git a/PrefireExecutable/Sources/prefire/Config/Config.swift b/PrefireExecutable/Sources/prefire/Config/Config.swift index a5a7744..3dd2048 100644 --- a/PrefireExecutable/Sources/prefire/Config/Config.swift +++ b/PrefireExecutable/Sources/prefire/Config/Config.swift @@ -24,6 +24,7 @@ struct TestsConfig { var imports: [String]? var testableImports: [String]? var useGroupedSnapshots: Bool? + var drawHierarchyInKeyWindowDefaultEnabled: Bool? enum CodingKeys: String, CodingKey { case target = "target" @@ -38,6 +39,7 @@ struct TestsConfig { case imports = "imports" case testableImports = "testable_imports" case useGroupedSnapshots = "use_grouped_snapshots" + case drawHierarchyInKeyWindowDefaultEnabled = "draw_hierarchy_in_key_window_default_enabled" } } diff --git a/PrefireExecutable/Sources/prefire/Config/ConfigDecoder.swift b/PrefireExecutable/Sources/prefire/Config/ConfigDecoder.swift index bb9bafe..bd8ac31 100644 --- a/PrefireExecutable/Sources/prefire/Config/ConfigDecoder.swift +++ b/PrefireExecutable/Sources/prefire/Config/ConfigDecoder.swift @@ -72,6 +72,8 @@ final class ConfigDecoder { config.tests.testTargetPath = getValue(from: components.last, env: env) case .useGroupedSnapshots: config.tests.useGroupedSnapshots = getValue(from: components.last, env: env) == "true" + case .drawHierarchyInKeyWindowDefaultEnabled: + config.tests.drawHierarchyInKeyWindowDefaultEnabled = getValue(from: components.last, env: env) == "true" } } diff --git a/PrefireExecutable/Tests/PrefireTests/ConfigDecoderTests.swift b/PrefireExecutable/Tests/PrefireTests/ConfigDecoderTests.swift index 2882a38..6bee702 100644 --- a/PrefireExecutable/Tests/PrefireTests/ConfigDecoderTests.swift +++ b/PrefireExecutable/Tests/PrefireTests/ConfigDecoderTests.swift @@ -20,6 +20,7 @@ class ConfigDecoderTests: XCTestCase { - SwiftUI - testable_imports: - Prefire + - draw_hierarchy_in_key_window_default_enabled: true playbook_configuration: - template_file_path: CustomModels.stencil - imports: @@ -45,6 +46,7 @@ class ConfigDecoderTests: XCTestCase { XCTAssertEqual(config.tests.previewDefaultEnabled, true) XCTAssertEqual(config.tests.imports, ["UIKit", "SwiftUI"]) XCTAssertEqual(config.tests.testableImports, ["Prefire"]) + XCTAssertEqual(config.tests.drawHierarchyInKeyWindowDefaultEnabled, true) XCTAssertEqual(config.playbook.imports, ["UIKit", "Foundation"]) XCTAssertEqual(config.playbook.testableImports, ["SwiftUI"]) XCTAssertEqual(config.playbook.template, "CustomModels.stencil") diff --git a/PrefireExecutable/Tests/PrefireTests/GenerateTestsCommandTest.swift b/PrefireExecutable/Tests/PrefireTests/GenerateTestsCommandTest.swift index 1290962..aaafe8a 100644 --- a/PrefireExecutable/Tests/PrefireTests/GenerateTestsCommandTest.swift +++ b/PrefireExecutable/Tests/PrefireTests/GenerateTestsCommandTest.swift @@ -48,4 +48,18 @@ class GenerateTestsCommandTests: XCTestCase { XCTAssertEqual(YAMLParser().string(from: arguments), YAMLParser().string(from: expectedArguments)) } + + func test_makeArguments_drawHierarchyInKeyWindowDefaultEnabled() async { + options.drawHierarchyInKeyWindowDefaultEnabled = true + + let expectedArguments = [ + "mainTarget": "\(options.target ?? "")" as NSString, + "file": options.testTargetPath.flatMap({ $0 + "PreviewTests.generated.swift"})!.string as NSString, + "drawHierarchyInKeyWindowDefaultEnabled": "true" as NSString, + ] as [String: NSObject] + + let arguments = await GenerateTestsCommand.makeArguments(for: options) + + XCTAssertEqual(YAMLParser().string(from: arguments), YAMLParser().string(from: expectedArguments)) + } }