From a70b3d06e9130d6971f7d730ea877e850e5eeb8d Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Wed, 8 Sep 2021 09:21:03 +0200 Subject: OptIn GlobalScope usages in JS tests --- .../sevenwonders/ui/redux/sagas/SagasFrameworkTest.kt | 13 +++++-------- .../kotlin/org/luxons/sevenwonders/ui/test/TestUtils.kt | 9 +++++++++ .../org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt | 5 ++--- 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/test/TestUtils.kt diff --git a/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFrameworkTest.kt b/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFrameworkTest.kt index 044ba1ef..7471d577 100644 --- a/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFrameworkTest.kt +++ b/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFrameworkTest.kt @@ -1,8 +1,7 @@ package org.luxons.sevenwonders.ui.redux.sagas -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.promise +import kotlinx.coroutines.* +import org.luxons.sevenwonders.ui.test.runSuspendingTest import redux.RAction import redux.Store import redux.WrapperAction @@ -41,8 +40,7 @@ private data class TestRedux( class SagaContextTest { @Test - fun dispatch(): dynamic = GlobalScope.promise { - + fun dispatch() = runSuspendingTest { val redux = configureTestStore(State("initial")) redux.sagas.runSaga { @@ -53,7 +51,7 @@ class SagaContextTest { } @Test - fun next(): dynamic = GlobalScope.promise { + fun next() = runSuspendingTest { val redux = configureTestStore(State("initial")) val job = redux.sagas.launchSaga(this) { @@ -69,8 +67,7 @@ class SagaContextTest { } @Test - fun onEach(): dynamic = GlobalScope.promise { - + fun onEach() = runSuspendingTest { val redux = configureTestStore(State("initial")) val job = redux.sagas.launchSaga(this) { diff --git a/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/test/TestUtils.kt b/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/test/TestUtils.kt new file mode 100644 index 00000000..7e06c572 --- /dev/null +++ b/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/test/TestUtils.kt @@ -0,0 +1,9 @@ +package org.luxons.sevenwonders.ui.test + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.promise + +@OptIn(DelicateCoroutinesApi::class) // OK in JS tests +fun runSuspendingTest(testBody: suspend CoroutineScope.() -> Unit) = GlobalScope.promise { testBody() } diff --git a/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt b/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt index ba43c33f..c605e41c 100644 --- a/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt +++ b/sw-ui/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt @@ -1,15 +1,14 @@ package org.luxons.sevenwonders.ui.utils -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay -import kotlinx.coroutines.promise +import org.luxons.sevenwonders.ui.test.runSuspendingTest import kotlin.test.Test import kotlin.test.assertEquals class CoroutineUtilsTest { @Test - fun awaitFirstTest(): dynamic = GlobalScope.promise { + fun awaitFirstTest() = runSuspendingTest { val s = awaitFirst( { delay(100); "1" }, { delay(200); "2" }, -- cgit