Skip to content

Commit 4a27646

Browse files
committed
Fixes for JVM
Some tests still failing. To discuss in ticket
1 parent 03e8702 commit 4a27646

File tree

10 files changed

+91
-13
lines changed
  • .github/workflows
  • 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
  • test-utils

10 files changed

+91
-13
lines changed

.github/workflows/pull_request.yml

+22
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,25 @@ jobs:
113113
with:
114114
name: "Firebase Debug Log"
115115
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"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase
77

8-
actual val context: Any = Unit
8+
actual val context: Any = testContext
99

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

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase.auth
77

8+
import dev.gitlive.firebase.testContext
89

910
actual val emulatorHost: String = "10.0.2.2"
1011

11-
actual val context: Any = Unit
12+
actual val context: Any = testContext
1213

1314
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1415
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
@@ -5,7 +5,9 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase.remoteconfig
77

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

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

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase.database
77

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

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

1214
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1315
actual annotation class IgnoreForAndroidUnitTest
16+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
17+
actual annotation class IgnoreForAndroidTest
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
@@ -5,9 +5,11 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase.perf
77

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

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

1214
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
1315
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
@@ -5,9 +5,11 @@
55
@file:JvmName("tests")
66
package dev.gitlive.firebase.storage
77

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

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

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

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,31 @@
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+
}

0 commit comments

Comments
 (0)