[Gradle, JS] Add custom log4js appender for karma

#KT-38109 fixed
This commit is contained in:
Ilya Goncharov
2020-04-09 17:34:57 +03:00
parent f0e033b97c
commit 91a25417f5
3 changed files with 41 additions and 0 deletions
@@ -79,6 +79,9 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
config.plugins = config.plugins || [];
config.plugins.push('karma-*'); // default
config.plugins.push('kotlin-test-js-runner/karma-kotlin-reporter.js');
config.loggers = config.loggers || [];
config.loggers.push({type: 'kotlin-test-js-runner/tc-log-appender.js'});
""".trimIndent()
)
}
@@ -1,3 +1,8 @@
/*
* 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.
*/
import typescript from 'rollup-plugin-typescript2';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
@@ -47,6 +52,13 @@ export default [
format: 'cjs'
}
},
{
input: './tc-log-appender.js',
output: {
file: 'lib/tc-log-appender.js',
format: 'cjs'
}
},
{
input: './mocha-kotlin-reporter.js',
external: ['path', 'util'],
@@ -0,0 +1,26 @@
/*
* 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 {tcEscape} from "./src/teamcity-format"
const consoleLog = console.log.bind(console);
function consoleAppender(layout, timezoneOffset) {
return (loggingEvent) => {
consoleLog(tcEscape(layout(loggingEvent, timezoneOffset)));
};
}
function configure(config, layouts) {
let layout = layouts.colouredLayout;
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return consoleAppender(layout, config.timezoneOffset);
}
module.exports.configure = configure;