Provide logging through kotlin-test=js-runner
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.testing
|
||||
|
||||
import org.gradle.api.internal.tasks.testing.TestResultProcessor
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClient
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
|
||||
import org.slf4j.Logger
|
||||
|
||||
internal class JSServiceMessagesClient(
|
||||
results: TestResultProcessor,
|
||||
settings: TCServiceMessagesClientSettings,
|
||||
log: Logger
|
||||
) : TCServiceMessagesClient(results, settings, log) {
|
||||
override fun printNonTestOutput(text: String) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
+14
-2
@@ -6,7 +6,9 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.testing.nodejs
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.internal.tasks.testing.TestResultProcessor
|
||||
import org.gradle.process.ProcessForkOptions
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClient
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutionSpec
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
@@ -14,10 +16,12 @@ import org.jetbrains.kotlin.gradle.targets.js.KotlinGradleNpmPackage
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.internal.parseNodeJsStackTraceAsJvm
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.JSServiceMessagesClient
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTestFramework
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinTestRunnerCliArgs
|
||||
import org.jetbrains.kotlin.gradle.testing.IgnoredTestSuites
|
||||
import org.slf4j.Logger
|
||||
|
||||
class KotlinNodeJsTestRunner(override val compilation: KotlinJsCompilation) : KotlinJsTestFramework {
|
||||
val project: Project
|
||||
@@ -63,11 +67,19 @@ class KotlinNodeJsTestRunner(override val compilation: KotlinJsCompilation) : Ko
|
||||
} +
|
||||
cliArgs.toList()
|
||||
|
||||
return TCServiceMessagesTestExecutionSpec(
|
||||
return object : TCServiceMessagesTestExecutionSpec(
|
||||
forkOptions,
|
||||
args,
|
||||
true,
|
||||
clientSettings
|
||||
)
|
||||
) {
|
||||
override fun createClient(testResultProcessor: TestResultProcessor, log: Logger): TCServiceMessagesClient {
|
||||
return JSServiceMessagesClient(
|
||||
testResultProcessor,
|
||||
clientSettings,
|
||||
log
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,8 @@ export function getAdapter(
|
||||
exclude: cliArgsValue.exclude as string[],
|
||||
};
|
||||
|
||||
const teamCity = new TeamCityMessagesFlow(null, (payload) => console.log(payload));
|
||||
const realConsoleLog = console.log;
|
||||
const teamCity = new TeamCityMessagesFlow(null, (payload) => realConsoleLog(payload));
|
||||
|
||||
let runner: KotlinTestRunner = initialAdapter;
|
||||
runner = runWithTeamCityReporter(runner, args.onIgnoredTestSuites, teamCity, hrTimer);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {KotlinTestRunner} from "./KotlinTestRunner";
|
||||
import {TeamCityMessageData, TeamCityMessagesFlow} from "./TeamCityMessagesFlow";
|
||||
import {Timer} from "./Timer";
|
||||
import {format} from "util";
|
||||
|
||||
const kotlin_test = require('kotlin-test');
|
||||
|
||||
@@ -77,7 +78,33 @@ export function runWithTeamCityReporter(
|
||||
const startTime = timer ? timer.start() : null;
|
||||
teamCity.sendMessage('testStarted', withName(name));
|
||||
try {
|
||||
runner.test(name, isIgnored, fn);
|
||||
runner.test(name, isIgnored, () => {
|
||||
const log = (type: string) => function (message?: any, ...optionalParams: any[]) {
|
||||
teamCity.sendMessage(
|
||||
"testStdOut",
|
||||
withName(
|
||||
name,
|
||||
{
|
||||
"out": `[${type}] ${format(message, ...optionalParams)}\n`
|
||||
}
|
||||
)
|
||||
)
|
||||
};
|
||||
|
||||
const logMethods = ['log', 'info', 'warn', 'error', 'debug'];
|
||||
|
||||
const globalConsole = console as unknown as {
|
||||
[method: string]: (message?: any, ...optionalParams: any[]) => void
|
||||
};
|
||||
|
||||
const revertLogMethods = logMethods.map(method => {
|
||||
const realMethod = globalConsole[method];
|
||||
globalConsole[method] = log(method);
|
||||
return () => globalConsole[method] = realMethod
|
||||
});
|
||||
fn();
|
||||
revertLogMethods.forEach(revert => revert());
|
||||
});
|
||||
} catch (e) {
|
||||
const data: TeamCityMessageData = withName(name, {
|
||||
"message": e.message,
|
||||
|
||||
Reference in New Issue
Block a user