Skip to content

Commit

Permalink
[Gradle, JS] Typed message for log type
Browse files Browse the repository at this point in the history
#KT-38109 fixed
#KT-38286 fixed
  • Loading branch information
ilgonmic committed Apr 16, 2020
1 parent dccf670 commit db41c65
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal open class TCServiceMessagesClient(
}
}
is TestSuiteFinished -> close(message.ts, getSuiteName(message))
is Message -> regularText(message.text)
is Message -> printNonTestOutput(message.text, message.attributes["type"])
else -> Unit
}

Expand Down Expand Up @@ -115,7 +115,7 @@ internal open class TCServiceMessagesClient(
afterMessage = false
}

protected open fun printNonTestOutput(text: String) {
protected open fun printNonTestOutput(text: String, type: String? = null) {
print(text)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TCServiceMessagesTestExecutor(
spec.forkOptions.copyTo(exec)
exec.args = spec.args
exec.standardOutput = TCServiceMessageOutputStreamHandler(client, { spec.showSuppressedOutput() }, log)
exec.errorOutput = TCServiceMessageOutputStreamHandler(client, { spec.showSuppressedOutput() }, log)
execHandle = exec.build()

lateinit var result: ExecResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal open class JSServiceMessagesClient(
settings: TCServiceMessagesClientSettings,
log: Logger
) : TCServiceMessagesClient(results, settings, log) {
override fun printNonTestOutput(text: String) {
override fun printNonTestOutput(text: String, type: String?) {
if (log.isDebugEnabled) {
log.debug(text)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
""".trimIndent()
)

//language=ES6
it.appendln(
"""
// noinspection JSUnnecessarySemicolon
;(function(config) {
const tcErrorPlugin = require('kotlin-test-js-runner/tc-log-error-webpack');
config.plugins.push(new tcErrorPlugin(tcErrorPlugin))
})(config);
""".trimIndent()
)

it.appendln(" return config;")
it.appendln("}")
it.appendln()
Expand Down Expand Up @@ -418,15 +429,17 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :

private val failedBrowsers: MutableList<String> = mutableListOf()

override fun printNonTestOutput(text: String) {
override fun printNonTestOutput(text: String, type: String?) {
val value = text.trimEnd()
progressLogger.progress(value)

parseConsole(value)
parseConsole(value, type)
}

private fun parseConsole(text: String) {
private fun parseConsole(text: String, type: String?) {

val result = KARMA_MESSAGE.matchEntire(text)

if (result != null) {

val (logLevel, message) = result.destructured
Expand All @@ -445,8 +458,20 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
INFO, LOG -> log.info(nonColoredMessage)
DEBUG -> log.debug(nonColoredMessage)
}
} else {
super.printNonTestOutput(text)

return
}

val nonColoredText = text.clearAnsiColor()

if (type == "error") {
log.error(nonColoredText)
return
}

if (type == "warn") {
log.warn(nonColoredText)
return
}
}

Expand Down
7 changes: 7 additions & 0 deletions libraries/tools/kotlin-test-js-runner/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export default [
format: 'cjs'
}
},
{
input: './tc-log-error-webpack.js',
output: {
file: 'lib/tc-log-error-webpack.js',
format: 'cjs'
}
},
{
input: './mocha-kotlin-reporter.js',
external: ['path', 'util'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export const MESSAGE: string

export function tcEscape(str: string): string

export function formatMessage(...str: string[]): string
export function formatMessage(type: string, ...str: string[]): string
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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']`

/**
* from teamcity-service-messages
Expand Down
33 changes: 33 additions & 0 deletions libraries/tools/kotlin-test-js-runner/tc-log-error-webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 strict';

import {formatMessage, TYPED_MESSAGE} from "./src/teamcity-format";

const ModuleNotFoundError = require("webpack/lib/ModuleNotFoundError")

class TeamCityErrorPlugin {
apply(compiler) {
compiler.hooks.done.tap('TeamCityErrorPlugin', (stats) => {
stats.compilation.errors.forEach(error => {
if (error instanceof ModuleNotFoundError) {
error.dependencies.forEach(dependency => {
console.error(formatMessage(TYPED_MESSAGE, `Module '${dependency.request}' not found`, 'error'))
})
return
}

console.error(formatMessage(TYPED_MESSAGE, error.message, 'error'))
})

stats.compilation.warnings.forEach(warning => {
console.warn(formatMessage(TYPED_MESSAGE, warning.message, 'warn'))
})
});
}
}

module.exports = TeamCityErrorPlugin;

0 comments on commit db41c65

Please sign in to comment.