Andrew
Andrew

Reputation: 1109

How to target js with kotlin kotest?

I have been trying to setup kotest in a kotlin multiplatform project. On the kotest starting guide it says to add this dependency to commonTest

implementation 'io.kotest:kotest-framework-engine:$version'

Unfortunately this does not resolve

Could not resolve io.kotest:kotest-framework-engine:4.4.1.
Required by:
    project :**strong text**

If add this dependency just to jvmTest it resolves. I can not find any guides to setup kotest for multiplatform.

Upvotes: 1

Views: 230

Answers (1)

Oliver O.
Oliver O.

Reputation: 721

It appears that kotest does not yet support the Kotlin compiler's IR backend for JS. This is kotest issue 2037. If you configure the LEGACY compiler backend for your JS multiplatform settings, it should work.

Kotest's Quick Start documentation does actually cover multiplatform configuration when you select the rightmost tab ("Multiplatform") in each section.

These are the relevant sections from a build.gradle.kts script which uses kotest with the IR backend on JVM along with the LEGACY backend on JS:

val kotestVersion = "4.4.1"

kotlin {
    jvm("backend") {
        compilations.all {
            kotlinOptions.useIR = true
        }
        withJava()
    }
    js("frontend", LEGACY) {
        browser {
            binaries.executable()
            testTask {
                useKarma {
                    useChromeHeadless()
                    webpackConfig.cssSupport.enabled = true
                }
            }
        }
    }
    sourceSets {
        val commonTest by getting {
            dependencies {
                implementation("io.kotest:kotest-framework-engine:$kotestVersion")
                implementation("io.kotest:kotest-assertions-core:$kotestVersion")
                implementation("io.kotest:kotest-property:$kotestVersion")
            }
        }
        val backendTest by getting {
            dependencies {
                implementation("io.kotest:kotest-runner-junit5:$kotestVersion")
            }
        }
    }
}

tasks {
    // Tests
    withType<Test> {
        useJUnitPlatform()
    }
}

Upvotes: 2

Related Questions