Browse Source

[web] [tests] Completely get rid of waitForAnimationFrame in favour of waitForRecompositionComplete

pull/1151/head
Shagen Ogandzhanian 3 years ago
parent
commit
ce606d1c22
  1. 8
      web/benchmark-core/src/jsTest/kotlin/BenchmarkTests.kt
  2. 26
      web/benchmark-core/src/jsTest/kotlin/TestUtils.kt

8
web/benchmark-core/src/jsTest/kotlin/BenchmarkTests.kt

@ -125,15 +125,9 @@ class BenchmarkTests {
repeat(items.size) {
if (it % 10 == 0) items[it] = "${items[it]}-$it"
}
waitForAnimationFrame()
}
repeat(items.size) {
if (it % 10 == 0) items[it] = "${items[it]}-$it"
waitForRecompositionComplete()
}
waitForAnimationFrame()
assertEquals(1000, root.childElementCount)
assertEquals("1", root.children[1]!!.firstChild!!.textContent)
assertEquals("10-10", root.children[10]!!.firstChild!!.textContent)

26
web/benchmark-core/src/jsTest/kotlin/TestUtils.kt

@ -1,36 +1,10 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composition
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.css.selectors.*
import org.jetbrains.compose.web.attributes.*
import org.jetbrains.compose.web.dom.*
import org.jetbrains.compose.web.*
import kotlinx.browser.document
import kotlinx.browser.window
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.promise
import kotlinx.dom.clear
import org.w3c.dom.HTMLElement
import org.w3c.dom.MutationObserver
import org.w3c.dom.MutationObserverInit
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
/* Currently, the recompositionRunner relies on AnimationFrame to run the recomposition and
applyChanges. Therefore we can use this method after updating the state and before making
assertions.
If tests get broken, then DefaultMonotonicFrameClock need to be checked if it still
uses window.requestAnimationFrame */
internal suspend fun waitForAnimationFrame() {
suspendCoroutine<Unit> { continuation ->
window.requestAnimationFrame {
continuation.resume(Unit)
}
}
}
private object MutationObserverOptions : MutationObserverInit {
override var childList: Boolean? = true
override var attributes: Boolean? = true

Loading…
Cancel
Save