-
Notifications
You must be signed in to change notification settings - Fork 89
Adopt ComposeUiTest API changes #2066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -78,13 +78,4 @@ internal class ComposeRootRegistry : PlatformContext.RootForTestListener { | |||
fun getComposeRoots(): Set<PlatformRootForTest> { | |||
return synchronized(lock) { roots.toSet() } | |||
} | |||
|
|||
fun <R> withRegistry(block: () -> R): R { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some exaplanation here:
calling withRegistry
and passing a block withkotlinx.coroutines.test.runTest
call is not correct for web - because kotlinx.coroutines.test.runTest
returns immediately.
So I split the logic from this function:
- setupRegistry is called before the scene is created and before calling
kotlinx.coroutines.test.runTest
- tearDownRegistry is called inside of
kotlinx.coroutines.test.runTest
block (in finally)
block: suspend SkikoComposeUiTest.() -> Unit | ||
): TestResult { | ||
composeRootRegistry.setupRegistry() | ||
scene = runOnUiThread(::createUi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some explanation:
Creating the scene manually instead of using withScene {
.
We need an effectContext
of the recomposer to be passed to the runTestContext, so with the current structure of classes, the scene must be created before we run kotlinx.coroutines.test.runTest(
. See combinedCoroutineContext
.
This requirement is ensured by this test:
Line 203 in 1e12cea
fun runTestContextMustHaveMonotonicFrameClock() = runComposeUiTest { |
Note: the failing test on web (androidx.compose.ui.input.TextInputTests.compositeInputWebkit[wasmJs, browser, Chrome135.0.0.0, Linuxx86_64]) doesn't use the ComposeUiTest API. |
...se/ui/ui-test/src/skikoTest/kotlin/androidx/compose/ui/test/ComposeUiTestTestCopyFromAosp.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComplexApplicationTest.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test-junit4/src/desktopTest/kotlin/androidx/compose/ui/test/ComposeUiTestTest.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test-junit4/src/desktopTest/kotlin/androidx/compose/ui/test/ComposeUiTestTest.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/ComposeUiTest.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/ComposeUiTest.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/ComposeUiTest.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test/src/desktopMain/kotlin/androidx/compose/ui/test/ComposeUiTest.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/ComposeUiTest.skiko.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test-junit4/src/desktopTest/kotlin/androidx/compose/ui/test/ComposeUiTestTest.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui-test/src/skikoMain/kotlin/androidx/compose/ui/test/ComposeUiTest.skiko.kt
Show resolved
Hide resolved
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/BaseComposeScene.skiko.kt
Show resolved
Hide resolved
package androidx.compose.ui.test | ||
|
||
@OptionalExpectation | ||
expect annotation class IgnoreWebTest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Let's use the same pattern between modules. Let's have separate annotations for each build target (IgnoreJs + IgnoreWasm) and just apply both where required.
But it's minor, so up to you "Web" in name is descriptive enough
The corresponding CL - https://android-review.googlesource.com/c/platform/frameworks/support/+/3509670
Note: API changes here only in the experimental API.
Fixes https://youtrack.jetbrains.com/issue/CMP-7994/
Testing
Added a copy of relevant tests from AOSP.
Release Notes
Features - Multiple Platforms
ComposeUiTest
API. Theblock
inrunComposeUiTest
issuspend
now. It allows to callawaitIdle
and other suspend functions. It ensures a correct execution of a test on all platforms. See the web specifics inkotlinx.coroutines.test.runTest
documentation.