I wrote a multiplatform library and publish it to ...
# javascript
r
I wrote a multiplatform library and publish it to maven local. Then I use the library in another KMP project. Everything is ok except cannot run js unit tests in the KMP project. I add my library like the following:
Copy code
sourceSets {
    val commonMain by getting {
      dependencies {
        implementation("com.calculation.multiplatform:MultiplatformBigDecimal:1.0.0-beta6")
      }
    }
    val commonTest by getting {
      dependencies {
        implementation(kotlin("test"))
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
        implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
      }
    }
  }
The ios unit tests and JVM unit tests work well. But when I run js unit tests, I got the following error:
Copy code
Could not determine the dependencies of task ':jsTestPackageJson'.
> Could not resolve all dependencies for configuration ':jsTestNpm'.
   > Could not resolve com.calculation.multiplatform:MultiplatformBigDecimal:1.0.0-beta6.
     Required by:
         project :
      > No matching variant of com.calculation.multiplatform:MultiplatformBigDecimal:1.0.0-beta6 was found. The consumer was configured to find a usage of 'kotlin-runtime' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js', attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but:
I cannot understand the message. Is there anyone who can tell me how can I solve this problem?
g
I guess this lib doesn't provide an export to JS, is this lib open sourced?
b
Both, lib and consumer needs to declare same js backend (ir in this case)
r
It's not open sourced yet.
You mean add @JsExport annotation for every class in my library?
b
JsExport is irrelevant here. It's only needed when you want your compiled code visible to js consumers
g
I think you want to look at the build.gradle of the MultiplatformBigDecimal lib, to get something like that:
Copy code
kotlin { 
  js(IR) {
    browser { ... }
    binaries.library()
  }
(if you can copy just the js part, it could help us to help you)
r
Copy code
js {
        useCommonJs()
        browser()
        testRuns["test"].executionTask.configure {
            useCommonJs()
        }
    }
This is my js part
g
I guess it's related to the missing
binaries.library()
or
binaries.executable()
(doc)
r
Ok, I'm testing
Caused by: org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException: Could not create task ':jsTest'.
Cannot sync with config:
Copy code
js(IR) {
        useCommonJs()
        browser()
        testRuns["test"].executionTask.configure {
            useCommonJs()
        }
        binaries.library()
    }
Oh, worked now, it's because the testRuns config
Remove it
Copy code
js(IR) {
        useCommonJs()
        browser()
        binaries.library()
    }
This works for me
Thanks you guys
👍 1
Another strange thing. Now I can run js unit test in my KMP project. But I just want to run unit tests in BigDecimalTest class. Actually it run tests in other classes
b
Js ir backend does not support selective tests yet
So even if you run a single rest via IDE, all tests are actually executed
If selective tests are a must for you, your only option is to switch to the Legacy backend
r
Get it, thanks so much