From 3ff7e119eb2a853899868d8e64db21170b7f74c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 27 Jul 2024 16:38:42 +0200 Subject: [PATCH 1/3] fix(kotest): Workaround Kotest+KJS crash "TestScope is not installed" See https://gitlab.com/opensavvy/groundwork/prepared/-/issues/59 See https://github.com/kotest/kotest/issues/4077 --- .../src/commonMain/kotlin/PreparedSuite.kt | 9 ++++++--- .../src/jsMain/kotlin/PreparedSuite.js.kt | 19 +++++++++++++++++++ .../src/jvmMain/kotlin/PreparedSuite.jvm.kt | 12 ++++++++++++ .../nativeMain/kotlin/PreparedSuite.native.kt | 12 ++++++++++++ .../wasmJsMain/kotlin/PreparedSuite.wasmJs.kt | 12 ++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 runners/runner-kotest/src/jsMain/kotlin/PreparedSuite.js.kt create mode 100644 runners/runner-kotest/src/jvmMain/kotlin/PreparedSuite.jvm.kt create mode 100644 runners/runner-kotest/src/nativeMain/kotlin/PreparedSuite.native.kt create mode 100644 runners/runner-kotest/src/wasmJsMain/kotlin/PreparedSuite.wasmJs.kt diff --git a/runners/runner-kotest/src/commonMain/kotlin/PreparedSuite.kt b/runners/runner-kotest/src/commonMain/kotlin/PreparedSuite.kt index f400455..1a01903 100644 --- a/runners/runner-kotest/src/commonMain/kotlin/PreparedSuite.kt +++ b/runners/runner-kotest/src/commonMain/kotlin/PreparedSuite.kt @@ -1,16 +1,15 @@ package opensavvy.prepared.runner.kotest -import io.kotest.core.coroutines.coroutineTestScope import io.kotest.core.names.TestName import io.kotest.core.spec.KotestTestScope import io.kotest.core.spec.style.StringSpec +import io.kotest.core.spec.style.scopes.ContainerScope import io.kotest.core.spec.style.scopes.RootScope import io.kotest.core.spec.style.scopes.addTest import io.kotest.core.test.TestType import opensavvy.prepared.suite.SuiteDsl import opensavvy.prepared.suite.TestDsl import opensavvy.prepared.suite.config.* -import opensavvy.prepared.suite.runTestDslSuspend import kotlin.coroutines.CoroutineContext /** @@ -67,11 +66,15 @@ private class NonNestedSuite(private val root: RootScope, private val parentConf ) root.addTest(testName = TestName(name = prefix child name), disabled = false, type = TestType.Test, config = kotestConfig) { - coroutineTestScope.runTestDslSuspend(name, context, config, block) + executeTest(name, context, config, block) } } } +// Workaround to avoid using the coroutine dispatcher on KJS. +// See https://gitlab.com/opensavvy/groundwork/prepared/-/issues/59 +internal expect suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) + /** * Appends [name] at the end of `this`, handling the case where `this` is `null`. */ diff --git a/runners/runner-kotest/src/jsMain/kotlin/PreparedSuite.js.kt b/runners/runner-kotest/src/jsMain/kotlin/PreparedSuite.js.kt new file mode 100644 index 0000000..9381b34 --- /dev/null +++ b/runners/runner-kotest/src/jsMain/kotlin/PreparedSuite.js.kt @@ -0,0 +1,19 @@ +package opensavvy.prepared.runner.kotest + +import io.kotest.core.spec.style.scopes.ContainerScope +import kotlinx.coroutines.await +import opensavvy.prepared.suite.TestDsl +import opensavvy.prepared.suite.config.TestConfig +import opensavvy.prepared.suite.runTestDsl +import kotlin.coroutines.CoroutineContext +import kotlin.js.Promise + +internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) { + // Currently, Kotest is not able to give us access to the Kotlin.Coroutines.Test dispatcher. + // Instead, we create a new coroutine environment and awaits it. + // See https://gitlab.com/opensavvy/groundwork/prepared/-/issues/59 + // See https://github.com/kotest/kotest/issues/4077 + + val promise = runTestDsl(name, context, config, block) as Promise<*> + promise.await() +} diff --git a/runners/runner-kotest/src/jvmMain/kotlin/PreparedSuite.jvm.kt b/runners/runner-kotest/src/jvmMain/kotlin/PreparedSuite.jvm.kt new file mode 100644 index 0000000..b27e238 --- /dev/null +++ b/runners/runner-kotest/src/jvmMain/kotlin/PreparedSuite.jvm.kt @@ -0,0 +1,12 @@ +package opensavvy.prepared.runner.kotest + +import io.kotest.core.coroutines.coroutineTestScope +import io.kotest.core.spec.style.scopes.ContainerScope +import opensavvy.prepared.suite.TestDsl +import opensavvy.prepared.suite.config.TestConfig +import opensavvy.prepared.suite.runTestDslSuspend +import kotlin.coroutines.CoroutineContext + +internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) { + coroutineTestScope.runTestDslSuspend(name, context, config, block) +} diff --git a/runners/runner-kotest/src/nativeMain/kotlin/PreparedSuite.native.kt b/runners/runner-kotest/src/nativeMain/kotlin/PreparedSuite.native.kt new file mode 100644 index 0000000..b27e238 --- /dev/null +++ b/runners/runner-kotest/src/nativeMain/kotlin/PreparedSuite.native.kt @@ -0,0 +1,12 @@ +package opensavvy.prepared.runner.kotest + +import io.kotest.core.coroutines.coroutineTestScope +import io.kotest.core.spec.style.scopes.ContainerScope +import opensavvy.prepared.suite.TestDsl +import opensavvy.prepared.suite.config.TestConfig +import opensavvy.prepared.suite.runTestDslSuspend +import kotlin.coroutines.CoroutineContext + +internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) { + coroutineTestScope.runTestDslSuspend(name, context, config, block) +} diff --git a/runners/runner-kotest/src/wasmJsMain/kotlin/PreparedSuite.wasmJs.kt b/runners/runner-kotest/src/wasmJsMain/kotlin/PreparedSuite.wasmJs.kt new file mode 100644 index 0000000..b27e238 --- /dev/null +++ b/runners/runner-kotest/src/wasmJsMain/kotlin/PreparedSuite.wasmJs.kt @@ -0,0 +1,12 @@ +package opensavvy.prepared.runner.kotest + +import io.kotest.core.coroutines.coroutineTestScope +import io.kotest.core.spec.style.scopes.ContainerScope +import opensavvy.prepared.suite.TestDsl +import opensavvy.prepared.suite.config.TestConfig +import opensavvy.prepared.suite.runTestDslSuspend +import kotlin.coroutines.CoroutineContext + +internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) { + coroutineTestScope.runTestDslSuspend(name, context, config, block) +} -- 2.51.2 From 4f40cd4cef8e6d6ad8efa73af5bccf1bb82eae10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 27 Jul 2024 16:58:37 +0200 Subject: [PATCH 2/3] build(gradle): Add the Kotest plugin to all modules that use Kotest Otherwise, the JS, Native and WASM tests don't run --- compat/compat-arrow/build.gradle.kts | 1 + compat/compat-kotlinx-datetime/build.gradle.kts | 1 + compat/compat-parameterize/build.gradle.kts | 1 + suite/build.gradle.kts | 1 + 4 files changed, 4 insertions(+) diff --git a/compat/compat-arrow/build.gradle.kts b/compat/compat-arrow/build.gradle.kts index da46f75..6ec00f0 100644 --- a/compat/compat-arrow/build.gradle.kts +++ b/compat/compat-arrow/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) + alias(opensavvyConventions.plugins.aligned.kotest) } kotlin { diff --git a/compat/compat-kotlinx-datetime/build.gradle.kts b/compat/compat-kotlinx-datetime/build.gradle.kts index e63b049..1636f51 100644 --- a/compat/compat-kotlinx-datetime/build.gradle.kts +++ b/compat/compat-kotlinx-datetime/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) + alias(opensavvyConventions.plugins.aligned.kotest) } @OptIn(ExperimentalWasmDsl::class) diff --git a/compat/compat-parameterize/build.gradle.kts b/compat/compat-parameterize/build.gradle.kts index f17d79c..8a88efe 100644 --- a/compat/compat-parameterize/build.gradle.kts +++ b/compat/compat-parameterize/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) + alias(opensavvyConventions.plugins.aligned.kotest) } kotlin { diff --git a/suite/build.gradle.kts b/suite/build.gradle.kts index 7e996af..2a1dc05 100644 --- a/suite/build.gradle.kts +++ b/suite/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) + alias(opensavvyConventions.plugins.aligned.kotest) } @OptIn(ExperimentalWasmDsl::class) -- 2.51.2 From 469e1555cd5e5228347d6b64ce47a42d93213a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 27 Jul 2024 17:07:38 +0200 Subject: [PATCH 3/3] upgrade: Kotest 5.9.1 From now on, the Kotest version will be the same as in the OpenSavvy Conventions. Closes https://gitlab.com/opensavvy/groundwork/prepared/-/issues/58 --- gradle/libs.versions.toml | 4 ---- runners/runner-kotest/build.gradle.kts | 5 ++--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cc3f573..86dd8d1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,6 @@ # List of dependencies of the project [versions] -kotest = "5.9.0" # https://github.com/kotest/kotest/releases arrow = "1.2.4" # https://github.com/arrow-kt/arrow/releases kotlinx-coroutines = "1.8.1" # https://github.com/Kotlin/kotlinx.coroutines/releases kotlinx-datetime = "0.5.0" # https://github.com/Kotlin/kotlinx-datetime/releases @@ -15,9 +14,6 @@ ktor = "2.3.11" # https://ktor.io/docs/releases.html#release-detai kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } -kotest-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } -kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } -kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } gradle-testkit = { module = "dev.gradleplugins:gradle-test-kit", version.ref = "gradle-testkit" } arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" } parameterize = { module = "com.benwoodworth.parameterize:parameterize", version.ref = "parameterize" } diff --git a/runners/runner-kotest/build.gradle.kts b/runners/runner-kotest/build.gradle.kts index 695c1ce..b1ce3e2 100644 --- a/runners/runner-kotest/build.gradle.kts +++ b/runners/runner-kotest/build.gradle.kts @@ -36,14 +36,13 @@ kotlin { dependencies { api(projects.suite) - api(libs.kotest.engine) - api(libs.kotest.assertions) + api("io.kotest:kotest-framework-engine:${opensavvyConventions.versions.kotest.get()}") } } val jvmMain by sourceSets.getting { dependencies { - api(libs.kotest.runner.junit5) + api("io.kotest:kotest-runner-junit5:${opensavvyConventions.versions.kotest.get()}") } } } -- 2.51.2