BarredEwe / Prefire

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

Circular dependency between modules 'ModuleTypes' and 'SnapshotTests' #9

Closed markst closed 1 year ago

markst commented 1 year ago

Swift package:

let package = Package(
    name: "ModuleTypes",
    platforms: [.iOS(.v15)],
    products: [
        .library(
            name: "ModuleTypes",
            targets: ["ModuleTypes"]
        )
    ],
    dependencies: [
        .package(path: "../Asset"),
        .package(path: "../Common"),
        .package(path: "../Components"),
        .package(url: "https://github.com/BarredEwe/Prefire.git", branch: "main"),
        .package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.11.0")
    ],
    targets: [
        .target(
            name: "ModuleTypes",
            dependencies: [
                "Prefire",
                .product(name: "Assets", package: "Asset"),
                .product(name: "Common", package: "Common"),
                .product(name: "Components", package: "Components")
            ],
            path: "./",
            exclude: ["Tests"],
            plugins: [
                // For Snapshot Tests
                .plugin(name: "PrefireTestsPlugin", package: "Prefire")
            ]
        ),
        .testTarget(
            name: "SnapshotTests",
            dependencies: [
                "ModuleTypes",
                .product(name: "TestAssets", package: "Asset"),
                .product(name: "SnapshotTesting", package: "swift-snapshot-testing")
            ]
        )
    ]
)
markst commented 1 year ago

Appears that mainTarget is incorrectly resolving to my test target. Strange when it seems to be: context.package.targets.first

BarredEwe commented 1 year ago

Hello! Yes, you are right. I can use your fix and make a pull request, or you can create pull request it yourself (since you already fixed the problem). 😊

BarredEwe commented 1 year ago

I think the problem is adding the plugin for tests not in the test target.

         .testTarget(
             name: "SnapshotTests",
             dependencies: [
                 "ModuleTypes",
                 .product(name: "TestAssets", package: "Asset"),
                 .product(name: "SnapshotTesting", package: "swift-snapshot-testing")
             ],
             plugins: [
                 // For Snapshot Tests
                 .plugin(name: "PrefireTestsPlugin", package: "Prefire")
             ]
         )

But still, I added some checks to get the mainTarget https://github.com/BarredEwe/Prefire/pull/14

markst commented 1 year ago

Think you may be right @BarredEwe - I'll have another go. Still right to not assume targets.first is main target.

BarredEwe commented 1 year ago

I think, filtering your own target name (this fix was added in the latest release) and connecting the plugin to testTarget can fix this problem. @markst Could you try the latest release?