Skip to content

Commit 2cbbe39

Browse files
committed
Skip auth tests on iOS
1 parent 55797eb commit 2cbbe39

File tree

4 files changed

+41
-10
lines changed
  • firebase-auth/src
    • androidAndroidTest/kotlin/dev/gitlive/firebase/auth
    • commonTest/kotlin/dev/gitlive/firebase/auth
    • iosTest/kotlin/dev/gitlive/firebase/auth
    • jsTest/kotlin/dev/gitlive/firebase/auth

4 files changed

+41
-10
lines changed

firebase-auth/src/androidAndroidTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase.auth
77

8+
import android.util.Log
89
import androidx.test.platform.app.InstrumentationRegistry
910
import kotlinx.coroutines.runBlocking
1011

1112
actual val emulatorHost: String = "10.0.2.2"
1213

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

15-
actual fun runTest(test: suspend () -> Unit) = runBlocking { test() }
16+
actual val currentPlatform: TargetPlatform = TargetPlatform.Android
17+
18+
actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
19+
if (skip) {
20+
Log.w("Test", "Skip the test.")
21+
return@runBlocking
22+
}
23+
24+
test()
25+
}
26+

firebase-auth/src/commonTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ import kotlin.test.*
1010

1111
expect val emulatorHost: String
1212
expect val context: Any
13-
expect fun runTest(test: suspend () -> Unit)
13+
expect fun runTest(skip: Boolean = false, test: suspend () -> Unit)
14+
expect val currentPlatform: TargetPlatform
15+
16+
enum class TargetPlatform { Android, IOS, JS }
1417

1518
class FirebaseAuthTest {
1619

20+
// Skip the tests on iOS simulator due keychain exceptions
21+
private val skip = currentPlatform == TargetPlatform.IOS
22+
1723
@BeforeTest
1824
fun initializeFirebase() {
1925
Firebase
@@ -35,14 +41,14 @@ class FirebaseAuthTest {
3541
}
3642

3743
@Test
38-
fun testSignInWithUsernameAndPassword() = runTest {
44+
fun testSignInWithUsernameAndPassword() = runTest(skip) {
3945
val uid = getTestUid("[email protected]", "test123")
4046
val result = Firebase.auth.signInWithEmailAndPassword("[email protected]", "test123")
4147
assertEquals(uid, result.user!!.uid)
4248
}
4349

4450
@Test
45-
fun testCreateUserWithEmailAndPassword() = runTest {
51+
fun testCreateUserWithEmailAndPassword() = runTest(skip) {
4652
val email = "test+${Random.nextInt(100000)}@test.com"
4753
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
4854
assertNotEquals(null, createResult.user?.uid)
@@ -57,7 +63,7 @@ class FirebaseAuthTest {
5763
}
5864

5965
@Test
60-
fun testFetchSignInMethods() = runTest {
66+
fun testFetchSignInMethods() = runTest(skip) {
6167
val email = "test+${Random.nextInt(100000)}@test.com"
6268
var signInMethodResult = Firebase.auth.fetchSignInMethodsForEmail(email)
6369
assertEquals(emptyList(), signInMethodResult)
@@ -69,7 +75,7 @@ class FirebaseAuthTest {
6975
}
7076

7177
@Test
72-
fun testSendEmailVerification() = runTest {
78+
fun testSendEmailVerification() = runTest(skip) {
7379
val email = "test+${Random.nextInt(100000)}@test.com"
7480
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
7581
assertNotEquals(null, createResult.user?.uid)
@@ -79,7 +85,7 @@ class FirebaseAuthTest {
7985
}
8086

8187
@Test
82-
fun sendPasswordResetEmail() = runTest {
88+
fun sendPasswordResetEmail() = runTest(skip) {
8389
val email = "test+${Random.nextInt(100000)}@test.com"
8490
val createResult = Firebase.auth.createUserWithEmailAndPassword(email, "test123")
8591
assertNotEquals(null, createResult.user?.uid)
@@ -90,7 +96,7 @@ class FirebaseAuthTest {
9096
}
9197

9298
@Test
93-
fun testSignInWithCredential() = runTest {
99+
fun testSignInWithCredential() = runTest(skip) {
94100
val uid = getTestUid("[email protected]", "test123")
95101
val credential = EmailAuthProvider.credential("[email protected]", "test123")
96102
val result = Firebase.auth.signInWithCredential(credential)

firebase-auth/src/iosTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ actual val emulatorHost: String = "localhost"
1111

1212
actual val context: Any = Unit
1313

14-
actual fun runTest(test: suspend () -> Unit) = runBlocking {
14+
actual val currentPlatform: TargetPlatform = TargetPlatform.IOS
15+
16+
actual fun runTest(skip: Boolean, test: suspend () -> Unit) = runBlocking {
17+
if (skip) {
18+
NSLog("Skip the test.")
19+
return@runBlocking
20+
}
21+
1522
val testRun = MainScope().async { test() }
1623
while (testRun.isActive) {
1724
NSRunLoop.mainRunLoop.runMode(

firebase-auth/src/jsTest/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ actual val emulatorHost: String = "localhost"
1111

1212
actual val context: Any = Unit
1313

14-
actual fun runTest(test: suspend () -> Unit) = GlobalScope
14+
actual val currentPlatform: TargetPlatform = TargetPlatform.JS
15+
16+
actual fun runTest(skip: Boolean, test: suspend () -> Unit) = GlobalScope
1517
.promise {
18+
if (skip) {
19+
console.log("Skip the test.")
20+
return@promise
21+
}
22+
1623
try {
1724
test()
1825
} catch (e: dynamic) {

0 commit comments

Comments
 (0)