[Gradle, JS] Process Karma messages to Gradle log
#KT-38109 fixed
This commit is contained in:
+51
-13
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.testing.karma
|
package org.jetbrains.kotlin.gradle.targets.js.testing.karma
|
||||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.*
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
||||||
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.clearAnsiColor
|
||||||
import org.jetbrains.kotlin.gradle.utils.property
|
import org.jetbrains.kotlin.gradle.utils.property
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -410,7 +411,7 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
|
|||||||
val baseTestNameSuffix get() = settings.testNameSuffix
|
val baseTestNameSuffix get() = settings.testNameSuffix
|
||||||
override var testNameSuffix: String? = baseTestNameSuffix
|
override var testNameSuffix: String? = baseTestNameSuffix
|
||||||
|
|
||||||
private val errorBrowsers: MutableList<String> = mutableListOf()
|
private val failedBrowsers: MutableList<String> = mutableListOf()
|
||||||
|
|
||||||
override fun printNonTestOutput(text: String) {
|
override fun printNonTestOutput(text: String) {
|
||||||
val value = text.trimEnd()
|
val value = text.trimEnd()
|
||||||
@@ -418,26 +419,54 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
|
|||||||
|
|
||||||
parseConsole(value)
|
parseConsole(value)
|
||||||
|
|
||||||
super.printNonTestOutput(text)
|
if (log.isDebugEnabled) {
|
||||||
|
super.printNonTestOutput(text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseConsole(text: String) {
|
private fun parseConsole(text: String) {
|
||||||
if (KARMA_PROBLEM.matches(text)) {
|
val result = KARMA_MESSAGE.matchEntire(text)
|
||||||
config.browsers
|
if (result != null) {
|
||||||
.filter { it in text }
|
|
||||||
.filterNot { it in errorBrowsers }
|
val (logLevel, message) = result.destructured
|
||||||
.also {
|
|
||||||
errorBrowsers.addAll(it)
|
val nonColoredMessage = message.clearAnsiColor()
|
||||||
|
|
||||||
|
when (logLevel) {
|
||||||
|
WARN -> {
|
||||||
|
processFailedBrowsers(text)
|
||||||
|
log.warn(nonColoredMessage)
|
||||||
}
|
}
|
||||||
|
ERROR -> {
|
||||||
|
processFailedBrowsers(text)
|
||||||
|
log.error(nonColoredMessage)
|
||||||
|
}
|
||||||
|
INFO, LOG -> log.info(nonColoredMessage)
|
||||||
|
DEBUG -> log.debug(nonColoredMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// To provide additional information from Karma
|
||||||
|
if (SET_ENV_VAR.matches(text.trim())) {
|
||||||
|
log.error(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun processFailedBrowsers(text: String) {
|
||||||
|
config.browsers
|
||||||
|
.filter { it in text }
|
||||||
|
.filterNot { it in failedBrowsers }
|
||||||
|
.also {
|
||||||
|
failedBrowsers.addAll(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun testFailedMessage(execHandle: ExecHandle, exitValue: Int): String {
|
override fun testFailedMessage(execHandle: ExecHandle, exitValue: Int): String {
|
||||||
if (errorBrowsers.isEmpty()) {
|
if (failedBrowsers.isEmpty()) {
|
||||||
return super.testFailedMessage(execHandle, exitValue)
|
return super.testFailedMessage(execHandle, exitValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
val failedBrowsers = errorBrowsers
|
val failedBrowsers = failedBrowsers
|
||||||
.joinToString("\n") {
|
.joinToString("\n") {
|
||||||
"- $it"
|
"- $it"
|
||||||
}
|
}
|
||||||
@@ -501,4 +530,13 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val KARMA_PROBLEM = "(?m)^.*\\d{2} \\d{2} \\d{4,} \\d{2}:\\d{2}:\\d{2}.\\d{3}:(ERROR|WARN) \\[.*]: (.*)\$".toRegex()
|
private const val ERROR = "ERROR"
|
||||||
|
private const val WARN = "WARN"
|
||||||
|
private const val INFO = "INFO"
|
||||||
|
private const val DEBUG = "DEBUG"
|
||||||
|
private const val LOG = "LOG"
|
||||||
|
|
||||||
|
private val KARMA_MESSAGE = "(?m)^.*\\d{2} \\d{2} \\d{4,} \\d{2}:\\d{2}:\\d{2}.\\d{3}:($ERROR|$WARN|$INFO|$DEBUG|$LOG) \\[.*]: (.*)\$"
|
||||||
|
.toRegex()
|
||||||
|
|
||||||
|
private val SET_ENV_VAR = "Please, set \"\\w+\" env variable.".toRegex()
|
||||||
+6
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2020 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -27,3 +27,8 @@ private val invalidTaskNameCharacters = "[/\\\\:<>\"?*|]".toRegex()
|
|||||||
* Replaces characters which are not allowed in Gradle task names (/, \, :, <, >, ", ?, *, |) with '_'
|
* Replaces characters which are not allowed in Gradle task names (/, \, :, <, >, ", ?, *, |) with '_'
|
||||||
*/
|
*/
|
||||||
internal fun String.asValidTaskName() = replace(invalidTaskNameCharacters, "_")
|
internal fun String.asValidTaskName() = replace(invalidTaskNameCharacters, "_")
|
||||||
|
|
||||||
|
private val ANSI_COLOR_REGEX = "\\x1b\\[[0-9;]*m".toRegex()
|
||||||
|
|
||||||
|
internal fun String.clearAnsiColor() =
|
||||||
|
replace(ANSI_COLOR_REGEX, "")
|
||||||
Reference in New Issue
Block a user