Skip to content

Commit f3f693a

Browse files
committed
Better test cleanup
1 parent 4d3e7c5 commit f3f693a

File tree

63 files changed

+309
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+309
-540
lines changed

build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ subprojects {
115115
"androidMainImplementation"(platform("com.google.firebase:firebase-bom:$firebaseBoMVersion"))
116116
"commonTestImplementation"(kotlin("test-common"))
117117
"commonTestImplementation"(kotlin("test-annotations-common"))
118-
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
119-
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
120118
if (this@afterEvaluate.name != "firebase-crashlytics") {
121119
"jvmMainApi"("dev.gitlive:firebase-java-sdk:0.1.1")
122120
"jvmMainApi"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion") {

firebase-app/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ import androidx.test.platform.app.InstrumentationRegistry
99

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

12-
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }
1312
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1413
actual annotation class IgnoreForAndroidUnitTest

firebase-app/src/androidMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ actual class FirebaseApp internal constructor(val android: com.google.firebase.F
3535
actual val options: FirebaseOptions
3636
get() = android.options.run { FirebaseOptions(applicationId, apiKey, databaseUrl, gaTrackingId, storageBucket, projectId) }
3737

38-
actual fun delete() = android.delete()
38+
actual suspend fun delete() = android.delete()
3939
}
4040

4141
actual fun Firebase.apps(context: Any?) = com.google.firebase.FirebaseApp.getApps(context as Context)

firebase-app/src/androidUnitTest/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import org.junit.Ignore
99

1010
actual val context: Any = ""
1111

12-
actual fun runTest(test: suspend () -> Unit) = kotlinx.coroutines.test.runTest { test() }
13-
1412
// Tests are to be run on AndroidInstrumentedTests.
1513
// Kotlin 1.8 does not allow us to remove the commonTest dependency from AndroidUnitTest
1614
// Therefore we just wont run them

firebase-app/src/commonMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object Firebase
1919
expect class FirebaseApp {
2020
val name: String
2121
val options: FirebaseOptions
22-
fun delete()
22+
suspend fun delete()
2323
}
2424

2525
/** Returns the default firebase app instance. */

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,15 @@ import kotlin.test.Test
44
import kotlin.test.assertEquals
55

66
expect val context: Any
7-
expect fun runTest(test: suspend () -> Unit)
87
expect annotation class IgnoreForAndroidUnitTest()
98

109
@IgnoreForAndroidUnitTest
1110
class FirebaseAppTest {
1211
@Test
13-
fun testInitialize() {
12+
fun testInitialize() = runTest {
1413
Firebase.initialize(
1514
context,
16-
FirebaseOptions(
17-
applicationId = "1:846484016111:ios:dd1f6688bad7af768c841a",
18-
apiKey = "AIzaSyCK87dcMFhzCz_kJVs2cT2AVlqOTLuyWV0",
19-
databaseUrl = "https://fir-kotlin-sdk.firebaseio.com",
20-
storageBucket = "fir-kotlin-sdk.appspot.com",
21-
projectId = "fir-kotlin-sdk",
22-
gcmSenderId = "846484016111"
23-
)
15+
firebaseOptions
2416
)
2517

2618
assertEquals(1, Firebase.apps(context).size)

firebase-app/src/iosMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ actual class FirebaseApp internal constructor(val ios: FIRApp) {
3333
actual val options: FirebaseOptions
3434
get() = ios.options.run { FirebaseOptions(bundleID, APIKey!!, databaseURL!!, trackingID, storageBucket, projectID) }
3535

36-
actual fun delete() { }
36+
actual suspend fun delete() {
37+
val deleted = CompletableDeferred<Unit>()
38+
ios.deleteApp { deleted.complete(Unit) }
39+
deleted.await()
40+
}
3741
}
3842

3943
actual fun Firebase.apps(context: Any?) = FIRApp.allApps()

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,7 @@
44

55
package dev.gitlive.firebase
66

7-
import kotlinx.coroutines.*
8-
import platform.Foundation.*
9-
107
actual val context: Any = Unit
118

12-
actual fun runTest(test: suspend () -> Unit) = runBlocking {
13-
val testRun = MainScope().async { test() }
14-
while (testRun.isActive) {
15-
NSRunLoop.mainRunLoop.runMode(
16-
NSDefaultRunLoopMode,
17-
beforeDate = NSDate.create(timeInterval = 1.0, sinceDate = NSDate())
18-
)
19-
yield()
20-
}
21-
testRun.await()
22-
}
23-
249
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
2510
actual annotation class IgnoreForAndroidUnitTest

firebase-app/src/jsMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ actual class FirebaseApp internal constructor(val js: JsFirebaseApp) {
3434
FirebaseOptions(appId, apiKey, databaseURL, gaTrackingId, storageBucket, projectId, messagingSenderId, authDomain)
3535
}
3636

37-
actual fun delete() {
37+
actual suspend fun delete() {
3838
deleteApp(js)
3939
}
4040
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44

55
package dev.gitlive.firebase
66

7-
import kotlinx.coroutines.test.runTest
8-
import kotlin.time.Duration.Companion.minutes
9-
107
actual val context: Any = Unit
118

12-
actual fun runTest(test: suspend () -> Unit) {
13-
runTest(timeout = 5.minutes) { test() }
14-
}
15-
169
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1710
actual annotation class IgnoreForAndroidUnitTest

0 commit comments

Comments
 (0)