Reputation: 7628
I can use jacoco on the JVM side, but what can I use on the JS side of the Multiplatform project?
Upvotes: 3
Views: 346
Reputation: 905
For now, there are no integrated code coverage tools.
But you can implement it manually using karma.config.d
and https://karma-runner.github.io/0.8/config/coverage.html.
Note: you can do it only with browser
target
How to setup:
Necessary to add dependencies, ideally dev dependencies into test source set, but dev dependencies are possible only since 1.4-M3, so they can be replaced with usual npm
implementation(devNpm("istanbul-instrumenter-loader", "3.0.1"))
implementation(devNpm("karma-coverage-istanbul-reporter", "3.0.3"))
After that create js file in karma.config.d folder in the project folder
;(function(config) { // just IIFE to protect local variabled
const path = require("path") // native Node.JS module
config.reporters.push("coverage-istanbul")
config.plugins.push("karma-coverage-istanbul-reporter")
config.webpack.module.rules.push(
{
test: /\.js$/,
use: {loader: 'istanbul-instrumenter-loader'},
include: [path.resolve(__dirname, '../module-name/kotlin/')] // here is necessary to use module-name in `build/js/packages`
}
)
config.coverageIstanbulReporter = {
reports: ["html"]
}
}(config));
It works with Kotlin code (but honestly report is arguable) but anyway, it provides both statistics for js and Kt files, but for js indicate 0%.
I created a feature request: https://youtrack.jetbrains.com/issue/KT-40460
Update:
The HTML file with results is in build/js/packages/{$module-name}-test/coverage/index.html
. You can run build
or browserTest
task.
NOTE: If you on Windows you have to change include: [path.resolve(__dirname, '../module-name/kotlin/')]
to include: [path.resolve(__dirname, '..\\module-name\\kotlin\\')]
Upvotes: 3