Oliver.O
01/16/2023, 12:08 PMAbstractProjectConfig
works in Kotlin/Js (in a standard multiplatform configuration using Karma). My preliminary findings suggest that a BeforeProjectListener
extension works as expected while a `ProjectExtension`'s interceptProject
method is not being invoked. Are there any known limitations? Also, what are the entry points into the Kotest framework on Js?sam
01/16/2023, 1:24 PMOliver.O
01/16/2023, 1:35 PMopen class CommonTestConfiguration(
private val loggingConfiguration: LoggingConfiguration = LoggingConfiguration(::emitViaPrintln)
) : AbstractProjectConfig() {
override fun extensions() =
listOf(
LoggingTestProjectExtension(loggingConfiguration),
DebugTraceTestProjectExtension
)
private class LoggingTestProjectExtension(val loggingConfiguration: LoggingConfiguration) : BeforeProjectListener {
override suspend fun beforeProject() {
loggingConfiguration.activate()
<http://logger.info|logger.info> { "testVariant: $testVariant" }
}
}
private object DebugTraceTestProjectExtension : ProjectExtension, SpecExtension, TestCaseExtension {
override suspend fun interceptProject(context: ProjectContext, callback: suspend (ProjectContext) -> Unit) {
DebugTrace.enabled = true // <- the effect of this one seems to be missed
callback(context)
}
override suspend fun intercept(spec: Spec, execute: suspend (Spec) -> Unit) {
execute(spec) // plus other stuff
}
override suspend fun intercept(testCase: TestCase, execute: suspend (TestCase) -> TestResult): TestResult =
execute(testCase) // plus other stuff
}
}
And this in a Js source set:
object TestConfiguration : CommonTestConfiguration(LoggingConfiguration(::emitViaPrintln))
interceptProject
is missing. Regarding the others, I don't know yet. Still investigating. But thanks for the plugin hint.sam
01/16/2023, 1:37 PMOliver.O
01/16/2023, 1:41 PMsam
01/16/2023, 1:42 PMOliver.O
01/16/2023, 2:06 PMinterceptProject
gets invoked. Actually, it seems to be invoked twice (but that's not an issue at this time). So the root cause of my issue (a global flag in a companion object having an unexpected value) might be unrelated to Kotest. Thanks so much for bearing with me!sam
01/16/2023, 2:07 PMOliver.O
01/16/2023, 4:10 PMoverride suspend fun interceptProject(context: ProjectContext, callback: suspend (ProjectContext) -> Unit) {
val debugTraceEnabledBefore = DebugTrace.enabled
DebugTrace.enabled = true
callback(context)
DebugTrace.enabled = debugTraceEnabledBefore
}
On the JVM, the intercept's callback returns after all tests have completed. On Js, it returns before any test had a chance to run. The same applies to `AbstractProjectConfig`'s afterProject
method. So on Js, the enabled
setting got reset before a single test would run.
Maybe it would be a good idea to harmonize lifecycle methods between different platforms, if feasible. Or at least document the exact order of invocations.sam
01/16/2023, 4:12 PMOliver.O
01/16/2023, 4:12 PMsam
01/16/2023, 4:13 PMOliver.O
01/16/2023, 9:50 PMsam
01/16/2023, 10:22 PM