我真的想通過利用本地安裝firebase-server來編寫一些集成測試,它將模仿實時數據庫服務器。如何通過Swift連接到本地Firebase服務器?
我有installed並從CLI開始吧: node_modules/.bin/firebase-server -p 5000
但我通過SWIFT連接到它的麻煩。 按照Firebase文檔,需要下載項目中的利用GoogleService-Info.plist
。這顯然必須改變,因爲我想連接到本地服務器。
這就是我現在所擁有的在AppDelegate.swift
:
var firebaseConfig: String!
if isRunningTests() {
// unit test server (idealy local)
firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info-tests", ofType: "plist")
} else {
#if DEBUG
// staging server
firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist")
#else
// production server
firebaseConfig = Bundle.main.path(forResource: "GoogleService-Info-prod", ofType: "plist")
#endif
}
guard let options = FIROptions(contentsOfFile: firebaseConfig) else {
fatalError("Invalid Firebase configuration file.")
}
FIRApp.configure(with: options)
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
FIRDatabase.database().persistenceEnabled = true
這意味着單元測試我加載GoogleService-Info-tests
plist,以連接到遠程測試數據庫。我怎麼能連接到ws://test.firebase.localhost:5000
?我不清楚options
中的哪些變量是強制性的,需要提供。
github上的相關問題:https://github.com/urish/firebase-server/issues/85 – urish