File tree 13 files changed +99
-16
lines changed
firebase-app/src/jvmTest/kotlin/dev/gitlive/firebase
firebase-auth/src/jvmTest/kotlin/dev/gitlive/firebase/auth
firebase-config/src/jvmTest/kotlin/dev/gitlive/firebase/remoteconfig
firebase-database/src/jvmTest/kotlin/dev/gitlive/firebase/database
src/jvmTest/kotlin/dev/gitlive/firebase/firestore
firebase-perf/src/jvmTest/kotlin/dev/gitlive/firebase/perf
firebase-storage/src/jvmTest/kotlin/dev/gitlive/firebase/storage
src/jvmMain/kotlin/dev/gitlive/firebase
13 files changed +99
-16
lines changed Original file line number Diff line number Diff line change @@ -117,3 +117,25 @@ jobs:
117
117
with :
118
118
name : " Firebase Debug Log"
119
119
path : " **/firebase-debug.log"
120
+ build-jvm :
121
+ runs-on : ubuntu-latest
122
+ steps :
123
+ - uses : actions/checkout@v3
124
+ - name : Setup test environment
125
+ uses : ./.github/actions/setup_test_action
126
+ timeout-minutes : 10
127
+ - name : Run JVM Tests
128
+ run : ./gradlew cleanTest jvmTest
129
+ - name : Upload JVM test artifact
130
+ uses : actions/upload-artifact@v3
131
+ if : failure()
132
+ with :
133
+ name : " JVM Test Report HTML"
134
+ path : |
135
+ **/build/reports/tests/jvmTest/
136
+ - name : Upload Firebase Debug Log
137
+ uses : actions/upload-artifact@v3
138
+ if : failure()
139
+ with :
140
+ name : " Firebase Debug Log"
141
+ path : " **/firebase-debug.log"
Original file line number Diff line number Diff line change 6
6
7
7
package dev.gitlive.firebase
8
8
9
- actual val context: Any = Unit
9
+ actual val context: Any = testContext
10
10
11
11
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
12
12
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 6
6
7
7
package dev.gitlive.firebase.auth
8
8
9
+ import dev.gitlive.firebase.testContext
10
+
9
11
actual val emulatorHost: String = " 10.0.2.2"
10
12
11
- actual val context: Any = Unit
13
+ actual val context: Any = testContext
12
14
13
15
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
14
16
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 6
6
7
7
package dev.gitlive.firebase.remoteconfig
8
8
9
- actual val context: Any = Unit
9
+ import dev.gitlive.firebase.testContext
10
+
11
+ actual val context: Any = testContext
10
12
11
13
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
12
14
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 6
6
7
7
package dev.gitlive.firebase.database
8
8
9
- actual val emulatorHost : String = " 10.0.2.2 "
9
+ import dev.gitlive.firebase.testContext
10
10
11
- actual val context: Any = Unit
11
+ actual val emulatorHost: String = " localhost"
12
+
13
+ actual val context: Any = testContext
12
14
13
15
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
14
16
actual annotation class IgnoreForAndroidUnitTest
17
+
18
+ @Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
19
+ actual annotation class IgnoreForAndroidTest
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ public final class dev/gitlive/firebase/firestore/DocumentSnapshot {
125
125
126
126
public final class dev/gitlive/firebase/firestore/DoubleAsTimestampSerializer : kotlinx/serialization/KSerializer {
127
127
public static final field INSTANCE Ldev/gitlive/firebase/firestore/DoubleAsTimestampSerializer;
128
- public static final field serverTimestamp D
128
+ public static final field SERVER_TIMESTAMP D
129
129
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Double;
130
130
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
131
131
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ public final class dev/gitlive/firebase/firestore/DocumentSnapshot {
125
125
126
126
public final class dev/gitlive/firebase/firestore/DoubleAsTimestampSerializer : kotlinx/serialization/KSerializer {
127
127
public static final field INSTANCE Ldev/gitlive/firebase/firestore/DoubleAsTimestampSerializer;
128
- public static final field serverTimestamp D
128
+ public static final field SERVER_TIMESTAMP D
129
129
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Double;
130
130
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
131
131
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
Original file line number Diff line number Diff line change
1
+ package dev.gitlive.firebase.firestore
2
+
3
+ import dev.gitlive.firebase.testContext
4
+
5
+ actual val emulatorHost: String = " localhost"
6
+
7
+ actual val context: Any = testContext
8
+
9
+ @Suppress(" UNCHECKED_CAST" )
10
+ actual fun encodedAsMap (encoded : Any? ): Map <String , Any ?> = encoded as Map <String , Any ?>
11
+ actual fun Map <String , Any ?>.asEncoded (): Any = this
Original file line number Diff line number Diff line change 6
6
7
7
package dev.gitlive.firebase.perf
8
8
9
- actual val emulatorHost : String = " 10.0.2.2 "
9
+ import dev.gitlive.firebase.testContext
10
10
11
- actual val context: Any = Unit
11
+ actual val emulatorHost: String = " localhost"
12
+
13
+ actual val context: Any = testContext
12
14
13
15
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
14
16
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 6
6
7
7
package dev.gitlive.firebase.storage
8
8
9
- actual val emulatorHost : String = " 10.0.2.2 "
9
+ import dev.gitlive.firebase.testContext
10
10
11
- actual val context: Any = Unit
11
+ actual val emulatorHost: String = " localhost"
12
+
13
+ actual val context: Any = testContext
12
14
13
15
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
14
16
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 1
- public final class dev/gitlive/firebase/TestUtilsAndroid {
1
+ public final class dev/gitlive/firebase/TestUtilsJvm {
2
+ public static final fun getTestContext ()Landroid/app/Application;
2
3
public static final fun nativeAssertEquals (Ljava/lang/Object;Ljava/lang/Object;)V
3
4
public static final fun nativeListOf ([Ljava/lang/Object;)Ljava/lang/Object;
4
5
public static final fun nativeMapOf ([Lkotlin/Pair;)Ljava/lang/Object;
Original file line number Diff line number Diff line change @@ -109,14 +109,17 @@ kotlin {
109
109
}
110
110
}
111
111
112
- getByName(" jvmMain" ) {
113
- kotlin.srcDir(" src/androidMain/kotlin" )
114
- }
115
-
116
112
getByName(" jsMain" ) {
117
113
dependencies {
118
114
implementation(kotlin(" test-js" ))
119
115
}
120
116
}
117
+
118
+ getByName(" jvmMain" ) {
119
+ dependencies {
120
+ val coroutinesVersion: String by project
121
+ api(" org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutinesVersion " )
122
+ }
123
+ }
121
124
}
122
125
}
Original file line number Diff line number Diff line change
1
+ @file:JvmName(" TestUtilsJvm" )
2
+ /*
3
+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
4
+ */
5
+
6
+ package dev.gitlive.firebase
7
+
8
+ import android.app.Application
9
+ import com.google.firebase.FirebasePlatform
10
+ import kotlinx.coroutines.CoroutineScope
11
+ import kotlinx.coroutines.runBlocking
12
+ import kotlin.time.Duration.Companion.minutes
13
+
14
+ val testContext = Application ().apply {
15
+ FirebasePlatform .initializeFirebasePlatform(object : FirebasePlatform () {
16
+ val storage = mutableMapOf<String , String >()
17
+ override fun store (key : String , value : String ) = storage.set(key, value)
18
+ override fun retrieve (key : String ) = storage[key]
19
+ override fun clear (key : String ) {
20
+ storage.remove(key)
21
+ }
22
+ override fun log (msg : String ) = println (msg)
23
+ })
24
+ }
25
+
26
+ actual fun runTest (test : suspend CoroutineScope .() -> Unit ) = kotlinx.coroutines.test.runTest(timeout = 5 .minutes) { test() }
27
+ actual fun runBlockingTest (action : suspend CoroutineScope .() -> Unit ) = runBlocking(block = action)
28
+
29
+ actual fun nativeMapOf (vararg pairs : Pair <Any , Any ?>): Any = mapOf (* pairs)
30
+ actual fun nativeListOf (vararg elements : Any? ): Any = listOf (* elements)
31
+ actual fun nativeAssertEquals (expected : Any? , actual : Any? ) {
32
+ kotlin.test.assertEquals(expected, actual)
33
+ }
You can’t perform that action at this time.
0 commit comments