File tree 10 files changed +91
-13
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
firebase-firestore/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
10 files changed +91
-13
lines changed Original file line number Diff line number Diff line change @@ -113,3 +113,25 @@ jobs:
113
113
with :
114
114
name : " Firebase Debug Log"
115
115
path : " **/firebase-debug.log"
116
+ build-jvm :
117
+ runs-on : ubuntu-latest
118
+ steps :
119
+ - uses : actions/checkout@v3
120
+ - name : Setup test environment
121
+ uses : ./.github/actions/setup_test_action
122
+ timeout-minutes : 10
123
+ - name : Run JVM Tests
124
+ run : ./gradlew cleanTest jvmTest
125
+ - name : Upload JVM test artifact
126
+ uses : actions/upload-artifact@v3
127
+ if : failure()
128
+ with :
129
+ name : " JVM Test Report HTML"
130
+ path : |
131
+ **/build/reports/tests/jvmTest/
132
+ - name : Upload Firebase Debug Log
133
+ uses : actions/upload-artifact@v3
134
+ if : failure()
135
+ with :
136
+ name : " Firebase Debug Log"
137
+ path : " **/firebase-debug.log"
Original file line number Diff line number Diff line change 5
5
@file:JvmName(" tests" )
6
6
package dev.gitlive.firebase
7
7
8
- actual val context: Any = Unit
8
+ actual val context: Any = testContext
9
9
10
10
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
11
11
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 5
5
@file:JvmName(" tests" )
6
6
package dev.gitlive.firebase.auth
7
7
8
+ import dev.gitlive.firebase.testContext
8
9
9
10
actual val emulatorHost: String = " 10.0.2.2"
10
11
11
- actual val context: Any = Unit
12
+ actual val context: Any = testContext
12
13
13
14
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
14
15
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 5
5
@file:JvmName(" tests" )
6
6
package dev.gitlive.firebase.remoteconfig
7
7
8
- actual val context: Any = Unit
8
+ import dev.gitlive.firebase.testContext
9
+
10
+ actual val context: Any = testContext
9
11
10
12
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
11
13
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 5
5
@file:JvmName(" tests" )
6
6
package dev.gitlive.firebase.database
7
7
8
- actual val emulatorHost : String = " 10.0.2.2 "
8
+ import dev.gitlive.firebase.testContext
9
9
10
- actual val context: Any = Unit
10
+ actual val emulatorHost: String = " localhost"
11
+
12
+ actual val context: Any = testContext
11
13
12
14
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
13
15
actual annotation class IgnoreForAndroidUnitTest
16
+ @Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
17
+ actual annotation class IgnoreForAndroidTest
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 5
5
@file:JvmName(" tests" )
6
6
package dev.gitlive.firebase.perf
7
7
8
- actual val emulatorHost : String = " 10.0.2.2 "
8
+ import dev.gitlive.firebase.testContext
9
9
10
- actual val context: Any = Unit
10
+ actual val emulatorHost: String = " localhost"
11
+
12
+ actual val context: Any = testContext
11
13
12
14
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
13
15
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change 5
5
@file:JvmName(" tests" )
6
6
package dev.gitlive.firebase.storage
7
7
8
- actual val emulatorHost : String = " 10.0.2.2 "
8
+ import dev.gitlive.firebase.testContext
9
9
10
- actual val context: Any = Unit
10
+ actual val emulatorHost: String = " localhost"
11
+
12
+ actual val context: Any = testContext
11
13
12
14
@Target(AnnotationTarget .CLASS , AnnotationTarget .FUNCTION )
13
15
actual annotation class IgnoreForAndroidUnitTest
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 ) { storage.remove(key) }
20
+ override fun log (msg : String ) = println (msg)
21
+ })
22
+ }
23
+
24
+ actual fun runTest (test : suspend CoroutineScope .() -> Unit ) = kotlinx.coroutines.test.runTest(timeout = 5 .minutes) { test() }
25
+ actual fun runBlockingTest (action : suspend CoroutineScope .() -> Unit ) = runBlocking(block = action)
26
+
27
+ actual fun nativeMapOf (vararg pairs : Pair <Any , Any ?>): Any = mapOf (* pairs)
28
+ actual fun nativeListOf (vararg elements : Any? ): Any = listOf (* elements)
29
+ actual fun nativeAssertEquals (expected : Any? , actual : Any? ) {
30
+ kotlin.test.assertEquals(expected, actual)
31
+ }
You can’t perform that action at this time.
0 commit comments