我真的想通过利用
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?我不清楚选项中的哪些变量是强制性的,需要提供.
最佳答案 您可以使用FIROptions init!(googleAppID:String!,bundleID:String!,gcmSenderID GCMSenderID:String!,apiKey APIKey:String!,clientID:String !, trackingID:String!,androidClientID:String!,databaseURL:String!, storageBucket:String!,deepLinkURLScheme:String!)方法并从真实应用程序传入AppId,bundleId,SenderID,然后传入databaseURL,它可以是本地URL.你应该能够将nil传递给其他人并且没问题(尽管你可能需要对编译器警告进行静音,因为它们似乎在Swift中被标记为不可为空).
或者,您可以更改GoogleService-Info-tests.plist中的一个字段以指向新数据库.