Skip to content

Commit

Permalink
Fixes for JVM
Browse files Browse the repository at this point in the history
Some tests still failing. To discuss in ticket
  • Loading branch information
Daeda88 committed Jun 11, 2024
1 parent 03e8702 commit 4a27646
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 13 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,25 @@ jobs:
with:
name: "Firebase Debug Log"
path: "**/firebase-debug.log"
build-jvm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup test environment
uses: ./.github/actions/setup_test_action
timeout-minutes: 10
- name: Run JVM Tests
run: ./gradlew cleanTest jvmTest
- name: Upload JVM test artifact
uses: actions/upload-artifact@v3
if: failure()
with:
name: "JVM Test Report HTML"
path: |
**/build/reports/tests/jvmTest/
- name: Upload Firebase Debug Log
uses: actions/upload-artifact@v3
if: failure()
with:
name: "Firebase Debug Log"
path: "**/firebase-debug.log"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@file:JvmName("tests")
package dev.gitlive.firebase

actual val context: Any = Unit
actual val context: Any = testContext

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
@file:JvmName("tests")
package dev.gitlive.firebase.auth

import dev.gitlive.firebase.testContext

actual val emulatorHost: String = "10.0.2.2"

actual val context: Any = Unit
actual val context: Any = testContext

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
@file:JvmName("tests")
package dev.gitlive.firebase.remoteconfig

actual val context: Any = Unit
import dev.gitlive.firebase.testContext

actual val context: Any = testContext

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
@file:JvmName("tests")
package dev.gitlive.firebase.database

actual val emulatorHost: String = "10.0.2.2"
import dev.gitlive.firebase.testContext

actual val context: Any = Unit
actual val emulatorHost: String = "localhost"

actual val context: Any = testContext

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.gitlive.firebase.firestore

import dev.gitlive.firebase.testContext

actual val emulatorHost: String = "localhost"

actual val context: Any = testContext

@Suppress("UNCHECKED_CAST")
actual fun encodedAsMap(encoded: Any?): Map<String, Any?> = encoded as Map<String, Any?>
actual fun Map<String, Any?>.asEncoded(): Any = this
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
@file:JvmName("tests")
package dev.gitlive.firebase.perf

actual val emulatorHost: String = "10.0.2.2"
import dev.gitlive.firebase.testContext

actual val context: Any = Unit
actual val emulatorHost: String = "localhost"

actual val context: Any = testContext

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
@file:JvmName("tests")
package dev.gitlive.firebase.storage

actual val emulatorHost: String = "10.0.2.2"
import dev.gitlive.firebase.testContext

actual val context: Any = Unit
actual val emulatorHost: String = "localhost"

actual val context: Any = testContext

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
11 changes: 7 additions & 4 deletions test-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ kotlin {
}
}

getByName("jvmMain") {
kotlin.srcDir("src/androidMain/kotlin")
}

getByName("jsMain") {
dependencies {
implementation(kotlin("test-js"))
}
}

getByName("jvmMain") {
dependencies {
val coroutinesVersion: String by project
api("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutinesVersion")
}
}
}
}
31 changes: 31 additions & 0 deletions test-utils/src/jvmMain/kotlin/dev/gitlive/firebase/TestUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@file:JvmName("TestUtilsJvm")
/*
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.gitlive.firebase

import android.app.Application
import com.google.firebase.FirebasePlatform
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import kotlin.time.Duration.Companion.minutes

val testContext = Application().apply {
FirebasePlatform.initializeFirebasePlatform(object : FirebasePlatform() {
val storage = mutableMapOf<String, String>()
override fun store(key: String, value: String) = storage.set(key, value)
override fun retrieve(key: String) = storage[key]
override fun clear(key: String) { storage.remove(key) }
override fun log(msg: String) = println(msg)
})
}

actual fun runTest(test: suspend CoroutineScope.() -> Unit) = kotlinx.coroutines.test.runTest(timeout = 5.minutes) { test() }
actual fun runBlockingTest(action: suspend CoroutineScope.() -> Unit) = runBlocking(block = action)

actual fun nativeMapOf(vararg pairs: Pair<Any, Any?>): Any = mapOf(*pairs)
actual fun nativeListOf(vararg elements: Any?): Any = listOf(*elements)
actual fun nativeAssertEquals(expected: Any?, actual: Any?) {
kotlin.test.assertEquals(expected, actual)
}

0 comments on commit 4a27646

Please sign in to comment.