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