New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed spec lifecycle ordering for JS #3602
base: master
Are you sure you want to change the base?
Conversation
I have extended your test so that it will additionally cover an extension configured project-wide and case-specific (the latter configured differently, intended to override the project-wide setting) . This currently fails on the Jvm, as the case-specific extension will wrap the project-level extension. Here's the modified code for package com.sksamuel.kotest.engine
import io.kotest.core.extensions.ProjectExtension
import io.kotest.core.extensions.SpecExtension
import io.kotest.core.extensions.TestCaseExtension
import io.kotest.core.project.ProjectContext
import io.kotest.core.spec.Spec
import io.kotest.core.spec.style.FunSpec
import io.kotest.core.test.TestCase
import io.kotest.core.test.TestResult
import io.kotest.engine.TestEngineLauncher
import io.kotest.engine.listener.CollectingTestEngineListener
import io.kotest.matchers.shouldBe
class LifecycleOrderTest : FunSpec() {
init {
test("project, spec and test interceptors should wrap each other") {
val collector = CollectingTestEngineListener()
TestEngineLauncher(collector)
.withClasses(LifecycleTests::class)
.withExtensions(LifecycleExtension("project"))
.launch()
collector.names shouldBe listOf("foo", "bar")
LifecycleExtension.state shouldBe listOf(
Triple("project", Lifecycle.PROJECT, Phase.ENTRY),
Triple("project", Lifecycle.SPEC, Phase.ENTRY),
Triple("project", Lifecycle.TEST_CASE, Phase.ENTRY),
Triple("project", Lifecycle.TEST_CASE, Phase.EXIT),
Triple("project", Lifecycle.TEST_CASE, Phase.ENTRY),
Triple("bar", Lifecycle.TEST_CASE, Phase.ENTRY),
Triple("bar", Lifecycle.TEST_CASE, Phase.EXIT),
Triple("project", Lifecycle.TEST_CASE, Phase.EXIT),
Triple("project", Lifecycle.SPEC, Phase.EXIT),
Triple("project", Lifecycle.PROJECT, Phase.EXIT),
)
}
}
}
private class LifecycleTests : FunSpec() {
init {
test("foo") {}
test("bar").config(extensions = listOf(LifecycleExtension("bar"))) {}
}
}
enum class Lifecycle {
PROJECT,
SPEC,
TEST_CASE
}
enum class Phase {
ENTRY,
EXIT
}
class LifecycleExtension(val name: String) : ProjectExtension, SpecExtension, TestCaseExtension {
companion object {
val state = mutableListOf<Triple<String, Lifecycle, Phase>>()
}
override suspend fun interceptProject(context: ProjectContext, callback: suspend (ProjectContext) -> Unit) {
state.add(Triple(name, Lifecycle.PROJECT, Phase.ENTRY))
callback(context)
state.add(Triple(name, Lifecycle.PROJECT, Phase.EXIT))
}
override suspend fun intercept(spec: Spec, execute: suspend (Spec) -> Unit) {
state.add(Triple(name, Lifecycle.SPEC, Phase.ENTRY))
execute(spec)
state.add(Triple(name, Lifecycle.SPEC, Phase.EXIT))
}
override suspend fun intercept(testCase: TestCase, execute: suspend (TestCase) -> TestResult): TestResult {
state.add(Triple(name, Lifecycle.TEST_CASE, Phase.ENTRY))
val result = execute(testCase)
state.add(Triple(name, Lifecycle.TEST_CASE, Phase.EXIT))
return result
}
} This produces:
|
) The test is actually Sam's work (kotest#3602), which I shamelessly copied and adapted for this issue's purpose.
Can you confirm that this does actually pass on the JVM because I can't get it to fail. |
Took master as of commit c043f69 (plus "Refactor concurrency" PR), ran Then reverted the change of
|
Ok great so my changes to the test executor ended up fixing his too (on JVM). |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Fixes #3340