Skip to content

Commit 1dca9cd

Browse files
merge: Kotest runner fixes
Various fixes and workarounds for the stability of the Kotest runner. See merge request opensavvy/groundwork/prepared!89
2 parents acec075 + 469e155 commit 1dca9cd

File tree

11 files changed

+67
-10
lines changed

11 files changed

+67
-10
lines changed

compat/compat-arrow/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
alias(opensavvyConventions.plugins.base)
33
alias(opensavvyConventions.plugins.kotlin.library)
4+
alias(opensavvyConventions.plugins.aligned.kotest)
45
}
56

67
kotlin {

compat/compat-kotlinx-datetime/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
33
plugins {
44
alias(opensavvyConventions.plugins.base)
55
alias(opensavvyConventions.plugins.kotlin.library)
6+
alias(opensavvyConventions.plugins.aligned.kotest)
67
}
78

89
@OptIn(ExperimentalWasmDsl::class)

compat/compat-parameterize/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
alias(opensavvyConventions.plugins.base)
33
alias(opensavvyConventions.plugins.kotlin.library)
4+
alias(opensavvyConventions.plugins.aligned.kotest)
45
}
56

67
kotlin {

gradle/libs.versions.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# List of dependencies of the project
22

33
[versions]
4-
kotest = "5.9.0" # https://github.com/kotest/kotest/releases
54
arrow = "1.2.4" # https://github.com/arrow-kt/arrow/releases
65
kotlinx-coroutines = "1.8.1" # https://github.com/Kotlin/kotlinx.coroutines/releases
76
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
1514
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
1615
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
1716
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
18-
kotest-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
19-
kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
20-
kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
2117
gradle-testkit = { module = "dev.gradleplugins:gradle-test-kit", version.ref = "gradle-testkit" }
2218
arrow-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
2319
parameterize = { module = "com.benwoodworth.parameterize:parameterize", version.ref = "parameterize" }

runners/runner-kotest/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ kotlin {
3636
dependencies {
3737
api(projects.suite)
3838

39-
api(libs.kotest.engine)
40-
api(libs.kotest.assertions)
39+
api("io.kotest:kotest-framework-engine:${opensavvyConventions.versions.kotest.get()}")
4140
}
4241
}
4342

4443
val jvmMain by sourceSets.getting {
4544
dependencies {
46-
api(libs.kotest.runner.junit5)
45+
api("io.kotest:kotest-runner-junit5:${opensavvyConventions.versions.kotest.get()}")
4746
}
4847
}
4948
}

runners/runner-kotest/src/commonMain/kotlin/PreparedSuite.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package opensavvy.prepared.runner.kotest
22

3-
import io.kotest.core.coroutines.coroutineTestScope
43
import io.kotest.core.names.TestName
54
import io.kotest.core.spec.KotestTestScope
65
import io.kotest.core.spec.style.StringSpec
6+
import io.kotest.core.spec.style.scopes.ContainerScope
77
import io.kotest.core.spec.style.scopes.RootScope
88
import io.kotest.core.spec.style.scopes.addTest
99
import io.kotest.core.test.TestType
1010
import opensavvy.prepared.suite.SuiteDsl
1111
import opensavvy.prepared.suite.TestDsl
1212
import opensavvy.prepared.suite.config.*
13-
import opensavvy.prepared.suite.runTestDslSuspend
1413
import kotlin.coroutines.CoroutineContext
1514

1615
/**
@@ -67,11 +66,15 @@ private class NonNestedSuite(private val root: RootScope, private val parentConf
6766
)
6867

6968
root.addTest(testName = TestName(name = prefix child name), disabled = false, type = TestType.Test, config = kotestConfig) {
70-
coroutineTestScope.runTestDslSuspend(name, context, config, block)
69+
executeTest(name, context, config, block)
7170
}
7271
}
7372
}
7473

74+
// Workaround to avoid using the coroutine dispatcher on KJS.
75+
// See https://gitlab.com/opensavvy/groundwork/prepared/-/issues/59
76+
internal expect suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit)
77+
7578
/**
7679
* Appends [name] at the end of `this`, handling the case where `this` is `null`.
7780
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package opensavvy.prepared.runner.kotest
2+
3+
import io.kotest.core.spec.style.scopes.ContainerScope
4+
import kotlinx.coroutines.await
5+
import opensavvy.prepared.suite.TestDsl
6+
import opensavvy.prepared.suite.config.TestConfig
7+
import opensavvy.prepared.suite.runTestDsl
8+
import kotlin.coroutines.CoroutineContext
9+
import kotlin.js.Promise
10+
11+
internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) {
12+
// Currently, Kotest is not able to give us access to the Kotlin.Coroutines.Test dispatcher.
13+
// Instead, we create a new coroutine environment and awaits it.
14+
// See https://gitlab.com/opensavvy/groundwork/prepared/-/issues/59
15+
// See https://github.com/kotest/kotest/issues/4077
16+
17+
val promise = runTestDsl(name, context, config, block) as Promise<*>
18+
promise.await()
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package opensavvy.prepared.runner.kotest
2+
3+
import io.kotest.core.coroutines.coroutineTestScope
4+
import io.kotest.core.spec.style.scopes.ContainerScope
5+
import opensavvy.prepared.suite.TestDsl
6+
import opensavvy.prepared.suite.config.TestConfig
7+
import opensavvy.prepared.suite.runTestDslSuspend
8+
import kotlin.coroutines.CoroutineContext
9+
10+
internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) {
11+
coroutineTestScope.runTestDslSuspend(name, context, config, block)
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package opensavvy.prepared.runner.kotest
2+
3+
import io.kotest.core.coroutines.coroutineTestScope
4+
import io.kotest.core.spec.style.scopes.ContainerScope
5+
import opensavvy.prepared.suite.TestDsl
6+
import opensavvy.prepared.suite.config.TestConfig
7+
import opensavvy.prepared.suite.runTestDslSuspend
8+
import kotlin.coroutines.CoroutineContext
9+
10+
internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) {
11+
coroutineTestScope.runTestDslSuspend(name, context, config, block)
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package opensavvy.prepared.runner.kotest
2+
3+
import io.kotest.core.coroutines.coroutineTestScope
4+
import io.kotest.core.spec.style.scopes.ContainerScope
5+
import opensavvy.prepared.suite.TestDsl
6+
import opensavvy.prepared.suite.config.TestConfig
7+
import opensavvy.prepared.suite.runTestDslSuspend
8+
import kotlin.coroutines.CoroutineContext
9+
10+
internal actual suspend fun ContainerScope.executeTest(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) {
11+
coroutineTestScope.runTestDslSuspend(name, context, config, block)
12+
}

suite/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
33
plugins {
44
alias(opensavvyConventions.plugins.base)
55
alias(opensavvyConventions.plugins.kotlin.library)
6+
alias(opensavvyConventions.plugins.aligned.kotest)
67
}
78

89
@OptIn(ExperimentalWasmDsl::class)

0 commit comments

Comments
 (0)