How do I use the <SystemEnvironmentProjectListener...
# kotest
j
How do I use the SystemEnvironmentProjectListener (or really any externally defined project listener) in my project? I found a README that says to do this:
Copy code
class ProjectConfig : AbstractProjectConfig() {

    override fun listeners(): List<TestListener> = listOf(SystemEnvironmentProjectListener("foo", "bar"))

}
but AbstractProjectConfig::listeners is deprecated and the deprecation message, “`Use extensions."` , isn’t the most helpful. I would like to define the listener once for the whole project. * Not a contribution *
e
Try this:
Copy code
object EnvironmentExtension : TestCaseExtension {
   override suspend fun intercept(testCase: TestCase, execute: suspend (TestCase) -> TestResult): TestResult {
      return withEnvironment("" to "") {
         execute(testCase)
      }
   }
}

object ProjectConfig : AbstractProjectConfig() {
   override fun extensions() = listOf(EnvironmentExtension)
}
I can try updating the readme if it works. Perhaps we could also raise an issue about creating a replacement for
SystemEnvironmentProjectListener
j
Lol, I didn’t even realize
extensions
was a function in
AbstractProjectConfig
. I thought when the message said “extensions” it was talking about extensions in the abstract 😅
It looks like a
Listener
is an
Extension
so this might just work, trying now…
e
Ah, convenient 🙂