[Gradle, JS] Less verbosity for karma parsing

#KT-38109 fixed
This commit is contained in:
Ilya Goncharov
2020-04-14 17:06:41 +03:00
parent df41397a32
commit ee218e9855
5 changed files with 23 additions and 16 deletions
@@ -82,7 +82,7 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
config.loggers = [
{
type: 'kotlin-test-js-runner/tc-log-appender.js',
layout: { type: 'pattern', pattern: '%[%d{DATE}:%p [%c]: %]%m' }
layout: { type: 'pattern', pattern: '%[[%c]: %]%m' }
}
]
""".trimIndent()
@@ -438,24 +438,21 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
private fun parseConsole(text: String, type: String?) {
val result = KARMA_MESSAGE.matchEntire(text)
var actualText = text
if (result != null) {
val launcherMessage = KARMA_LAUNCHER_MESSAGE.matchEntire(text)
val (logLevel, message) = result.destructured
when (logLevel.toLowerCase()) {
if (launcherMessage != null) {
val (message) = launcherMessage.destructured
actualText = message
when (type?.toLowerCase()) {
WARN, ERROR -> {
processFailedBrowsers(text)
}
}
processLogMessage(message, logLevel)
return
}
type?.let { processLogMessage(text, it) }
type?.let { processLogMessage(actualText, it) }
}
private fun processLogMessage(
@@ -559,5 +556,5 @@ private const val INFO = "info"
private const val DEBUG = "debug"
private const val LOG = "log"
private val KARMA_MESSAGE = "^.*\\d{2} \\d{2} \\d{4,} \\d{2}:\\d{2}:\\d{2}.\\d{3}:(ERROR|WARN|INFO|DEBUG|LOG) \\[.*]: ([\\w\\W]*)\$"
private val KARMA_LAUNCHER_MESSAGE = "^.*\\[launcher]: ([\\w\\W]*)\$"
.toRegex()
@@ -57,6 +57,8 @@ tasks {
"karma-debug-runner.js",
"karma-debug-framework.js",
"mocha-kotlin-reporter.js",
"tc-log-appender.js",
"tc-log-error-webpack.js",
"package.json",
"rollup.config.js",
"tsconfig.json",
@@ -14,7 +14,7 @@ export const TEST_END: string
export const TEST_END_NO_DURATION: string
export const BLOCK_OPENED: string
export const BLOCK_CLOSED: string
export const MESSAGE: string
export const TYPED_MESSAGE: string
export function tcEscape(str: string): string
@@ -16,7 +16,6 @@ export const TEST_END_NO_DURATION = `##teamcity[testFinished name='%s' flowId='%
export const BLOCK_OPENED = `##teamcity[blockOpened name='%s' flowId='%s']`
export const BLOCK_CLOSED = `##teamcity[blockClosed name='%s' flowId='%s']`
export const MESSAGE = `##teamcity[message text='%s']`
export const TYPED_MESSAGE = `##teamcity[message text='%s' type='%s']`
/**
@@ -5,13 +5,22 @@
'use strict';
import {formatMessage, MESSAGE} from "./src/teamcity-format"
import {formatMessage, TYPED_MESSAGE} from "./src/teamcity-format"
const consoleLog = console.log.bind(console);
function consoleAppender(layout, timezoneOffset) {
return (loggingEvent) => {
consoleLog(formatMessage(MESSAGE, layout(loggingEvent, timezoneOffset)));
consoleLog(
formatMessage(
TYPED_MESSAGE,
layout(
loggingEvent,
timezoneOffset
),
loggingEvent.level.toString()
)
);
};
}