rra/ilgonmic/mocha-fail

[Gradle, JS] Use empty adapter to just dry run

[Gradle, JS] Not dry run, but full run

[Gradle, JS] Fix test to be failed without dry run

[Gradle, JS] Not use client twice

[Gradle, JS] Add test on mocha failing

[Gradle, JS] Fail mocha in case of infrastructure problems

Merge-request: KT-MR-5802
Merged-by: Ilya Goncharov <Ilya.Goncharov@jetbrains.com>

^KT-51623 fixed
This commit is contained in:
Ilya Goncharov
2022-03-15 11:18:35 +00:00
committed by Space
parent 41a54241bb
commit c8237cb5e2
7 changed files with 95 additions and 7 deletions
@@ -1109,6 +1109,31 @@ abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean)
}
}
@DisplayName("mocha fails on module not found")
@GradleTest
fun testMochaFailedModuleNotFound(gradleVersion: GradleVersion) {
project("kotlin-js-nodejs-project", gradleVersion) {
projectPath.resolve("src/test/kotlin/Tests.kt").appendText(
"\n" + """
|
|@JsModule("foo")
|@JsNonModule
|external val foo: dynamic
|
|class Tests2 {
| @Test
| fun testHello() {
| foo
| }
|}
""".trimMargin()
)
buildAndFail("nodeTest") {
assertTasksFailed(":nodeTest")
}
}
}
@DisplayName("webpack configuration is valid")
@GradleTest
fun testWebpackConfig(gradleVersion: GradleVersion) {
@@ -20,7 +20,8 @@ open class TCServiceMessagesTestExecutionSpec(
val forkOptions: ProcessForkOptions,
val args: List<String>,
val checkExitCode: Boolean,
val clientSettings: TCServiceMessagesClientSettings
val clientSettings: TCServiceMessagesClientSettings,
val dryRunArgs: List<String>? = null,
) : TestExecutionSpec {
internal open fun createClient(testResultProcessor: TestResultProcessor, log: Logger): TCServiceMessagesClient =
TCServiceMessagesClient(testResultProcessor, clientSettings, log)
@@ -48,6 +49,19 @@ class TCServiceMessagesTestExecutor(
val client = spec.createClient(testResultProcessor, log)
if (spec.dryRunArgs != null) {
val exec = execHandleFactory.newExec()
spec.forkOptions.copyTo(exec)
exec.args = spec.args
execHandle = exec.build()
execHandle.start()
val result: ExecResult = execHandle.waitForFinish()
if (result.exitValue != 0) {
error(client.testFailedMessage(execHandle, result.exitValue))
}
}
try {
val exec = execHandleFactory.newExec()
spec.forkOptions.copyTo(exec)
@@ -79,7 +79,7 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
val file = task.inputFileProperty.get().asFile.toString()
val adapter = createAdapterJs(file)
val adapter = createAdapterJs(file, "kotlin-test-nodejs-runner", ADAPTER_NODEJS)
val args = mutableListOf(
"--require",
@@ -102,11 +102,26 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
}
}
val dryRunArgs = mutableListOf(
"--require",
npmProject.require("source-map-support/register.js")
).apply {
if (debug) {
add("--inspect-brk")
}
add(createAdapterJs(file, "kotlin-test-nodejs-empty-runner", ADAPTER_EMPTY_NODEJS).canonicalPath)
addAll(cliArgs.toList())
if (platformType == KotlinPlatformType.wasm) {
addAll(cliArg("-n", "experimental-wasm-typed-funcref,experimental-wasm-gc,experimental-wasm-eh"))
}
}
return TCServiceMessagesTestExecutionSpec(
forkOptions,
args,
false,
clientSettings
clientSettings,
dryRunArgs
)
}
@@ -115,14 +130,16 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
}
private fun createAdapterJs(
file: String
file: String,
adapter: String,
adapterName: String
): File {
val adapterJs = npmProject.dir.resolve(ADAPTER_NODEJS)
val adapterJs = npmProject.dir.resolve(adapterName)
adapterJs.printWriter().use { writer ->
val adapter = npmProject.require("kotlin-test-js-runner/kotlin-test-nodejs-runner.js")
val adapterFile = npmProject.require("kotlin-test-js-runner/$adapter.js")
val escapedFile = file.jsQuoted()
writer.println("require(${adapter.jsQuoted()})")
writer.println("require(${adapterFile.jsQuoted()})")
writer.println("module.exports = require($escapedFile)")
}
@@ -132,6 +149,7 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
companion object {
const val ADAPTER_NODEJS = "adapter-nodejs.js"
const val ADAPTER_EMPTY_NODEJS = "adapter-empty-nodejs.js"
private const val DEFAULT_TIMEOUT = "2s"
}
@@ -40,6 +40,7 @@ tasks {
inputs.dir("src")
inputs.files(
"nodejs.ts",
"nodejs-empty.ts",
"nodejs-idle.ts",
"karma.ts",
"karma-kotlin-reporter.js",
+5
View File
@@ -0,0 +1,5 @@
import {EmptyKotlinTestRunner} from "./src/EmptyKotlinTestRunner";
(globalThis as any).kotlinTest = {
adapterTransformer: () => new EmptyKotlinTestRunner()
}
@@ -21,6 +21,16 @@ export default [
},
plugins: plugins()
},
{
input: './nodejs-empty.ts',
output: {
file: 'lib/kotlin-test-nodejs-empty-runner.js',
format: 'cjs',
banner: '#!/usr/bin/env node',
sourcemap: true
},
plugins: plugins()
},
{
input: './karma.ts',
output: {
@@ -0,0 +1,15 @@
/*
* Copyright 2010-2022 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 {KotlinTestRunner} from "./KotlinTestRunner";
export class EmptyKotlinTestRunner implements KotlinTestRunner {
suite(name: string, isIgnored: boolean, fn: () => void): void {
}
test(name: string, isIgnored: boolean, fn: () => void): void {
}
}