Hello, not sure if this belongs to js or <#C3PQML5...
# javascript
y
Hello, not sure if this belongs to js or #multiplatform , but will go ahead and ask here So the basic problem I'm trying to solve is to mimic the behaviour of having multiple modules for a target such that each individual 'module' can be built independently - having it's own tests and sources - so that one is working within that particular modules, one runs the test cases only for that module (thus, getting faster iteration cycles) Now, in multiplatform analogy, I believe this would translate to a
sourceSet
. I have configured a
custom sourceSet
as below
Copy code
js {
        browser {}
        nodejs {
            useCommonJs()
        }

        val fooMain  by compilations.creating {
            nodejs {
                useCommonJs()
            }
            defaultSourceSet {
                dependencies {
                    api(kotlin("stdlib-js"))
                    implementation(npm("<some-dependency>","some-version"))
                }
            }
        }

        val fooTest by compilations.creating {
            defaultSourceSet {
                dependsOn(fooMain.defaultSourceSet)
                dependencies {
                    implementation(kotlin("test-js"))
                }
            }
        }

    }
  // Some other config 
  sourceSets {
        val jsMain by getting {
            dependsOn(getByName("fooMain"))
            // some more config
        }
  }
Now, the question is - How do I write a task that 'compiles and runs' the tests written in
fooTest
. The [documentation](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#running-tests) mentions that
Copy code
For Kotlin/JS targets, add kotlin-test-js as a test dependency. At this point, test tasks for Kotlin/JS are created but do not run tests by default; they should be manually configured to run the tests with a JavaScript test framework.
Now, I believe that means configuring a
KotlinJsTest
task that has
useMocha()
configured. However, I am unable to wire up such a task. Can someone please help me out? Also, apologies if this is present somewhere in the documentation - if it is, please direct me to it. If it isn't , please direct me how I can add it once I have the answer 🙂
d
Copy code
val jsTest by getting {
            dependsOn(getByName("fooTest"))
            // some more config
        }
y
Thanks for the reply @Dominaezzz. However, that would basically runn
fooTest
suite when we run the
jsTest
suite (that way,
jsTest
test suite runs the test cases for all js source sets). That is perfectly fine and I had got that working. Is there a way to run only
fooTest
test suite ?
d
Copy code
val jsTest by getting {
                dependencies {
                    implementation(kotlin("test-js"))
                }
        }