[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.ResultType.*
|
||||
import org.gradle.internal.operations.OperationIdentifier
|
||||
import org.gradle.process.internal.ExecHandle
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.testing.KotlinTestFailure
|
||||
import org.slf4j.Logger
|
||||
@@ -51,6 +52,9 @@ internal open class TCServiceMessagesClient(
|
||||
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) {
|
||||
|
||||
// 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 ignoreRunFailures: Boolean
|
||||
) : TestExecuter<TCServiceMessagesTestExecutionSpec> {
|
||||
var execHandle: ExecHandle? = null
|
||||
lateinit var execHandle: ExecHandle
|
||||
var outputReaderThread: Thread? = null
|
||||
var shouldStop = false
|
||||
|
||||
@@ -51,12 +51,12 @@ class TCServiceMessagesTestExecutor(
|
||||
|
||||
lateinit var result: ExecResult
|
||||
client.root(rootOperation) {
|
||||
execHandle!!.start()
|
||||
result = execHandle!!.waitForFinish()
|
||||
execHandle.start()
|
||||
result = execHandle.waitForFinish()
|
||||
}
|
||||
|
||||
if (spec.checkExitCode && result.exitValue != 0) {
|
||||
error("$execHandle exited with errors (exit code: ${result.exitValue})")
|
||||
error(client.testFailedMessage(execHandle, result.exitValue))
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
spec.showSuppressedOutput()
|
||||
|
||||
+44
@@ -11,6 +11,7 @@ import org.gradle.api.Project
|
||||
import org.gradle.api.internal.tasks.testing.TestResultProcessor
|
||||
import org.gradle.internal.logging.progress.ProgressLogger
|
||||
import org.gradle.process.ProcessForkOptions
|
||||
import org.gradle.process.internal.ExecHandle
|
||||
import org.jetbrains.kotlin.gradle.internal.operation
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutionSpec
|
||||
@@ -409,13 +410,54 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
|
||||
val baseTestNameSuffix get() = settings.testNameSuffix
|
||||
override var testNameSuffix: String? = baseTestNameSuffix
|
||||
|
||||
private val errorBrowsers: MutableList<String> = mutableListOf()
|
||||
|
||||
override fun printNonTestOutput(text: String) {
|
||||
val value = text.trimEnd()
|
||||
progressLogger.progress(value)
|
||||
|
||||
parseConsole(value)
|
||||
|
||||
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 =
|
||||
processKarmaStackTrace(stackTrace)
|
||||
|
||||
@@ -458,3 +500,5 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
|
||||
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