Skip to content

Commit

Permalink
Sync Android and JVM packages to latest (#222)
Browse files Browse the repository at this point in the history
* SetTimeoutPlugin exception handling enhancement pt. 1

* Make views in Flow nullable

* lint

* SetTimeoutPlugin exception handling enhancement pt. 2

* Call state hook when releasing player

* lint

* expose V8 params in psuedo constructors

* Update into extension method to handle null view case

* support null contextual serialization for assets

* viewmodel tests

* fix test

* attempt fix 2

* guard against logging on release due to weird timing

* add error handling during asset expansion

* clear guideline for top level render function

* add test for hydration scope cancelling on player release

* add coroutine-test import to android player package

* lint

* M1 J2V8 Support

* fix build file

* replace deprecated channel method

* fix bazel intellij sync

* [android#265]: fix orientation change reset

* [android#269]: PlayerViewModel::runtime null safety

* [jvm#224]: [email protected]

* [android#276]: asset handler hook

* [jvm#229]: replacing `getFunction` with `getInvokable`

* [jvm#230]: automatic deserializes functions and invokables

* [jvm#231]: name loggers dynamically

* [jvm#228]: migrate to NodeSerializableField

* fix lingering getFunction replacements

* [jvm#235]: local class discriminators

* [jvm#239]: `JSErrorException` enhancement

* [jvm#237]: expose skipTransition hook

* [jvm#240]: fix testutils node

* [jvm#241]: `NavigationFlowEndState.param` helper

* [android#287]: scroll to top when navigating to a new view

* [jvm#238]: dedicated runtime thread

* [android#286]: `SuspendableAsset`

* [jvm#243] debuggable v8

* [android#292] android debuggable v8

* upgrade kotlin to 1.7 and lint

* working demo app

* all //jvm tests passing

* fix all android tests

* ensure test target fails on failure

* fix instrumented android tests

* lint

* bootstrap intents break everything

* androidx orchestrator

* clean up workspace and use released player rules for kotlin upgrade

* format and comment androidtest python script

* pr comments

---------

Co-authored-by: Larry <[email protected]>
  • Loading branch information
sugarmanz and Kiwiegg authored Dec 5, 2023
1 parent d6664c4 commit cd3c689
Show file tree
Hide file tree
Showing 264 changed files with 5,807 additions and 2,603 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ jobs:
- run: bazel test --define=APPLITOOLS_API_KEY=${APPLITOOLS_API_KEY} --define=APPLITOOLS_BATCH_ID=${CIRCLE_SHA1} --define=APPLITOOLS_PR_NUMBER=${CIRCLE_PULL_REQUEST##*/} --config=ci -- //android/demo:android_instrumentation_test

- run:
when: always
command: |
RESULTS_DIR=_test_results
find -L ./bazel-testlogs -name test.xml | while read line
do
mkdir -p $RESULTS_DIR/$(dirname $line)
cp $line $RESULTS_DIR/$(dirname $line)
done
- store_test_results:
path: _test_results

- store_artifacts:
path: screenshots

Expand Down
2 changes: 0 additions & 2 deletions .editorconfig

This file was deleted.

52 changes: 29 additions & 23 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ workspace(
},
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

http_archive(
name = "rules_player",
strip_prefix = "rules_player-0.10.3",
urls = ["https://github.com/player-ui/rules_player/archive/refs/tags/v0.10.3.tar.gz"],
sha256 = "a21d0fc7428e124bdc5a068ae68e0625a13f8238e685965268b5ed46f4de23fe"
name = "rules_player",
sha256 = "c015a09ce2a5f999a89473cb9f71346c6831e27830a228ebe8f1ba25e83b77b2",
strip_prefix = "rules_player-0.10.4",
urls = ["https://github.com/player-ui/rules_player/archive/refs/tags/v0.10.4.tar.gz"],
)

load("@rules_player//:workspace.bzl", "deps")
Expand Down Expand Up @@ -66,7 +66,7 @@ kotlin()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()
register_toolchains("//jvm:kotlin_toolchain")

load("@rules_player//junit5:conf.bzl", "junit5")

Expand All @@ -79,33 +79,23 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

grab_remote = "https://github.com/sugarmanz/grab-bazel-common.git"

grab_commit = "a3fe2daf2965b439c8c2a4c2cce1f13beba446b1"
grab_commit = "5326c6ba7a4e39e150c33e123134525473baffb6"

git_repository(
name = "grab_bazel_common",
commit = grab_commit,
remote = grab_remote,
shallow_since = "1654123549 -0400",
shallow_since = "1700536974 -0500",
)

# Optional patched Android Tools
load("@grab_bazel_common//:workspace_defs.bzl", "android_tools")
load("@grab_bazel_common//android:repositories.bzl", "bazel_common_dependencies")

android_tools(
commit = grab_commit,
remote = grab_remote,
shallow_since = "1654123549 -0400",
)
bazel_common_dependencies()

DAGGER_TAG = "2.28.1"
load("@grab_bazel_common//android:initialize.bzl", "bazel_common_initialize")

DAGGER_SHA = "9e69ab2f9a47e0f74e71fe49098bea908c528aa02fa0c5995334447b310d0cdd"

http_archive(
name = "dagger",
sha256 = DAGGER_SHA,
strip_prefix = "dagger-dagger-%s" % DAGGER_TAG,
url = "https://github.com/google/dagger/archive/dagger-%s.zip" % DAGGER_TAG,
bazel_common_initialize(
pinned_maven_install = False,
)

http_archive(
Expand All @@ -119,6 +109,20 @@ load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

ANDROIDX_TEST_VERSION = "1.4.2"

http_file(
name = "android_test_orchestrator_apk",
sha256 = "b7a2e7d0184b03e12c7357f3914d539da40b52a11e90815edff1022c655f459b",
url = "https://dl.google.com/android/maven2/androidx/test/orchestrator/%s/orchestrator-%s.apk" % (ANDROIDX_TEST_VERSION, ANDROIDX_TEST_VERSION),
)

http_file(
name = "android_test_services_apk",
sha256 = "c6bc74268b29bdabad8da962e00e2f6fd613c24b42c69e81b258397b4819f156",
url = "https://dl.google.com/android/maven2/androidx/test/services/test-services/%s/test-services-%s.apk" % (ANDROIDX_TEST_VERSION, ANDROIDX_TEST_VERSION),
)

http_archive(
name = "build_bazel_rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
Expand Down Expand Up @@ -165,6 +169,7 @@ maven_install(
"https://maven.google.com/",
"https://plugins.gradle.org/m2/",
"https://jcenter.bintray.com/",
"https://jitpack.io/",
],
)

Expand All @@ -173,6 +178,7 @@ maven_install(
artifacts = [
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:jar:1.5.2",
],
fetch_sources = True,
repositories = [
"https://repo1.maven.org/maven2",
],
Expand Down
6 changes: 3 additions & 3 deletions android/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def _applitools_config_impl(ctx, **kwargs):
head = [
"package %s;" % ctx.attr.package,
"public object ApplitoolsConfig {",
" public val API_KEY = " + ("\"" + ctx.var["APPLITOOLS_API_KEY"] + "\"" if "APPLITOOLS_API_KEY" in ctx.var else "\"UNSET\""),
" public val BATCH_ID = " + ("\"" + ctx.var["APPLITOOLS_BATCH_ID"] + "\"" if "APPLITOOLS_BATCH_ID" in ctx.var else "\"local\""),
" public val PR_NUMBER = " + ("\"" + ctx.var["APPLITOOLS_PR_NUMBER"] + "\"" if "APPLITOOLS_PR_NUMBER" in ctx.var else "\"UNSET\""),
" public val API_KEY: String? = " + ("\"" + ctx.var["APPLITOOLS_API_KEY"] + "\"" if "APPLITOOLS_API_KEY" in ctx.var else "null"),
" public val BATCH_ID: String = " + ("\"" + ctx.var["APPLITOOLS_BATCH_ID"] + "\"" if "APPLITOOLS_BATCH_ID" in ctx.var else "\"local\""),
" public val PR_NUMBER: String = " + ("\"" + ctx.var["APPLITOOLS_PR_NUMBER"] + "\"" if "APPLITOOLS_PR_NUMBER" in ctx.var else "\"UNSET\""),
]
last = ["}"]
values = ctx.attr.values
Expand Down
3 changes: 3 additions & 0 deletions android/demo/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android_binary(
kt_jvm_import(
name = "kotlinx_coroutines_core_jvm_fixed",
jars = ["@kotlinx_coroutines_core_fixed//:v1/https/repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.2/kotlinx-coroutines-core-jvm-1.5.2.jar"],
srcjar = "@kotlinx_coroutines_core_fixed//:v1/https/repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.2/kotlinx-coroutines-core-jvm-1.5.2-sources.jar",
visibility = ["//visibility:public"],
deps = [
":sun_dependencies_neverlink",
Expand Down Expand Up @@ -86,6 +87,8 @@ sh_test(
data = [
":demo",
":demo_test_app",
"@android_test_orchestrator_apk//file",
"@android_test_services_apk//file",
],
)

Expand Down
5 changes: 4 additions & 1 deletion android/demo/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ maven_main = [
"androidx.navigation:navigation-runtime:%s" % versions.androidx.navigation,
"androidx.navigation:navigation-ui-ktx:%s" % versions.androidx.navigation,
"androidx.navigation:navigation-fragment-ktx:%s" % versions.androidx.navigation,

"androidx.lifecycle:lifecycle-viewmodel-ktx:%s" % versions.androidx.lifecycle,
"androidx.lifecycle:lifecycle-runtime-ktx:%s" % versions.androidx.lifecycle,
"com.afollestad.material-dialogs:core:%s" % versions.material_dialogs,
"com.google.android.material:material:%s" % versions.material,
#"com.squareup.leakcanary:leakcanary-android:2.2",
"com.facebook.stetho:stetho:%s" % versions.facebook.stetho,
"com.github.AlexTrotsenko:j2v8-debugger:%s" % versions.j2v8.debugger,
]

maven_test = [
Expand Down
79 changes: 78 additions & 1 deletion android/demo/scripts/androidtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,84 @@

set -u -e -o pipefail

# Install app to test
adb install android/demo/demo.apk

# Install test app
adb install android/demo/demo_test_app.apk

adb shell am instrument -w com.intuit.player.android.reference.demo.test/androidx.test.runner.AndroidJUnitRunner
DEVICE_API_LEVEL=$(adb shell getprop ro.build.version.sdk)

FORCE_QUERYABLE_OPTION=""
if [[ $DEVICE_API_LEVEL -ge 30 ]]; then
FORCE_QUERYABLE_OPTION="--force-queryable"
fi

# TODO: Hooks up properly to runfiles
cp external/android_test_orchestrator_apk/file/downloaded orchestrator.apk
cp external/android_test_services_apk/file/downloaded test_services.apk

# Install the test orchestrator.
adb install $FORCE_QUERYABLE_OPTION -r orchestrator.apk

# Install test services.
adb install $FORCE_QUERYABLE_OPTION -r test_services.apk

adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0

# Inspiration: https://gist.github.com/swenson/f797ffea7e243d889406#file-runtests-sh

# adb shell throws away the return value, so we have to hack do some magic
# see https://code.google.com/p/android/issues/detail?id=3254

adb logcat -c &&
python - <<END
import os
import re
import subprocess as sp
import sys
import threading
import time
done = False
def update():
while not done:
time.sleep(5)
print "Running..."
# Start idling thread to prevent CI from killing the process for inactivity
t = threading.Thread(target=update)
t.dameon = True
t.start()
# Wait for device and launch tests with Androidx test orchestrator
def run():
os.system('adb wait-for-device')
p = sp.Popen("""adb shell 'CLASSPATH=\$(pm path androidx.test.services) app_process / \
androidx.test.services.shellexecutor.ShellMain am instrument -w -e clearPackageData true \
-e targetInstrumentation com.intuit.player.android.reference.demo.test/androidx.test.runner.AndroidJUnitRunner \
androidx.test.orchestrator/.AndroidTestOrchestrator'""",
shell=True, stdout=sp.PIPE, stderr=sp.PIPE, stdin=sp.PIPE)
return p.communicate()
# Search for JUnit success log
success = re.compile(r'OK \(\d+ test(s)?\)')
stdout, stderr = run()
done = True
print stderr
print stdout
if success.search(stderr + stdout):
sys.exit(0)
else:
sys.exit(1) # make sure we fail if the tests fail
END
RETVAL=$?
adb logcat -d '*:E'

exit $RETVAL
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import com.intuit.player.android.reference.demo.test.base.PerformanceTest
import com.intuit.player.android.reference.demo.test.base.waitForViewInRoot
import com.intuit.player.android.reference.demo.ui.main.MainActivity
import org.hamcrest.Matchers.allOf
import org.junit.Rule
Expand All @@ -18,13 +19,13 @@ class MainActivityTest : PerformanceTest<MainActivity> {

@Test
fun verifyDefault() {
onView(withText("Android Reference Assets"))
waitForViewInRoot(withText("Android Reference Assets"))
.check(matches(isDisplayed()))

onView(
allOf(
withText("Random Mock")
)
withText("Random Mock"),
),
).perform(click())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.intuit.player.android.reference.demo.test
import android.content.Intent
import android.net.Uri
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import com.intuit.player.android.reference.demo.test.base.ApplitoolsTest
import com.intuit.player.android.reference.demo.test.base.waitForViewInRoot
import com.intuit.player.android.reference.demo.ui.splash.SplashActivity
import com.intuit.player.jvm.utils.makeFlow
import org.junit.Rule
Expand All @@ -29,7 +29,7 @@ class SplashActivityTest : ApplitoolsTest() {
"type": "text",
"value": "Deep link test!"
}
""".trimIndent()
""".trimIndent(),
)
}

Expand All @@ -45,6 +45,6 @@ class SplashActivityTest : ApplitoolsTest() {

@Test
fun deepLinkTest() {
onView(withText("Deep link test!")).check(matches(isDisplayed()))
waitForViewInRoot(withText("Deep link test!")).check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package com.intuit.player.android.reference.demo.test.assets.action

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.intuit.player.android.reference.demo.test.base.AssetUITest
import com.intuit.player.android.reference.demo.test.base.shouldBePlayerState
import com.intuit.player.android.reference.demo.test.base.waitForViewInRoot
import com.intuit.player.jvm.core.player.state.CompletedState
import com.intuit.player.jvm.core.player.state.ErrorState
import com.intuit.player.jvm.core.player.state.InProgressState
import com.intuit.player.jvm.core.player.state.dataModel
import org.junit.Assert.assertEquals
import org.junit.Test

class ActionUITest : AssetUITest("action") {
class ActionUITest : AssetUITest("reference-assets") {

@Test
fun basic() {
launchMock()
launchMock("action-basic")

repeat(10) {
onView(withText("Count: $it"))
.check(matches(isDisplayed()))
waitForViewInRoot(withText("Count: $it"))
.perform(click())

eyes.checkPlayer("click $it")
waitForViewInRoot(withText("Count: ${it + 1}"))

eyes?.checkPlayer("click $it")
}

currentState.shouldBePlayerState<InProgressState> {
Expand All @@ -35,9 +36,9 @@ class ActionUITest : AssetUITest("action") {

@Test
fun transitionToEndSuccess() {
launchMock("transition-to-end")
launchMock("action-transition-to-end")

onView(withText("End the flow (success)"))
waitForViewInRoot(withText("End the flow (success)"))
.check(matches(isDisplayed()))
.perform(click())

Expand All @@ -48,9 +49,9 @@ class ActionUITest : AssetUITest("action") {

@Test
fun transitionToEndError() {
launchMock("transition-to-end")
launchMock("action-transition-to-end")

onView(withText("End the flow (error)"))
waitForViewInRoot(withText("End the flow (error)"))
.check(matches(isDisplayed()))
.perform(click())

Expand Down
Loading

0 comments on commit cd3c689

Please sign in to comment.