Skip to content

Commit

Permalink
[Gradle, JS] Add custom log4js appender for karma
Browse files Browse the repository at this point in the history
#KT-38109 fixed
  • Loading branch information
ilgonmic committed Apr 16, 2020
1 parent f0e033b commit 91a2541
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
Expand Down
12 changes: 12 additions & 0 deletions libraries/tools/kotlin-test-js-runner/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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'],
Expand Down
26 changes: 26 additions & 0 deletions libraries/tools/kotlin-test-js-runner/tc-log-appender.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 91a2541

Please sign in to comment.