Skip to content

Commit

Permalink
fix all android tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarmanz committed Nov 30, 2023
1 parent ab05cb6 commit 2fe3aa3
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 19 deletions.
20 changes: 10 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ bazel_common_initialize(
# url = "https://github.com/google/dagger/archive/dagger-%s.zip" % DAGGER_TAG,
#)

#http_archive(
# name = "robolectric",
# sha256 = "4e002cbe712c8abd9c3b565eb165787a2a7a92dfafb117e0d84b6767c2053189",
# strip_prefix = "robolectric-bazel-4.8",
# urls = ["https://github.com/robolectric/robolectric-bazel/archive/4.8.tar.gz"],
#)
#
#load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
#
#robolectric_repositories()
http_archive(
name = "robolectric",
sha256 = "4e002cbe712c8abd9c3b565eb165787a2a7a92dfafb117e0d84b6767c2053189",
strip_prefix = "robolectric-bazel-4.8",
urls = ["https://github.com/robolectric/robolectric-bazel/archive/4.8.tar.gz"],
)

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

http_archive(
name = "build_bazel_rules_android",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.intuit.player.android.extensions

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext

@OptIn(ExperimentalCoroutinesApi::class)
public class CoroutineTestDispatcherExtension : AfterEachCallback, BeforeEachCallback {

private val dispatcher = UnconfinedTestDispatcher()

override fun beforeEach(context: ExtensionContext?): Unit = Dispatchers.setMain(dispatcher)

override fun afterEach(context: ExtensionContext?): Unit = Dispatchers.resetMain()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.widget.TextView
import com.intuit.player.android.AndroidPlayer
import com.intuit.player.android.AssetContext
import com.intuit.player.android.asset.RenderableAsset
import com.intuit.player.android.extensions.CoroutineTestDispatcherExtension
import com.intuit.player.android.utils.TestAssetsPlugin
import com.intuit.player.jvm.core.asset.Asset
import com.intuit.player.jvm.core.flow.Flow
Expand Down
8 changes: 5 additions & 3 deletions jvm/j2v8/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
load("//jvm/dependencies:versions.bzl", "versions")
load("@rules_player//maven:parse_coordinates.bzl", "parse_coordinates")

maven = []
maven = [
"com.github.AlexTrotsenko:j2v8-debugger:%s" % versions.j2v8.debugger,
]

main_exports = [
"//jvm/core",
]

main_deps = main_exports + [
main_deps = main_exports + parse_coordinates(maven) + [
"//jvm:kotlin_serialization",

# TODO: Ensure all of these are _just_ compileOnly deps
"//jvm/j2v8/libs:j2v8_empty",
"//jvm/j2v8/libs:j2v8_debugger_no_op",
]

main_resources = [
Expand Down
6 changes: 0 additions & 6 deletions jvm/j2v8/libs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ java_import(
name = "j2v8_linux",
jars = [":j2v8_linux_x86_64-6.1.0.jar"],
)

# TODO: Iterate on debugger strategy
java_import(
name = "j2v8_debugger_no_op",
jars = [":j2v8_debugger_no_op.jar"],
)
Binary file removed jvm/j2v8/libs/j2v8_debugger_no_op.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal class FlowScopePluginTest {
@BeforeEach fun setup() {
every { player.hooks.state.tap(any(), capture(stateTap)) } returns "some-id"
every { inProgressState.flow } returns flow
every { player.scope } returns scope

flowScopePlugin = FlowScopePlugin().apply {
apply(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ import com.intuit.player.jvm.utils.start
import com.intuit.player.plugins.transactions.PendingTransactionPlugin
import com.intuit.player.plugins.types.CommonTypesPlugin
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import kotlinx.coroutines.withTimeout
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.rules.TestName
Expand Down Expand Up @@ -103,6 +108,7 @@ abstract class AssetTest(val group: String? = null) {

@Before
fun beforeEach() {
Dispatchers.setMain(TestCoroutineDispatcher())
player.onUpdate { asset, _ -> currentAssetTree = asset }
player.hooks.state.tap { state ->
if (state !is InProgressState) {
Expand All @@ -112,6 +118,11 @@ abstract class AssetTest(val group: String? = null) {
}
}

@After
fun afterEach() {
Dispatchers.resetMain()
}

fun launchMock() = launchMock(name.methodName)

fun launchMock(name: String) = launchMock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ maven = [
"androidx.test:runner:%s" % versions.androidx.test.core,
"junit:junit:%s" % versions.testing.junit,
"org.robolectric:robolectric:%s" % versions.testing.robolectric,
"org.jetbrains.kotlinx:kotlinx-coroutines-test:%s" % versions.kotlin.coroutines,
]

main_deps = parse_coordinates(maven) + [
Expand Down

0 comments on commit 2fe3aa3

Please sign in to comment.