I use this extra code in the gradle script in the ...
# multiplatform
j
I use this extra code in the gradle script in the new multiplatform project structure to copy also all the dependencies and run the JS tests:
Copy code
task installMocha(type: NpmTask) {
    args = ['install', 'mocha']
}

afterEvaluate {
    // Directory for all js test dependencies
    def testDir = "${buildDir}/jsTest"
    def projectName = name

    // Copy test files
    task copyJsTestOutput(type: Copy, dependsOn: [compileTestKotlinJs]) {
        from compileTestKotlinJs.outputFile.parentFile.path
        include "*.js"
        include "*.js.map"
        into testDir
    }

    // Copy all to be tested code and dependencies
    task copyJsMainOutputAndDependencies(type: Copy, dependsOn: compileKotlinJs) {
        from compileKotlinJs.destinationDir
        configurations.jsTestCompileClasspath.each {
            from(zipTree(it.absolutePath).matching { include '*.js.map'; include '*.js' })
        }

        into("${testDir}/node_modules")
    }

    // Use mocha as the test runner
    task runMocha(type: NodeTask, dependsOn: [copyJsMainOutputAndDependencies, copyJsTestOutput, installMocha]) {
        script = file('node_modules/mocha/bin/mocha')
        args = ["${testDir}/${projectName}_test.js"]
    }

    // Let mocha run when test is run in JS target
    jsTest.dependsOn runMocha
}
👍 1