-1

I have a firebase app that uses multiple modules so tests can run without needing to launch a simulator instance.

I've broken out my project into multiple spm targets, so my folder structure resembles the following:

MyApp
--- App
------ iOS
--------- ContentView.swift
--------- GoogleService-Info.plist
--- Sources
------ FirebaseClient
--------- FirebaseClient.swift
--- Tests
----- FirebaseClientTests
--------- FirebaseClientTests.swift
--- Package.swift

Calling FirebaseApp.configure() from FirebaseClient.swift works, but only so long as the main app is being run. If I try calling the setup function in FirebaseClient.swift from FirebaseClientTests.swift, I get the plist not found error. However, if I create a resources folder inside FirebaseClient, it can't find the plist in either executable. How can I set up the project so both the target and the test can find GoogleService-Info.plist?

TheLivingForce
  • 532
  • 9
  • 21

1 Answers1

0

Each test runs with a separate bundle identifier, so it's impossible to share the GoogleService-Info.plists. You'll need to create a new GoogleService-Info.plist from firebase for your test (the bundle ID for the test will just be FirebaseClientTests). Take the test bundle ID and put it into the resources folder for FirestoreClient. If you don't have a resources folder, modify the folder structure of FirestoreClient to resemble the following:

--- Sources
------ FirebaseClient
--------- Resources
------------ GoogleService-Info.plist
--------- FirebaseClient.swift

and change the target definition in Package.swift to the following:

.target(
   name: "FirestoreClient",
   //    ...
   resources: [
      .process("Resources"),
   ]
),

Finally, you have to tell Firebase not to look in the main bundle for the plist when calling FirebaseApp.configure. Use the solution in this answer - just replace Bundle.main with Bundle.module.

TheLivingForce
  • 532
  • 9
  • 21