Skip to content

Commit 28fc8d4

Browse files
committed
Merge branch 'feature/kotlin-2.0' into feature/api-validation
2 parents 33e2a8a + 4a27646 commit 28fc8d4

File tree

13 files changed

+99
-16
lines changed

13 files changed

+99
-16
lines changed

.github/workflows/pull_request.yml

+22
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,25 @@ jobs:
117117
with:
118118
name: "Firebase Debug Log"
119119
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"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
package dev.gitlive.firebase
88

9-
actual val context: Any = Unit
9+
actual val context: Any = testContext
1010

1111
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1212
actual annotation class IgnoreForAndroidUnitTest

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
package dev.gitlive.firebase.auth
88

9+
import dev.gitlive.firebase.testContext
10+
911
actual val emulatorHost: String = "10.0.2.2"
1012

11-
actual val context: Any = Unit
13+
actual val context: Any = testContext
1214

1315
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1416
actual annotation class IgnoreForAndroidUnitTest

firebase-config/src/jvmTest/kotlin/dev/gitlive/firebase/remoteconfig/RemoteConfig.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
package dev.gitlive.firebase.remoteconfig
88

9-
actual val context: Any = Unit
9+
import dev.gitlive.firebase.testContext
10+
11+
actual val context: Any = testContext
1012

1113
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1214
actual annotation class IgnoreForAndroidUnitTest

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66

77
package dev.gitlive.firebase.database
88

9-
actual val emulatorHost: String = "10.0.2.2"
9+
import dev.gitlive.firebase.testContext
1010

11-
actual val context: Any = Unit
11+
actual val emulatorHost: String = "localhost"
12+
13+
actual val context: Any = testContext
1214

1315
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1416
actual annotation class IgnoreForAndroidUnitTest
17+
18+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
19+
actual annotation class IgnoreForAndroidTest

firebase-firestore/api/android/firebase-firestore.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public final class dev/gitlive/firebase/firestore/DocumentSnapshot {
125125

126126
public final class dev/gitlive/firebase/firestore/DoubleAsTimestampSerializer : kotlinx/serialization/KSerializer {
127127
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
129129
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Double;
130130
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
131131
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;

firebase-firestore/api/jvm/firebase-firestore.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public final class dev/gitlive/firebase/firestore/DocumentSnapshot {
125125

126126
public final class dev/gitlive/firebase/firestore/DoubleAsTimestampSerializer : kotlinx/serialization/KSerializer {
127127
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
129129
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Double;
130130
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
131131
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
package dev.gitlive.firebase.perf
88

9-
actual val emulatorHost: String = "10.0.2.2"
9+
import dev.gitlive.firebase.testContext
1010

11-
actual val context: Any = Unit
11+
actual val emulatorHost: String = "localhost"
12+
13+
actual val context: Any = testContext
1214

1315
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1416
actual annotation class IgnoreForAndroidUnitTest

firebase-storage/src/jvmTest/kotlin/dev/gitlive/firebase/storage/storage.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
package dev.gitlive.firebase.storage
88

9-
actual val emulatorHost: String = "10.0.2.2"
9+
import dev.gitlive.firebase.testContext
1010

11-
actual val context: Any = Unit
11+
actual val emulatorHost: String = "localhost"
12+
13+
actual val context: Any = testContext
1214

1315
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1416
actual annotation class IgnoreForAndroidUnitTest

test-utils/api/jvm/test-utils.api

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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;
23
public static final fun nativeAssertEquals (Ljava/lang/Object;Ljava/lang/Object;)V
34
public static final fun nativeListOf ([Ljava/lang/Object;)Ljava/lang/Object;
45
public static final fun nativeMapOf ([Lkotlin/Pair;)Ljava/lang/Object;

test-utils/build.gradle.kts

+7-4
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ kotlin {
109109
}
110110
}
111111

112-
getByName("jvmMain") {
113-
kotlin.srcDir("src/androidMain/kotlin")
114-
}
115-
116112
getByName("jsMain") {
117113
dependencies {
118114
implementation(kotlin("test-js"))
119115
}
120116
}
117+
118+
getByName("jvmMain") {
119+
dependencies {
120+
val coroutinesVersion: String by project
121+
api("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutinesVersion")
122+
}
123+
}
121124
}
122125
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)