Skip to content

Commit d66734c

Browse files
committed
Fix tests
1 parent 5bb89b8 commit d66734c

File tree

11 files changed

+30
-37
lines changed
  • firebase-auth/src
    • commonTest/kotlin/dev/gitlive/firebase/auth
    • jsTest/kotlin/dev/gitlive/firebase/auth
  • firebase-config/src
  • firebase-crashlytics/src/commonTest/kotlin/dev/gitlive/firebase/crashlytics
  • firebase-database/src/androidAndroidTest/kotlin/dev/gitlive/firebase/database
  • firebase-firestore/src
    • androidAndroidTest/kotlin/dev/gitlive/firebase/firestore
    • commonTest/kotlin/dev/gitlive/firebase/firestore
    • jsTest/kotlin/dev/gitlive/firebase/firestore
  • firebase-perf/src

11 files changed

+30
-37
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
package dev.gitlive.firebase.auth
66

77
import dev.gitlive.firebase.*
8+
import kotlinx.coroutines.test.TestResult
89
import kotlin.random.Random
910
import kotlin.test.*
1011

1112
expect val emulatorHost: String
1213
expect val context: Any
13-
expect fun runTest(test: suspend () -> Unit)
14+
expect fun runTest(test: suspend () -> Unit): TestResult
1415

1516
class FirebaseAuthTest {
1617

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ actual val emulatorHost: String = "localhost"
99

1010
actual val context: Any = Unit
1111

12-
actual fun runTest(test: suspend () -> Unit) {
13-
kotlinx.coroutines.test.runTest { test() }
14-
}
12+
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }

firebase-config/src/commonTest/kotlin/dev/gitlive/firebase/remoteconfig/FirebaseRemoteConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import dev.gitlive.firebase.Firebase
88
import dev.gitlive.firebase.FirebaseOptions
99
import dev.gitlive.firebase.apps
1010
import dev.gitlive.firebase.initialize
11+
import kotlinx.coroutines.test.TestResult
1112
import kotlin.test.AfterTest
1213
import kotlin.test.BeforeTest
1314
import kotlin.test.Ignore
1415
import kotlin.test.Test
1516
import kotlin.test.assertEquals
1617

1718
expect val context: Any
18-
expect fun runTest(test: suspend () -> Unit)
19+
expect fun runTest(test: suspend () -> Unit): TestResult
1920

2021
class FirebaseRemoteConfigTest {
2122
private val defaults = arrayOf(

firebase-config/src/jsTest/kotlin/dev/gitlive/firebase/remoteconfig/FirebaseRemoteConfig.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ package dev.gitlive.firebase.remoteconfig
33

44
actual val context: Any = Unit
55

6-
actual fun runTest(test: suspend () -> Unit) {
7-
kotlinx.coroutines.test.runTest { test() }
8-
}
6+
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import dev.gitlive.firebase.FirebaseOptions
99
import dev.gitlive.firebase.apps
1010
import dev.gitlive.firebase.initialize
1111
import kotlinx.coroutines.CoroutineScope
12+
import kotlinx.coroutines.test.TestResult
1213
import kotlin.test.BeforeTest
1314
import kotlin.test.Test
1415
import kotlin.test.assertFalse
15-
import kotlin.test.assertNotNull
1616

1717
expect val emulatorHost: String
1818
expect val context: Any
19-
expect fun runTest(test: suspend CoroutineScope.() -> Unit)
19+
expect fun runTest(test: suspend CoroutineScope.() -> Unit): TestResult
2020

2121
class FirebaseCrashlyticsTest {
2222

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ import kotlinx.coroutines.test.TestResult
1111
actual val emulatorHost: String = "10.0.2.2"
1212

1313
actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext
14-
actual fun runTest(test: suspend () -> Unit): TestResult = kotlinx.coroutines.test.runTest { test() }
14+
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ actual val emulatorHost: String = "10.0.2.2"
1313

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

16-
actual fun runTest(test: suspend CoroutineScope.() -> Unit) = runBlocking { test() }
16+
actual fun runTest(test: suspend CoroutineScope.() -> Unit) = kotlinx.coroutines.test.runTest { test() }

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import dev.gitlive.firebase.FirebaseOptions
99
import dev.gitlive.firebase.apps
1010
import dev.gitlive.firebase.initialize
1111
import kotlinx.coroutines.CoroutineScope
12+
import kotlinx.coroutines.Dispatchers
1213
import kotlinx.coroutines.async
1314
import kotlinx.coroutines.delay
1415
import kotlinx.coroutines.flow.filter
1516
import kotlinx.coroutines.flow.first
16-
import kotlinx.coroutines.withTimeout
17+
import kotlinx.coroutines.test.TestResult
18+
import kotlinx.coroutines.withContext
1719
import kotlinx.serialization.Serializable
1820
import kotlin.random.Random
1921
import kotlin.test.BeforeTest
@@ -26,7 +28,7 @@ import kotlin.test.assertTrue
2628

2729
expect val emulatorHost: String
2830
expect val context: Any
29-
expect fun runTest(test: suspend CoroutineScope.() -> Unit)
31+
expect fun runTest(test: suspend CoroutineScope.() -> Unit): TestResult
3032

3133
class FirebaseFirestoreTest {
3234

@@ -157,11 +159,9 @@ class FirebaseFirestoreTest {
157159
.document("test${Random.nextInt()}")
158160

159161
val deferredPendingWritesSnapshot = async {
160-
withTimeout(5000) {
161-
doc.snapshots.filter { it.exists }.first()
162-
}
162+
doc.snapshots.filter { it.exists }.first()
163163
}
164-
delay(100) // makes possible to catch pending writes snapshot
164+
nonSkippedDelay(100) // makes possible to catch pending writes snapshot
165165

166166
doc.set(
167167
FirestoreTimeTest.serializer(),
@@ -180,11 +180,9 @@ class FirebaseFirestoreTest {
180180
.document("test${Random.nextInt()}")
181181

182182
val deferredPendingWritesSnapshot = async {
183-
withTimeout(5000) {
184-
doc.snapshots.filter { it.exists }.first()
185-
}
183+
doc.snapshots.filter { it.exists }.first()
186184
}
187-
delay(100) // makes possible to catch pending writes snapshot
185+
nonSkippedDelay(100) // makes possible to catch pending writes snapshot
188186

189187
doc.set(FirestoreTimeTest.serializer(), FirestoreTimeTest("ServerTimestampBehavior", Timestamp.ServerTimestamp))
190188

@@ -201,11 +199,9 @@ class FirebaseFirestoreTest {
201199
.document("test${Random.nextInt()}")
202200

203201
val deferredPendingWritesSnapshot = async {
204-
withTimeout(5000) {
205-
doc.snapshots.filter { it.exists }.first()
206-
}
202+
doc.snapshots.filter { it.exists }.first()
207203
}
208-
delay(100) // makes possible to catch pending writes snapshot
204+
nonSkippedDelay(100) // makes possible to catch pending writes snapshot
209205

210206
doc.set(FirestoreTimeTest.serializer(), FirestoreTimeTest("ServerTimestampBehavior", Timestamp.ServerTimestamp))
211207

@@ -445,11 +441,9 @@ class FirebaseFirestoreTest {
445441
.document("test${Random.nextInt()}")
446442

447443
val deferredPendingWritesSnapshot = async {
448-
withTimeout(5000) {
449-
doc.snapshots.filter { it.exists }.first()
450-
}
444+
doc.snapshots.filter { it.exists }.first()
451445
}
452-
delay(100) // makes possible to catch pending writes snapshot
446+
nonSkippedDelay(100) // makes possible to catch pending writes snapshot
453447

454448
doc.set(DoubleTimestamp.serializer(), DoubleTimestamp(DoubleAsTimestampSerializer.serverTimestamp))
455449

@@ -470,4 +464,8 @@ class FirebaseFirestoreTest {
470464
.document("three")
471465
.set(FirestoreTest.serializer(), FirestoreTest("ccc"))
472466
}
467+
468+
private suspend fun nonSkippedDelay(timeout: Long) = withContext(Dispatchers.Default) {
469+
delay(timeout)
470+
}
473471
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ actual val emulatorHost: String = "localhost"
1111

1212
actual val context: Any = Unit
1313

14-
actual fun runTest(test: suspend CoroutineScope.() -> Unit) {
15-
runTest { test() }
16-
}
14+
actual fun runTest(test: suspend CoroutineScope.() -> Unit) = runTest { test() }

firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import dev.gitlive.firebase.FirebaseOptions
99
import dev.gitlive.firebase.apps
1010
import dev.gitlive.firebase.initialize
1111
import kotlinx.coroutines.CoroutineScope
12+
import kotlinx.coroutines.test.TestResult
1213
import kotlin.test.*
1314

1415
expect val emulatorHost: String
1516
expect val context: Any
16-
expect fun runTest(test: suspend CoroutineScope.() -> Unit)
17+
expect fun runTest(test: suspend CoroutineScope.() -> Unit): TestResult
1718

1819
class FirebasePerformanceTest {
1920

0 commit comments

Comments
 (0)