[Gradle, JS] Add debugger.js with debugger statement to stop on the first line in a browser
^KT-56488 fixed
This commit is contained in:
committed by
Space Team
parent
c82b4f6fe5
commit
bea80f8b54
+26
-5
@@ -24,9 +24,12 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||||
import org.jetbrains.kotlin.gradle.plugin.internal.MppTestReportHelper
|
import org.jetbrains.kotlin.gradle.plugin.internal.MppTestReportHelper
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.*
|
import org.jetbrains.kotlin.gradle.targets.js.NpmPackageVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.appendConfigsFromDir
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.WebpackRulesDsl.Companion.webpackRulesContainer
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.WebpackRulesDsl.Companion.webpackRulesContainer
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.internal.parseNodeJsStackTraceAsJvm
|
import org.jetbrains.kotlin.gradle.targets.js.internal.parseNodeJsStackTraceAsJvm
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.jsQuoted
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.testing.*
|
import org.jetbrains.kotlin.gradle.targets.js.testing.*
|
||||||
@@ -36,6 +39,7 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion.Compan
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
||||||
import org.jetbrains.kotlin.gradle.testing.internal.reportsDir
|
import org.jetbrains.kotlin.gradle.testing.internal.reportsDir
|
||||||
import org.jetbrains.kotlin.gradle.utils.appendLine
|
import org.jetbrains.kotlin.gradle.utils.appendLine
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isParentOf
|
||||||
import org.jetbrains.kotlin.gradle.utils.property
|
import org.jetbrains.kotlin.gradle.utils.property
|
||||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
@@ -54,6 +58,7 @@ class KotlinKarma(
|
|||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val nodeRootPackageDir by lazy { nodeJs.rootPackageDir }
|
private val nodeRootPackageDir by lazy { nodeJs.rootPackageDir }
|
||||||
private val versions = nodeJs.versions
|
private val versions = nodeJs.versions
|
||||||
|
private val nodeModulesCacheDir = nodeJs.nodeModulesGradleCacheDir
|
||||||
|
|
||||||
private val config: KarmaConfig = KarmaConfig()
|
private val config: KarmaConfig = KarmaConfig()
|
||||||
private val requiredDependencies = mutableSetOf<RequiredKotlinJsDependency>()
|
private val requiredDependencies = mutableSetOf<RequiredKotlinJsDependency>()
|
||||||
@@ -369,11 +374,13 @@ class KotlinKarma(
|
|||||||
val file = task.inputFileProperty.get().asFile.toString()
|
val file = task.inputFileProperty.get().asFile.toString()
|
||||||
|
|
||||||
config.files.add(npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js"))
|
config.files.add(npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js"))
|
||||||
config.files.add(file)
|
if (!debug) {
|
||||||
|
config.files.add(file)
|
||||||
if (debug) {
|
} else {
|
||||||
config.singleRun = false
|
config.singleRun = false
|
||||||
|
|
||||||
|
config.files.add(createDebuggerJs(file).normalize().absolutePath)
|
||||||
|
|
||||||
confJsWriters.add {
|
confJsWriters.add {
|
||||||
//language=ES6
|
//language=ES6
|
||||||
it.appendLine(
|
it.appendLine(
|
||||||
@@ -383,7 +390,7 @@ class KotlinKarma(
|
|||||||
config.plugins.push('karma-*'); // default
|
config.plugins.push('karma-*'); // default
|
||||||
}
|
}
|
||||||
|
|
||||||
config.plugins.push('kotlin-test-js-runner/karma-debug-framework.js');
|
config.plugins.push('kotlin-test-js-runner/karma-kotlin-debug-plugin.js');
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -589,6 +596,20 @@ class KotlinKarma(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createDebuggerJs(
|
||||||
|
file: String,
|
||||||
|
): File {
|
||||||
|
val adapterJs = npmProject.dir.resolve("debugger.js")
|
||||||
|
adapterJs.printWriter().use { writer ->
|
||||||
|
// It is necessary for debugger attaching (--inspect-brk analogue)
|
||||||
|
writer.println("debugger;")
|
||||||
|
|
||||||
|
writer.println("module.exports = require(${file.jsQuoted()})")
|
||||||
|
}
|
||||||
|
|
||||||
|
return adapterJs
|
||||||
|
}
|
||||||
|
|
||||||
private fun Appendable.appendFromConfigDir() {
|
private fun Appendable.appendFromConfigDir() {
|
||||||
if (!configDirectory.isDirectory) {
|
if (!configDirectory.isDirectory) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ tasks {
|
|||||||
"nodejs-idle.ts",
|
"nodejs-idle.ts",
|
||||||
"karma.ts",
|
"karma.ts",
|
||||||
"karma-kotlin-reporter.js",
|
"karma-kotlin-reporter.js",
|
||||||
|
"karma-kotlin-debug-plugin.js",
|
||||||
"karma-debug-runner.js",
|
"karma-debug-runner.js",
|
||||||
"karma-debug-framework.js",
|
"karma-debug-framework.js",
|
||||||
"mocha-kotlin-reporter.js",
|
"mocha-kotlin-reporter.js",
|
||||||
|
|||||||
@@ -31,6 +31,4 @@ function configureTimeouts(injector) {
|
|||||||
|
|
||||||
initDebug.$inject = ['injector'];
|
initDebug.$inject = ['injector'];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = initDebug;
|
||||||
'framework:karma-kotlin-debug': ['factory', initDebug]
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
'framework:karma-kotlin-debug': ['factory', require("./karma-debug-framework")],
|
||||||
|
};
|
||||||
@@ -40,6 +40,13 @@ export default [
|
|||||||
},
|
},
|
||||||
plugins: plugins()
|
plugins: plugins()
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: './karma-kotlin-debug-plugin.js',
|
||||||
|
output: {
|
||||||
|
file: 'lib/karma-kotlin-debug-plugin.js',
|
||||||
|
format: 'esm'
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: './karma-debug-runner.js',
|
input: './karma-debug-runner.js',
|
||||||
output: {
|
output: {
|
||||||
|
|||||||
Reference in New Issue
Block a user