[Gradle, JS] Add debugger; only for debug mode

This commit is contained in:
Ilya Goncharov
2019-11-19 13:31:58 +03:00
parent 4d3698313d
commit c2b53dfce7
@@ -127,8 +127,6 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
} }
private fun useWebpack() { private fun useWebpack() {
createAdapterJs()
requiredDependencies.add(versions.karmaWebpack) requiredDependencies.add(versions.karmaWebpack)
requiredDependencies.add(versions.webpack) requiredDependencies.add(versions.webpack)
@@ -228,25 +226,26 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
} }
} }
private fun createAdapterJs() { private fun createAdapterJs(
configurators.add { file: String,
val npmProject = compilation.npmProject debug: Boolean
val file = it.nodeModulesToLoad ): File {
.map { npmProject.require(it) } val npmProject = compilation.npmProject
.single()
val adapterJs = npmProject.dir.resolve("adapter-browser.js") val adapterJs = npmProject.dir.resolve("adapter-browser.js")
adapterJs.printWriter().use { writer -> adapterJs.printWriter().use { writer ->
val karmaRunner = npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js") val karmaRunner = npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js")
// It is necessary for debugger attaching (--inspect-brk analogue) // It is necessary for debugger attaching (--inspect-brk analogue)
if (debug) {
writer.println("debugger;") writer.println("debugger;")
writer.println("require(${karmaRunner.jsQuoted()})")
writer.println("module.exports = require(${file.jsQuoted()})")
} }
config.files.add(adapterJs.canonicalPath) writer.println("require(${karmaRunner.jsQuoted()})")
writer.println("module.exports = require(${file.jsQuoted()})")
} }
return adapterJs
} }
override fun createTestExecutionSpec( override fun createTestExecutionSpec(
@@ -255,6 +254,16 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
nodeJsArgs: MutableList<String>, nodeJsArgs: MutableList<String>,
debug: Boolean debug: Boolean
): TCServiceMessagesTestExecutionSpec { ): TCServiceMessagesTestExecutionSpec {
val npmProject = compilation.npmProject
val file = task.nodeModulesToLoad
.map { npmProject.require(it) }
.single()
val adapterJs = createAdapterJs(file, debug)
config.files.add(adapterJs.canonicalPath)
if (debug) { if (debug) {
config.singleRun = false config.singleRun = false
@@ -287,8 +296,6 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
ignoreOutOfRootNodes = true ignoreOutOfRootNodes = true
) )
val npmProject = compilation.npmProject
config.basePath = npmProject.nodeModulesDir.absolutePath config.basePath = npmProject.nodeModulesDir.absolutePath
configurators.forEach { configurators.forEach {