【发布时间】:2017-04-22 21:16:20
【问题描述】:
我真的很想通过使用firebase-server 的本地安装来编写一些集成测试,这将模拟实时数据库服务器。
我有 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相关问题:github.com/urish/firebase-server/issues/85
标签: ios swift firebase firebase-realtime-database