[Debugger, JS] Provide possibility to debug mocha tests

This commit is contained in:
Ilya Goncharov
2019-11-07 15:18:57 +03:00
parent 30b4622a45
commit 20e33806ec
4 changed files with 27 additions and 18 deletions
@@ -114,10 +114,11 @@ open class KotlinJsTest : KotlinTest(), RequiresNpmDependencies {
val nodeJsArgs = mutableListOf<String>()
if (debug) {
nodeJsArgs.add("--inspect-brk")
}
return testFramework!!.createTestExecutionSpec(this, forkOptions, nodeJsArgs)
return testFramework!!.createTestExecutionSpec(
task = this,
forkOptions = forkOptions,
nodeJsArgs = nodeJsArgs,
debug = debug
)
}
}
@@ -15,7 +15,8 @@ interface KotlinJsTestFramework : RequiresNpmDependencies {
fun createTestExecutionSpec(
task: KotlinJsTest,
forkOptions: ProcessForkOptions,
nodeJsArgs: MutableList<String>
nodeJsArgs: MutableList<String>,
debug: Boolean
): TCServiceMessagesTestExecutionSpec
override val nodeModulesRequired: Boolean
@@ -254,7 +254,8 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
override fun createTestExecutionSpec(
task: KotlinJsTest,
forkOptions: ProcessForkOptions,
nodeJsArgs: MutableList<String>
nodeJsArgs: MutableList<String>,
debug: Boolean
): TCServiceMessagesTestExecutionSpec {
if (config.browsers.isEmpty()) {
error("No browsers configured for $task")
@@ -40,7 +40,8 @@ class KotlinMocha(override val compilation: KotlinJsCompilation) : KotlinJsTestF
override fun createTestExecutionSpec(
task: KotlinJsTest,
forkOptions: ProcessForkOptions,
nodeJsArgs: MutableList<String>
nodeJsArgs: MutableList<String>,
debug: Boolean
): TCServiceMessagesTestExecutionSpec {
val clientSettings = TCServiceMessagesClientSettings(
task.name,
@@ -59,20 +60,21 @@ class KotlinMocha(override val compilation: KotlinJsCompilation) : KotlinJsTestF
createAdapterJs(task)
val nodeModules = listOf(
"mocha/bin/mocha",
"./$ADAPTER_NODEJS"
)
val mocha = npmProject.require("mocha/bin/mocha")
val adapter = npmProject.require("./$ADAPTER_NODEJS")
val args = nodeJsArgs +
nodeModules.map {
npmProject.require(it)
} + cliArgs.toList() +
cliArg("--reporter", "kotlin-test-js-runner/mocha-kotlin-reporter.js") +
cliArg("--timeout", timeout) +
val args = mutableListOf(mocha).apply {
addAll(cliArg("--inspect-brk", debug))
add(adapter)
addAll(cliArgs.toList())
addAll(cliArg("--reporter", "kotlin-test-js-runner/mocha-kotlin-reporter.js"))
addAll(cliArg("--timeout", timeout))
addAll(
cliArg(
"-r", "kotlin-test-js-runner/kotlin-nodejs-source-map-support.js"
)
)
}
return TCServiceMessagesTestExecutionSpec(
forkOptions,
@@ -82,6 +84,10 @@ class KotlinMocha(override val compilation: KotlinJsCompilation) : KotlinJsTestF
)
}
private fun cliArg(cli: String, value: Boolean): List<String> {
return if (value) listOf(cli) else emptyList()
}
private fun cliArg(cli: String, value: String?): List<String> {
return value?.let { listOf(cli, it) } ?: emptyList()
}