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

jsTest.RunTest.kt Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise
import kotlinx.coroutines.withTimeout
import kotlin.js.Promise
import kotlin.time.Duration.Companion.seconds

actual fun  block(body: suspend CoroutineScope.() -> T): dynamic = runTestInternal(block = body)

fun  runTestInternal(
    block: suspend CoroutineScope.() -> T
): Promise {
    val promise = GlobalScope.promise {
        try {
            return@promise withTimeout(10.seconds) {
                block()
            }
        } catch (e: UnsupportedOperationException) {
            println("\r\nunsupported operation, skipping")
            e.printStackTrace()
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return@promise null
    }
    promise.catch {
        if (it !is UnsupportedOperationException) {
            throw it
        }
    }
    return promise
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy