Gradle, js, karma: source maps support
#KT-31478 #KT-31011 #KT-30573
This commit is contained in:
+1
@@ -38,6 +38,7 @@ class NpmVersions {
|
||||
val karmaWebpack = NpmPackageVersion("karma-webpack", "*")
|
||||
val karmaCoverage = NpmPackageVersion("karma-coverage", "*")
|
||||
|
||||
val karmaSourceMapLoader = NpmPackageVersion("karma-sourcemap-loader", "*")
|
||||
val karmaSourceMapSupport = NpmPackageVersion("karma-source-map-support", "1.4.0")
|
||||
|
||||
val kotlinNodeJsTestRunner = KotlinGradleNpmPackage("test-nodejs-runner")
|
||||
|
||||
-1
@@ -34,7 +34,6 @@ class KotlinNodeJs(target: KotlinJsTarget) :
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
runTask.dependsOn(target.project.nodeJs.root.npmResolveTask, compileKotlinTask)
|
||||
|
||||
val npmProject = compilation.npmProject
|
||||
runTask.args(compileKotlinTask.outputFile)
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.targets.js.testing
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.SkipWhenEmpty
|
||||
import org.gradle.process.internal.DefaultProcessForkOptions
|
||||
@@ -22,6 +23,7 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.karma.KotlinKarma
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.mocha.KotlinMocha
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.nodejs.KotlinNodeJsTestRunner
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
||||
import java.io.File
|
||||
|
||||
open class KotlinJsTest : KotlinTest(), RequiresNpmDependencies {
|
||||
@Internal
|
||||
@@ -37,6 +39,9 @@ open class KotlinJsTest : KotlinTest(), RequiresNpmDependencies {
|
||||
@Internal
|
||||
override lateinit var compilation: KotlinJsCompilation
|
||||
|
||||
val entry: File
|
||||
@InputFile get() = compilation.compileKotlinTask.outputFile
|
||||
|
||||
val compilationId: String
|
||||
@Input get() = compilation.let {
|
||||
val target = it.target
|
||||
|
||||
+16
-6
@@ -55,8 +55,10 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
||||
useTeamcityReporter()
|
||||
useMocha()
|
||||
useWebpack()
|
||||
useSourceMapSupport()
|
||||
|
||||
config.singleRun = true
|
||||
config.autoWatch = false
|
||||
}
|
||||
|
||||
private fun useTeamcityReporter() {
|
||||
@@ -64,6 +66,11 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
||||
config.reporters.add("teamcity")
|
||||
}
|
||||
|
||||
internal fun watch() {
|
||||
config.singleRun = false
|
||||
config.autoWatch = true
|
||||
}
|
||||
|
||||
fun useConfigDirectory(dir: File) {
|
||||
configDirectory = dir
|
||||
}
|
||||
@@ -157,11 +164,13 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
||||
}
|
||||
|
||||
fun useSourceMapSupport() {
|
||||
config.frameworks.add("source-map-support")
|
||||
requiredDependencies.add(versions.karmaSourceMapSupport)
|
||||
|
||||
requiredDependencies.add(versions.karmaSourceMapLoader)
|
||||
sourceMaps = true
|
||||
addPreprocessor("sourcemap")
|
||||
|
||||
// stacktraces with sourcemaps
|
||||
requiredDependencies.add(versions.karmaSourceMapSupport)
|
||||
config.frameworks.add("source-map-support")
|
||||
}
|
||||
|
||||
private fun addPreprocessor(name: String, predicate: (String) -> Boolean = { true }) {
|
||||
@@ -219,7 +228,7 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
||||
|
||||
val args = nodeJsArgs +
|
||||
nodeModules.map { npmProject.require(it) } +
|
||||
listOf("start", karmaConfJs.absolutePath)
|
||||
listOf("start", karmaConfJs.absolutePath, "--debug")
|
||||
|
||||
return object : TCServiceMessagesTestExecutionSpec(
|
||||
forkOptions,
|
||||
@@ -244,8 +253,9 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
||||
override fun createClient(testResultProcessor: TestResultProcessor, log: Logger) =
|
||||
object : TCServiceMessagesClient(testResultProcessor, clientSettings, log) {
|
||||
override fun printNonTestOutput(actualText: String) {
|
||||
suppressedOutput.appendln(actualText)
|
||||
progressLogger.progress(actualText)
|
||||
val value = actualText.trimEnd()
|
||||
suppressedOutput.appendln(value)
|
||||
progressLogger.progress(value)
|
||||
}
|
||||
|
||||
val baseTestNameSuffix get() = settings.testNameSuffix
|
||||
|
||||
+6
@@ -13,6 +13,7 @@ class KarmaConfig {
|
||||
val files: MutableList<String> = mutableListOf()
|
||||
val frameworks: MutableList<String> = mutableListOf()
|
||||
val browsers: MutableList<String> = mutableListOf()
|
||||
val customLaunchers: MutableMap<String, CustomLauncher> = mutableMapOf()
|
||||
val reporters: MutableList<String> = mutableListOf()
|
||||
val preprocessors: MutableMap<String, MutableList<String>> = mutableMapOf()
|
||||
var coverageReporter: CoverageReporter? = null
|
||||
@@ -35,6 +36,11 @@ class KarmaConfig {
|
||||
}
|
||||
}
|
||||
|
||||
class CustomLauncher(var base: String) {
|
||||
val flags = mutableListOf<String>()
|
||||
var debug: Boolean? = null
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "KarmaConfig(singleRun=$singleRun, autoWatch=$autoWatch, basePath=$basePath, files=$files, frameworks=$frameworks, browsers=$browsers, reporters=$reporters, preprocessors=$preprocessors, coverageReporter=$coverageReporter)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user