diff options
author | Joffrey Bion <joffrey.bion@gmail.com> | 2021-09-08 09:21:03 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@gmail.com> | 2021-09-08 09:21:03 +0200 |
commit | a70b3d06e9130d6971f7d730ea877e850e5eeb8d (patch) | |
tree | d55ff5f23cf5dc85fadd646fc3db34be344db14b | |
parent | OptIn GlobalScope usage in SagasFramework (diff) | |
download | seven-wonders-a70b3d06e9130d6971f7d730ea877e850e5eeb8d.tar.gz seven-wonders-a70b3d06e9130d6971f7d730ea877e850e5eeb8d.tar.bz2 seven-wonders-a70b3d06e9130d6971f7d730ea877e850e5eeb8d.zip |
OptIn GlobalScope usages in JS tests
3 files changed, 16 insertions, 11 deletions
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" }, |