Skip to content

Fix iOS tests, upgrade iOS Firebase SDK #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ jobs:
run: ./gradlew assemble
- name: Run JS Tests
run: ./gradlew cleanTest jsTest
- name: Upload test artifact
- name: Upload JS test artifact
uses: actions/upload-artifact@v2
if: failure()
with:
name: "JSTest Report HTML"
name: "JS Test Report HTML"
path: "firebase-firestore/build/reports/tests/jsTest/"
- name: Run iOS Tests
run: ./gradlew cleanTest iosX64Test
- name: Upload iOS test artifact
uses: actions/upload-artifact@v2
if: failure()
with:
name: "iOS Test Report HTML"
path: "firebase-firestore/build/reports/tests/iosTest/"
- name: Run Android Instrumented Tests
uses: reactivecircus/android-emulator-runner@v2
with:
Expand All @@ -44,3 +52,9 @@ jobs:
arch: x86_64
profile: Nexus 6
script: ./gradlew connectedAndroidTest
- name: Upload Android test artifact
uses: actions/upload-artifact@v2
if: failure()
with:
name: "Android Test Report HTML"
path: "firebase-firestore/build/reports/tests/androidTests/"
2 changes: 1 addition & 1 deletion firebase-app/src/nativeInterop/cinterop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 8.1.1
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 8.2.0
2 changes: 1 addition & 1 deletion firebase-app/src/nativeInterop/cinterop/FirebaseCore.def
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ language = Objective-C
package = cocoapods.FirebaseCore
modules = FirebaseCore
compilerOpts = -framework FirebaseCore
linkerOpts = -framework FirebaseCore -framework FirebaseCoreDiagnostics -framework FirebaseAnalytics -framework FIRAnalyticsConnector -framework GoogleAppMeasurement -framework FirebaseInstallations -framework GoogleDataTransport -framework GoogleUtilities -framework PromisesObjC -framework nanopb -framework StoreKit -lsqlite3
linkerOpts = -framework FirebaseCore -framework FirebaseCoreDiagnostics -framework FirebaseAnalytics -framework GoogleAppMeasurement -framework FirebaseInstallations -framework GoogleDataTransport -framework GoogleUtilities -framework PromisesObjC -framework nanopb -framework StoreKit -lsqlite3
16 changes: 16 additions & 0 deletions firebase-auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ kotlin {
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
val archVariant = if (konanTarget is KonanTarget.IOS_X64) "ios-arm64_i386_x86_64-simulator" else "ios-arm64_armv7"

rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/$archVariant")
}
).plus(
listOf(
"FirebaseAuth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
@file:JvmName("tests")
package dev.gitlive.firebase.auth

import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.runBlocking

actual val emulatorHost: String = "10.0.2.2"

actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext

actual fun runTest(test: suspend () -> Unit) = runBlocking { test() }
actual val currentPlatform: Platform = Platform.Android

actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
if (skip) {
Log.w("Test", "Skip the test.")
return@runBlocking
}

test()
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import kotlin.test.*

expect val emulatorHost: String
expect val context: Any
expect fun runTest(test: suspend () -> Unit)
expect fun runTest(skip: Boolean = false, test: suspend () -> Unit)
expect val currentPlatform: Platform

enum class Platform { Android, IOS, JS }

class FirebaseAuthTest {

// Skip the tests on iOS simulator due keychain exceptions
private val skip = currentPlatform == Platform.IOS

@BeforeTest
fun initializeFirebase() {
Firebase
Expand All @@ -35,14 +41,14 @@ class FirebaseAuthTest {
}

@Test
fun testSignInWithUsernameAndPassword() = runTest {
fun testSignInWithUsernameAndPassword() = runTest(skip) {
val uid = getTestUid("[email protected]", "test123")
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
assertEquals(uid, result.user!!.uid)
}

@Test
fun testCreateUserWithEmailAndPassword() = runTest {
fun testCreateUserWithEmailAndPassword() = runTest(skip) {
val email = "test+${Random.nextInt(100000)}@test.com"
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
assertNotEquals(null, createResult.user?.uid)
Expand All @@ -57,7 +63,7 @@ class FirebaseAuthTest {
}

@Test
fun testFetchSignInMethods() = runTest {
fun testFetchSignInMethods() = runTest(skip) {
val email = "test+${Random.nextInt(100000)}@test.com"
var signInMethodResult = Firebase.auth.fetchSignInMethodsForEmail(email)
assertEquals(emptyList(), signInMethodResult)
Expand All @@ -69,7 +75,7 @@ class FirebaseAuthTest {
}

@Test
fun testSendEmailVerification() = runTest {
fun testSendEmailVerification() = runTest(skip) {
val email = "test+${Random.nextInt(100000)}@test.com"
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
assertNotEquals(null, createResult.user?.uid)
Expand All @@ -79,7 +85,7 @@ class FirebaseAuthTest {
}

@Test
fun sendPasswordResetEmail() = runTest {
fun sendPasswordResetEmail() = runTest(skip) {
val email = "test+${Random.nextInt(100000)}@test.com"
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
assertNotEquals(null, createResult.user?.uid)
Expand All @@ -90,7 +96,7 @@ class FirebaseAuthTest {
}

@Test
fun testSignInWithCredential() = runTest {
fun testSignInWithCredential() = runTest(skip) {
val uid = getTestUid("[email protected]", "test123")
val credential = EmailAuthProvider.credential("[email protected]", "test123")
val result = Firebase.auth.signInWithCredential(credential)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ actual val emulatorHost: String = "localhost"

actual val context: Any = Unit

actual fun runTest(test: suspend () -> Unit) = runBlocking {
actual val currentPlatform: Platform = Platform.IOS

actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
if (skip) {
NSLog("Skip the test.")
return@runBlocking
}

val testRun = MainScope().async { test() }
while (testRun.isActive) {
NSRunLoop.mainRunLoop.runMode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ actual val emulatorHost: String = "localhost"

actual val context: Any = Unit

actual fun runTest(test: suspend () -> Unit) = GlobalScope
actual val currentPlatform: Platform = Platform.JS

actual fun runTest(skip: Boolean, test: suspend () -> Unit) = GlobalScope
.promise {
if (skip) {
console.log("Skip the test.")
return@promise
}

try {
test()
} catch (e: dynamic) {
Expand Down
2 changes: 1 addition & 1 deletion firebase-auth/src/nativeInterop/cinterop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 8.1.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 8.2.0
16 changes: 16 additions & 0 deletions firebase-database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ kotlin {
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
val archVariant = if (konanTarget is KonanTarget.IOS_X64) "ios-arm64_i386_x86_64-simulator" else "ios-arm64_armv7"

rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/$archVariant")
}
).plus(
listOf(
"FirebaseDatabase",
Expand Down
2 changes: 1 addition & 1 deletion firebase-database/src/nativeInterop/cinterop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseDatabaseBinary.json" == 8.1.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseDatabaseBinary.json" == 8.2.0
17 changes: 17 additions & 0 deletions firebase-firestore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,29 @@ kotlin {
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
val archVariant = if (konanTarget is KonanTarget.IOS_X64) "ios-arm64_i386_x86_64-simulator" else "ios-arm64_armv7"

rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/$archVariant")
}
).plus(
listOf(
"abseil",
"BoringSSL-GRPC",
"FirebaseFirestore",
"gRPC-Core",
"gRPC-C++",
"leveldb-library"
).map {
val archVariant = if (konanTarget is KonanTarget.IOS_X64) "ios-arm64_i386_x86_64-simulator" else "ios-arm64_armv7"
Expand Down
2 changes: 1 addition & 1 deletion firebase-firestore/src/nativeInterop/cinterop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFirestoreBinary.json" == 8.1.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFirestoreBinary.json" == 8.2.0
16 changes: 16 additions & 0 deletions firebase-functions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ kotlin {
fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
val nativeFrameworkPaths = listOf(
rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/iOS")
).plus(
listOf(
"FirebaseAnalytics",
"FirebaseCore",
"FirebaseCoreDiagnostics",
"FirebaseInstallations",
"GoogleAppMeasurement",
"GoogleDataTransport",
"GoogleUtilities",
"nanopb",
"PromisesObjC"
).map {
val archVariant = if (konanTarget is KonanTarget.IOS_X64) "ios-arm64_i386_x86_64-simulator" else "ios-arm64_armv7"

rootProject.project("firebase-app").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/$archVariant")
}
).plus(
listOf(
"FirebaseFunctions",
Expand Down
2 changes: 1 addition & 1 deletion firebase-functions/src/nativeInterop/cinterop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFunctionsBinary.json" == 8.1.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseFunctionsBinary.json" == 8.2.0