Versions
Xcode: 12.2/12.3
iOS: 13+
Problem
I'm using local Swift packages to organise code within my workspace. This has been working fine until I tried adding snapshot tests to my feature packages, which depend on another package containing resources.
My workspace is currently structured like this (where -> means depends on):
MyApp (Xcode Project) -> Login (Package) -> UILibrary (Package)
When adding snapshot tests to my UILibrary, those snapshot tests work fine, and everything loads correctly. However, when I add snapshot tests to my Login package (which depends on UILibrary) the tests reach a fatal error when the UILibrary is trying to load the Color assets which uses the generated Bundle.module
extension generated by Xcode.
fatalError("unable to find bundle named UILibrary_UILibrary")
Does anyone have any ideas on how to fix/workaround this? I'm currently facing re-organising my code as Xcode frameworks instead of Swift packages, as I've not had this issue on previous projects.
It looks like a similar issue to this: SwiftUI Previewer crashes while in swift package that depends on another's packages Bundle.module reference
Further details
Things I have tried:
- Adding UILibrary as a dependency to my LoginTests – still can't load.
- Using something like
Bundle(for: ClassForBundle.self)
instead ofBundle.module
in UILibrary – still can't load.
My Login Package.swift file looks like this:
let package = Package(
name: "Login",
platforms: [.iOS(.v13)],
products: [
.library(name: "Login", type: .dynamic, targets: ["Login"])
],
dependencies: [
.package(path: "../Shared/UILibrary"),
.package(name: "SnapshotTesting", url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.8.1"),
],
targets: [
.target(name: "Login", dependencies: ["UILibrary"]),
.testTarget(name: "LoginTests", dependencies: ["Login", "SnapshotTesting"])
]
)
My UILibrary Package.swift file looks like this:
let package = Package(
name: "UILibrary",
platforms: [.iOS(.v13)],
products: [
.library(name: "UILibrary", type: .dynamic, targets: ["UILibrary"])
],
dependencies: [
.package(name: "SnapshotTesting", url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.8.1"),
],
targets: [
.target(name: "UILibrary", dependencies: [], resources: [.process("Resources")]),
.testTarget(name: "UILibraryTests", dependencies: ["UILibrary", "SnapshotTesting"])
]
)
Note: Resources contains my colors & image asset catalogs so they are processed as part of the UILibrary target.