File tree Expand file tree Collapse file tree 5 files changed +114
-0
lines changed
androidAndroidTest/kotlin/dev/gitlive/firebase/database
commonTest/kotlin/dev.gitlive.firebase.database
iosTest/kotlin/dev/gitlive/firebase/database
jsTest/kotlin/dev.gitlive.firebase.database Expand file tree Collapse file tree 5 files changed +114
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ version = project.property("firebase-database.version") as String
10
10
plugins {
11
11
id(" com.android.library" )
12
12
kotlin(" multiplatform" )
13
+ kotlin(" plugin.serialization" ) version " 1.5.31"
13
14
}
14
15
15
16
repositories {
@@ -22,11 +23,17 @@ android {
22
23
defaultConfig {
23
24
minSdk = property(" minSdkVersion" ) as Int
24
25
targetSdk = property(" targetSdkVersion" ) as Int
26
+ testInstrumentationRunner = " androidx.test.runner.AndroidJUnitRunner"
27
+ multiDexEnabled = true
25
28
}
26
29
sourceSets {
27
30
getByName(" main" ) {
28
31
manifest.srcFile(" src/androidMain/AndroidManifest.xml" )
29
32
}
33
+ getByName(" androidTest" ){
34
+ java.srcDir(file(" src/androidAndroidTest/kotlin" ))
35
+ manifest.srcFile(" src/androidAndroidTest/AndroidManifest.xml" )
36
+ }
30
37
}
31
38
testOptions {
32
39
unitTests.apply {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ @file:JvmName(" tests" )
6
+ package dev.gitlive.firebase.database
7
+
8
+ import androidx.test.platform.app.InstrumentationRegistry
9
+ import kotlinx.coroutines.runBlocking
10
+
11
+ actual val emulatorHost: String = " 10.0.2.2"
12
+
13
+ actual val context: Any = InstrumentationRegistry .getInstrumentation().targetContext
14
+
15
+ actual fun runTest (test : suspend () -> Unit ) = runBlocking { test() }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ package dev.gitlive.firebase.database
6
+
7
+ import dev.gitlive.firebase.*
8
+ import kotlinx.coroutines.flow.first
9
+ import kotlinx.serialization.*
10
+ import kotlin.test.*
11
+
12
+ expect val emulatorHost: String
13
+ expect val context: Any
14
+ expect fun runTest (test : suspend () -> Unit )
15
+
16
+ class database {
17
+
18
+ @BeforeTest
19
+ fun initializeFirebase () {
20
+ Firebase
21
+ .takeIf { Firebase .apps(context).isEmpty() }
22
+ ?.apply {
23
+ initialize(
24
+ context,
25
+ FirebaseOptions (
26
+ applicationId = " 1:846484016111:ios:dd1f6688bad7af768c841a" ,
27
+ apiKey = " AIzaSyCK87dcMFhzCz_kJVs2cT2AVlqOTLuyWV0" ,
28
+ databaseUrl = " https://fir-kotlin-sdk.firebaseio.com" ,
29
+ storageBucket = " fir-kotlin-sdk.appspot.com" ,
30
+ projectId = " fir-kotlin-sdk" ,
31
+ gcmSenderId = " 846484016111"
32
+ )
33
+ )
34
+ Firebase .database.useEmulator(emulatorHost, 8080 )
35
+ }
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ package dev.gitlive.firebase.database
6
+
7
+ import kotlinx.coroutines.*
8
+ import platform.Foundation.*
9
+
10
+ actual val emulatorHost: String = " localhost"
11
+
12
+ actual val context: Any = Unit
13
+
14
+ actual fun runTest (test : suspend () -> Unit ) = runBlocking {
15
+ val testRun = MainScope ().async { test() }
16
+ while (testRun.isActive) {
17
+ NSRunLoop .mainRunLoop.runMode(
18
+ NSDefaultRunLoopMode ,
19
+ beforeDate = NSDate .create(timeInterval = 1.0 , sinceDate = NSDate ())
20
+ )
21
+ yield ()
22
+ }
23
+ testRun.await()
24
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ package dev.gitlive.firebase.database
6
+
7
+ import kotlinx.coroutines.GlobalScope
8
+ import kotlinx.coroutines.promise
9
+
10
+ actual val emulatorHost: String = " localhost"
11
+
12
+ actual val context: Any = Unit
13
+
14
+ actual fun runTest (test : suspend () -> Unit ) = GlobalScope
15
+ .promise {
16
+ try {
17
+ test()
18
+ } catch (e: Throwable ) {
19
+ e.log()
20
+ throw e
21
+ }
22
+ }.asDynamic()
23
+
24
+ internal fun Throwable.log () {
25
+ console.error(this )
26
+ cause?.let {
27
+ console.error(" Caused by:" )
28
+ it.log()
29
+ }
30
+ }
31
+
You can’t perform that action at this time.
0 commit comments