All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jsTest.io.eqoty.platformTestUtils.kt Maven / Gradle / Ivy

Go to download

A Kotlin multiplatform REST client utilizing secret network's gRPC gateway endpoints.

There is a newer version: 6.4.1-rc
Show newest version
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