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:
+25
@@ -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")
|
@DisplayName("webpack configuration is valid")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testWebpackConfig(gradleVersion: GradleVersion) {
|
fun testWebpackConfig(gradleVersion: GradleVersion) {
|
||||||
|
|||||||
+15
-1
@@ -20,7 +20,8 @@ open class TCServiceMessagesTestExecutionSpec(
|
|||||||
val forkOptions: ProcessForkOptions,
|
val forkOptions: ProcessForkOptions,
|
||||||
val args: List<String>,
|
val args: List<String>,
|
||||||
val checkExitCode: Boolean,
|
val checkExitCode: Boolean,
|
||||||
val clientSettings: TCServiceMessagesClientSettings
|
val clientSettings: TCServiceMessagesClientSettings,
|
||||||
|
val dryRunArgs: List<String>? = null,
|
||||||
) : TestExecutionSpec {
|
) : TestExecutionSpec {
|
||||||
internal open fun createClient(testResultProcessor: TestResultProcessor, log: Logger): TCServiceMessagesClient =
|
internal open fun createClient(testResultProcessor: TestResultProcessor, log: Logger): TCServiceMessagesClient =
|
||||||
TCServiceMessagesClient(testResultProcessor, clientSettings, log)
|
TCServiceMessagesClient(testResultProcessor, clientSettings, log)
|
||||||
@@ -48,6 +49,19 @@ class TCServiceMessagesTestExecutor(
|
|||||||
|
|
||||||
val client = spec.createClient(testResultProcessor, log)
|
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 {
|
try {
|
||||||
val exec = execHandleFactory.newExec()
|
val exec = execHandleFactory.newExec()
|
||||||
spec.forkOptions.copyTo(exec)
|
spec.forkOptions.copyTo(exec)
|
||||||
|
|||||||
+24
-6
@@ -79,7 +79,7 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
|
|||||||
|
|
||||||
val file = task.inputFileProperty.get().asFile.toString()
|
val file = task.inputFileProperty.get().asFile.toString()
|
||||||
|
|
||||||
val adapter = createAdapterJs(file)
|
val adapter = createAdapterJs(file, "kotlin-test-nodejs-runner", ADAPTER_NODEJS)
|
||||||
|
|
||||||
val args = mutableListOf(
|
val args = mutableListOf(
|
||||||
"--require",
|
"--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(
|
return TCServiceMessagesTestExecutionSpec(
|
||||||
forkOptions,
|
forkOptions,
|
||||||
args,
|
args,
|
||||||
false,
|
false,
|
||||||
clientSettings
|
clientSettings,
|
||||||
|
dryRunArgs
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,14 +130,16 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createAdapterJs(
|
private fun createAdapterJs(
|
||||||
file: String
|
file: String,
|
||||||
|
adapter: String,
|
||||||
|
adapterName: String
|
||||||
): File {
|
): File {
|
||||||
val adapterJs = npmProject.dir.resolve(ADAPTER_NODEJS)
|
val adapterJs = npmProject.dir.resolve(adapterName)
|
||||||
adapterJs.printWriter().use { writer ->
|
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()
|
val escapedFile = file.jsQuoted()
|
||||||
|
|
||||||
writer.println("require(${adapter.jsQuoted()})")
|
writer.println("require(${adapterFile.jsQuoted()})")
|
||||||
|
|
||||||
writer.println("module.exports = require($escapedFile)")
|
writer.println("module.exports = require($escapedFile)")
|
||||||
}
|
}
|
||||||
@@ -132,6 +149,7 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ADAPTER_NODEJS = "adapter-nodejs.js"
|
const val ADAPTER_NODEJS = "adapter-nodejs.js"
|
||||||
|
const val ADAPTER_EMPTY_NODEJS = "adapter-empty-nodejs.js"
|
||||||
|
|
||||||
private const val DEFAULT_TIMEOUT = "2s"
|
private const val DEFAULT_TIMEOUT = "2s"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ tasks {
|
|||||||
inputs.dir("src")
|
inputs.dir("src")
|
||||||
inputs.files(
|
inputs.files(
|
||||||
"nodejs.ts",
|
"nodejs.ts",
|
||||||
|
"nodejs-empty.ts",
|
||||||
"nodejs-idle.ts",
|
"nodejs-idle.ts",
|
||||||
"karma.ts",
|
"karma.ts",
|
||||||
"karma-kotlin-reporter.js",
|
"karma-kotlin-reporter.js",
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import {EmptyKotlinTestRunner} from "./src/EmptyKotlinTestRunner";
|
||||||
|
|
||||||
|
(globalThis as any).kotlinTest = {
|
||||||
|
adapterTransformer: () => new EmptyKotlinTestRunner()
|
||||||
|
}
|
||||||
@@ -21,6 +21,16 @@ export default [
|
|||||||
},
|
},
|
||||||
plugins: plugins()
|
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',
|
input: './karma.ts',
|
||||||
output: {
|
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 {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user