[Gradle, JS] Parse karma output to find problem with browser launch
#KT-38109 fixed
This commit is contained in:
+4
@@ -13,6 +13,7 @@ import org.gradle.api.tasks.testing.TestOutputEvent.Destination.StdOut
|
|||||||
import org.gradle.api.tasks.testing.TestResult
|
import org.gradle.api.tasks.testing.TestResult
|
||||||
import org.gradle.api.tasks.testing.TestResult.ResultType.*
|
import org.gradle.api.tasks.testing.TestResult.ResultType.*
|
||||||
import org.gradle.internal.operations.OperationIdentifier
|
import org.gradle.internal.operations.OperationIdentifier
|
||||||
|
import org.gradle.process.internal.ExecHandle
|
||||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||||
import org.jetbrains.kotlin.gradle.testing.KotlinTestFailure
|
import org.jetbrains.kotlin.gradle.testing.KotlinTestFailure
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
@@ -51,6 +52,9 @@ internal open class TCServiceMessagesClient(
|
|||||||
log.error("Failed to parse test process messages: \"$text\"", e)
|
log.error("Failed to parse test process messages: \"$text\"", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal open fun testFailedMessage(execHandle: ExecHandle, exitValue: Int): String =
|
||||||
|
"$execHandle exited with errors (exit code: $exitValue)"
|
||||||
|
|
||||||
override fun serviceMessage(message: ServiceMessage) {
|
override fun serviceMessage(message: ServiceMessage) {
|
||||||
|
|
||||||
// If a user uses TeamCity, this log may be treated by TC as an actual service message.
|
// If a user uses TeamCity, this log may be treated by TC as an actual service message.
|
||||||
|
|||||||
+4
-4
@@ -32,7 +32,7 @@ class TCServiceMessagesTestExecutor(
|
|||||||
val runListeners: MutableList<KotlinTestRunnerListener>,
|
val runListeners: MutableList<KotlinTestRunnerListener>,
|
||||||
val ignoreRunFailures: Boolean
|
val ignoreRunFailures: Boolean
|
||||||
) : TestExecuter<TCServiceMessagesTestExecutionSpec> {
|
) : TestExecuter<TCServiceMessagesTestExecutionSpec> {
|
||||||
var execHandle: ExecHandle? = null
|
lateinit var execHandle: ExecHandle
|
||||||
var outputReaderThread: Thread? = null
|
var outputReaderThread: Thread? = null
|
||||||
var shouldStop = false
|
var shouldStop = false
|
||||||
|
|
||||||
@@ -51,12 +51,12 @@ class TCServiceMessagesTestExecutor(
|
|||||||
|
|
||||||
lateinit var result: ExecResult
|
lateinit var result: ExecResult
|
||||||
client.root(rootOperation) {
|
client.root(rootOperation) {
|
||||||
execHandle!!.start()
|
execHandle.start()
|
||||||
result = execHandle!!.waitForFinish()
|
result = execHandle.waitForFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spec.checkExitCode && result.exitValue != 0) {
|
if (spec.checkExitCode && result.exitValue != 0) {
|
||||||
error("$execHandle exited with errors (exit code: ${result.exitValue})")
|
error(client.testFailedMessage(execHandle, result.exitValue))
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
spec.showSuppressedOutput()
|
spec.showSuppressedOutput()
|
||||||
|
|||||||
+44
@@ -11,6 +11,7 @@ import org.gradle.api.Project
|
|||||||
import org.gradle.api.internal.tasks.testing.TestResultProcessor
|
import org.gradle.api.internal.tasks.testing.TestResultProcessor
|
||||||
import org.gradle.internal.logging.progress.ProgressLogger
|
import org.gradle.internal.logging.progress.ProgressLogger
|
||||||
import org.gradle.process.ProcessForkOptions
|
import org.gradle.process.ProcessForkOptions
|
||||||
|
import org.gradle.process.internal.ExecHandle
|
||||||
import org.jetbrains.kotlin.gradle.internal.operation
|
import org.jetbrains.kotlin.gradle.internal.operation
|
||||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
|
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
|
||||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutionSpec
|
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutionSpec
|
||||||
@@ -409,13 +410,54 @@ 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()
|
||||||
|
|
||||||
override fun printNonTestOutput(text: String) {
|
override fun printNonTestOutput(text: String) {
|
||||||
val value = text.trimEnd()
|
val value = text.trimEnd()
|
||||||
progressLogger.progress(value)
|
progressLogger.progress(value)
|
||||||
|
|
||||||
|
parseConsole(value)
|
||||||
|
|
||||||
super.printNonTestOutput(text)
|
super.printNonTestOutput(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseConsole(text: String) {
|
||||||
|
if (KARMA_PROBLEM.matches(text)) {
|
||||||
|
config.browsers
|
||||||
|
.filter { it in text }
|
||||||
|
.filterNot { it in errorBrowsers }
|
||||||
|
.also {
|
||||||
|
errorBrowsers.addAll(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun testFailedMessage(execHandle: ExecHandle, exitValue: Int): String {
|
||||||
|
if (errorBrowsers.isEmpty()) {
|
||||||
|
return super.testFailedMessage(execHandle, exitValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
val failedBrowsers = errorBrowsers
|
||||||
|
.joinToString("\n") {
|
||||||
|
"- $it"
|
||||||
|
}
|
||||||
|
return """
|
||||||
|
|Errors occurred during launch of browser for testing.
|
||||||
|
|$failedBrowsers
|
||||||
|
|Please make sure that you have installed browsers.
|
||||||
|
|Or change it via
|
||||||
|
|browser {
|
||||||
|
| testTask {
|
||||||
|
| useKarma {
|
||||||
|
| useFirefox()
|
||||||
|
| useChrome()
|
||||||
|
| useSafari()
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
|
|
||||||
override fun processStackTrace(stackTrace: String): String =
|
override fun processStackTrace(stackTrace: String): String =
|
||||||
processKarmaStackTrace(stackTrace)
|
processKarmaStackTrace(stackTrace)
|
||||||
|
|
||||||
@@ -458,3 +500,5 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
|
|||||||
appendln()
|
appendln()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val KARMA_PROBLEM = "(?m)^.*\\d{2} \\d{2} \\d{4,} \\d{2}:\\d{2}:\\d{2}.\\d{3}:(ERROR|WARN) \\[.*]: (.*)\$".toRegex()
|
||||||
Reference in New Issue
Block a user