So this is similar to Ivan's question, but not qui...
# kotest
m
So this is similar to Ivan's question, but not quite: With kotest 6.1.3, and jsNodeTest, we finally have working gradle
--tests
argument support, and tests get filtered correctly. Thanks! Unfortunately, gradle doesn't seem to detect that jsNodeTest is executing these these tests.
Copy code
> Task :jsNodeTest
FAILURE: Build failed with an exception.
* What went wrong:
No matching tests found in any candidate test task.
    Requested tests:
        Test pattern com.xyz.example.ExampleTest in task :jsNodeTest
For
:cleanJsNodeTest :jsNodeTest --tests 'com.xyz.example.ExampleTest'
(ide-generated target) A hacky workaround is to do something like this:
Copy code
tasks.named<org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest>("jsNodeTest") {
    doFirst {
        var currentClass: Class<*>? = filter.javaClass
        var field: java.lang.reflect.Field? = null

        // Search through the class hierarchy for the commandLineIncludeTestNames field
        while (currentClass != null && field == null) {
            try {
                field = currentClass.getDeclaredField("commandLineIncludeTestNames")
            } catch (_: NoSuchFieldException) {
                currentClass = currentClass.superclass
            }
        }

        if (field != null) {
            field.isAccessible = true
            val patterns = field.get(filter) as? MutableSet<*>
            // Clear the commandLineIncludeTestNames so Gradle doesn't validate test execution
            patterns?.clear()
            println("Cleared command line test patterns to prevent Gradle validation")
        }
    }
}
I've tried reading through the kotest code and reading through gradle's docs on org.gradle.api.tasks.testing.TestListener. It's unclear to me if the problem is that kotest isn't using a TestListener to report test results, whether test listener is supposed to be handled outside of kotest in jsNodeTest but isn't, whether the test names are not coming through with the package prefix (certainly a lot harder to determine in IR), or if perhaps I need to upgrade past kotlin 2.2.21.
s
I believe I know the root cause, I've created this to track. https://github.com/kotest/kotest/issues/5704
Will work on a fix asap for 6.1.4
m
Thanks for the quick fix for this. I was able to verify that --tests gradle command runs fine from the command-line and only fails in the IDE, as you stated in the fix. I'm not entirely certain how to build and deploy a local copy of kotest-framework-plugin-gradle to test the change, and since I have a workaround, I'll report back when 6.1.4 is released.