jsTest.io.eqoty.platformTestUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client Show documentation
Show all versions of client Show documentation
A Kotlin multiplatform REST client utilizing secret network's gRPC gateway endpoints.
package io.eqoty
import io.eqoty.secretk.crypto.createWindowBroadcaster
import io.eqoty.secretk.crypto.destroyWindowBroadcaster
import io.eqoty.secretk.crypto.windowIsSetup
import jslibs.happydom.GlobalRegistrator
import kotlinx.browser.window
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
fun setupFakeWindow() {
GlobalRegistrator.register()
val crypto = js("""require('@peculiar/webcrypto');""")
window.asDynamic().crypto = js("""new crypto.Crypto();""")
}
fun destroyFakeWindow() {
window.asDynamic().crypto = null
GlobalRegistrator.unregister()
}
var isFirstRunAndNoWindow = !windowIsSetup.value
actual suspend fun platformBeforeEach() {
if (isFirstRunAndNoWindow) {
isFirstRunAndNoWindow = false
MainScope().launch {
createWindowBroadcaster.collect {
setupFakeWindow()
windowIsSetup.emit(true)
}
}
MainScope().launch {
destroyWindowBroadcaster.collect {
destroyFakeWindow()
windowIsSetup.value = false
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy