BarredEwe / Prefire

🔥 A library based on SwiftUI Preview, for easy generation: Playbook view, Snapshot and Accessibility tests
Apache License 2.0
296 stars 19 forks source link

No such module Prefire #44

Closed thannn closed 6 months ago

thannn commented 8 months ago

Context 🕵️‍♀️

Attempting to generate snapshot tests.

  1. Installed Prefire according to the readme:
  1. Using #Preview for SwiftUI previews.

  2. .prefire.yml:

    test_configuration:
    - target: RedactedTests
    - simulator_device: "iPhone15,4"
    - required_os: 16
    - preview_default_enabled: true
    - imports:
    - Foundation
    - UIKit
    - testable_imports:
    - Prefire

What 🌱

The generated code (PreviewTests.generated.swift) throws error No such module Prefire upon line import Prefire.

BarredEwe commented 8 months ago

Could you share the Package.swift file?

In theory, .testTarget should be something like this:

.testTarget(
            name: "PrefireExampleTests",
            dependencies: [
                "PrefireExample",
                .product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
            ],
            plugins: [
                .plugin(name: "PrefireTestsPlugin", package: "Prefire")
            ]
        )
thannn commented 8 months ago

Sure, here's the Package.swift:

let package = Package(
    name: "Redacted",
    platforms: [
        .iOS(.v15)
    ],
    products: [
        .library(name: "Redacted", targets: ["RedactedUI", "RedactedUIKit", "RedactedSwiftUI"]),
        .library(name: "RedactedUI", targets: ["RedactedUI"]),
        .library(name: "RedactedUIKit", targets: ["RedactedUIKit"]),
        .library(name: "RedactedSwiftUI", targets: ["RedactedSwiftUI"])
    ],
    dependencies: [
        .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.12.0"),
        .package(url: "https://github.com/BarredEwe/Prefire", from: "1.0.0")
    ],
    targets: [
        .target(name: "RedactedUI", ...),
        .target(name: "RedactedUIKit", ...),
        .target(name: "RedactedSwiftUI", ...),
        .testTarget(
            name: "RedactedTests",
            dependencies: [
                .target(name: "RedactedUI"),
                .target(name: "RedactedUIKit"),
                .target(name: "RedactedSwiftUI"),
                .product(name: "SnapshotTesting", package: "swift-snapshot-testing")
            ],
            plugins: [
                .plugin(name: "PrefireTestsPlugin", package: "Prefire")
            ]
        )
    ],
    swiftLanguageVersions: [.v5]
)
BarredEwe commented 8 months ago

You need to add Prefire dependency for the testTarget:

.testTarget(
            name: "RedactedTests",
            dependencies: [
                .target(name: "RedactedUI"),
                .target(name: "RedactedUIKit"),
                .target(name: "RedactedSwiftUI"),
                "Prefire",
                .product(name: "SnapshotTesting", package: "swift-snapshot-testing")
            ],
            plugins: [
                .plugin(name: "PrefireTestsPlugin", package: "Prefire")
            ]
        )
thannn commented 8 months ago

🤦 I'll have to up my SPM knowledge. That'll do, I can move along. Thank you!