Browse Source

Moved benchmark tests to a dedicated package

pull/1151/head
Shagen Ogandzhanian 3 years ago
parent
commit
ffc5eaf5b3
  1. 4
      web/benchmark-core/build.gradle.kts
  2. 6
      web/benchmark-core/src/jsTest/kotlin/BenchmarkComposables.kt
  3. 2
      web/benchmark-core/src/jsTest/kotlin/BenchmarkTests.kt
  4. 28
      web/benchmark-core/src/jsTest/kotlin/TestUtils.kt

4
web/benchmark-core/build.gradle.kts

@ -42,9 +42,11 @@ kotlin {
}
}
val BENCHMARKS_PATH = "reports/tests/jsTest/classes/org.jetbrains.compose.web.tests.benchmarks.BenchmarkTests.html"
val printBenchmarkResults by tasks.registering {
doLast {
val report = buildDir.resolve("reports/tests/jsTest/classes/BenchmarkTests.html").readText()
val report = buildDir.resolve(BENCHMARKS_PATH).readText()
val stdout = "#.*;".toRegex().findAll(report).map { it.value }.firstOrNull()
val benchmarks = stdout?.split(";")?.mapNotNull {

6
web/benchmark-core/src/jsTest/kotlin/BenchmarkComposables.kt

@ -1,3 +1,5 @@
package org.jetbrains.compose.web.tests.benchmarks
import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.css.selectors.*
@ -6,7 +8,7 @@ import org.jetbrains.compose.web.dom.*
import org.jetbrains.compose.web.*
@Composable
fun AddItems(count: Int) {
internal fun AddItems(count: Int) {
repeat(count) {
Div {
P {
@ -25,7 +27,7 @@ fun AddItems(count: Int) {
}
@Composable
fun AddItems(list: List<String>) {
internal fun AddItems(list: List<String>) {
list.forEach {
Div {
P {

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

@ -1,3 +1,5 @@
package org.jetbrains.compose.web.tests.benchmarks
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import kotlinx.browser.window

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

@ -1,28 +0,0 @@
import kotlinx.browser.document
import org.w3c.dom.HTMLElement
import org.w3c.dom.MutationObserver
import org.w3c.dom.MutationObserverInit
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
private object MutationObserverOptions : MutationObserverInit {
override var childList: Boolean? = true
override var attributes: Boolean? = true
override var characterData: Boolean? = true
override var subtree: Boolean? = true
override var attributeOldValue: Boolean? = true
}
internal suspend fun waitForChanges(elementId: String) {
waitForChanges(document.getElementById(elementId) as HTMLElement)
}
internal suspend fun waitForChanges(element: HTMLElement) {
suspendCoroutine<Unit> { continuation ->
val observer = MutationObserver { mutations, observer ->
continuation.resume(Unit)
observer.disconnect()
}
observer.observe(element, MutationObserverOptions)
}
}
Loading…
Cancel
Save