[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>() val nodeJsArgs = mutableListOf<String>()
if (debug) { return testFramework!!.createTestExecutionSpec(
nodeJsArgs.add("--inspect-brk") task = this,
} forkOptions = forkOptions,
nodeJsArgs = nodeJsArgs,
return testFramework!!.createTestExecutionSpec(this, forkOptions, nodeJsArgs) debug = debug
)
} }
} }
@@ -15,7 +15,8 @@ interface KotlinJsTestFramework : RequiresNpmDependencies {
fun createTestExecutionSpec( fun createTestExecutionSpec(
task: KotlinJsTest, task: KotlinJsTest,
forkOptions: ProcessForkOptions, forkOptions: ProcessForkOptions,
nodeJsArgs: MutableList<String> nodeJsArgs: MutableList<String>,
debug: Boolean
): TCServiceMessagesTestExecutionSpec ): TCServiceMessagesTestExecutionSpec
override val nodeModulesRequired: Boolean override val nodeModulesRequired: Boolean
@@ -254,7 +254,8 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
override fun createTestExecutionSpec( override fun createTestExecutionSpec(
task: KotlinJsTest, task: KotlinJsTest,
forkOptions: ProcessForkOptions, forkOptions: ProcessForkOptions,
nodeJsArgs: MutableList<String> nodeJsArgs: MutableList<String>,
debug: Boolean
): TCServiceMessagesTestExecutionSpec { ): TCServiceMessagesTestExecutionSpec {
if (config.browsers.isEmpty()) { if (config.browsers.isEmpty()) {
error("No browsers configured for $task") error("No browsers configured for $task")
@@ -40,7 +40,8 @@ class KotlinMocha(override val compilation: KotlinJsCompilation) : KotlinJsTestF
override fun createTestExecutionSpec( override fun createTestExecutionSpec(
task: KotlinJsTest, task: KotlinJsTest,
forkOptions: ProcessForkOptions, forkOptions: ProcessForkOptions,
nodeJsArgs: MutableList<String> nodeJsArgs: MutableList<String>,
debug: Boolean
): TCServiceMessagesTestExecutionSpec { ): TCServiceMessagesTestExecutionSpec {
val clientSettings = TCServiceMessagesClientSettings( val clientSettings = TCServiceMessagesClientSettings(
task.name, task.name,
@@ -59,20 +60,21 @@ class KotlinMocha(override val compilation: KotlinJsCompilation) : KotlinJsTestF
createAdapterJs(task) createAdapterJs(task)
val nodeModules = listOf( val mocha = npmProject.require("mocha/bin/mocha")
"mocha/bin/mocha", val adapter = npmProject.require("./$ADAPTER_NODEJS")
"./$ADAPTER_NODEJS"
)
val args = nodeJsArgs + val args = mutableListOf(mocha).apply {
nodeModules.map { addAll(cliArg("--inspect-brk", debug))
npmProject.require(it) add(adapter)
} + cliArgs.toList() + addAll(cliArgs.toList())
cliArg("--reporter", "kotlin-test-js-runner/mocha-kotlin-reporter.js") + addAll(cliArg("--reporter", "kotlin-test-js-runner/mocha-kotlin-reporter.js"))
cliArg("--timeout", timeout) + addAll(cliArg("--timeout", timeout))
addAll(
cliArg( cliArg(
"-r", "kotlin-test-js-runner/kotlin-nodejs-source-map-support.js" "-r", "kotlin-test-js-runner/kotlin-nodejs-source-map-support.js"
) )
)
}
return TCServiceMessagesTestExecutionSpec( return TCServiceMessagesTestExecutionSpec(
forkOptions, 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> { private fun cliArg(cli: String, value: String?): List<String> {
return value?.let { listOf(cli, it) } ?: emptyList() return value?.let { listOf(cli, it) } ?: emptyList()
} }