[Wasm] Use named imports in test-loader, runUnitTests generating into static dir
KT-65777
This commit is contained in:
committed by
Space Team
parent
c07781326b
commit
c3a0a41524
+11
-15
@@ -5,14 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.testing
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.Directory
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.process.ProcessForkOptions
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutionSpec
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutor
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.addWasmExperimentalArguments
|
||||
import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootPlugin
|
||||
@@ -21,21 +18,19 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.writeWasmUnitTestRunner
|
||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||
import java.nio.file.Path
|
||||
|
||||
internal class KotlinWasmD8(private val kotlinJsTest: KotlinJsTest) : KotlinJsTestFramework {
|
||||
internal class KotlinWasmD8(kotlinJsTest: KotlinJsTest) : KotlinJsTestFramework {
|
||||
override val settingsState: String = "KotlinWasmD8"
|
||||
|
||||
private val testPath = kotlinJsTest.path
|
||||
|
||||
@Transient
|
||||
override val compilation: KotlinJsIrCompilation = kotlinJsTest.compilation
|
||||
@Transient
|
||||
private val project: Project = compilation.target.project
|
||||
|
||||
private val d8 = D8RootPlugin.apply(project.rootProject)
|
||||
private val d8Executable by project.provider { d8.requireConfigured().executable }
|
||||
private val npmProjectDir by project.provider { compilation.npmProject.dir }
|
||||
private val d8 = D8RootPlugin.apply(kotlinJsTest.project.rootProject)
|
||||
private val d8Executable by kotlinJsTest.project.provider { d8.requireConfigured().executable }
|
||||
|
||||
override val workingDir: Provider<Directory>
|
||||
get() = npmProjectDir
|
||||
override val workingDir: Provider<Directory> = compilation.npmProject.dir
|
||||
|
||||
override fun createTestExecutionSpec(
|
||||
task: KotlinJsTest,
|
||||
@@ -43,10 +38,11 @@ internal class KotlinWasmD8(private val kotlinJsTest: KotlinJsTest) : KotlinJsTe
|
||||
nodeJsArgs: MutableList<String>,
|
||||
debug: Boolean
|
||||
): TCServiceMessagesTestExecutionSpec {
|
||||
val testRunnerFile = writeWasmUnitTestRunner(task.inputFileProperty.get().asFile)
|
||||
val compiledFile = task.inputFileProperty.get().asFile
|
||||
val testRunnerFile = writeWasmUnitTestRunner(workingDir.get().asFile, compiledFile)
|
||||
|
||||
forkOptions.executable = d8Executable
|
||||
forkOptions.workingDir = testRunnerFile.parentFile
|
||||
forkOptions.workingDir = compiledFile.parentFile
|
||||
|
||||
val clientSettings = TCServiceMessagesClientSettings(
|
||||
task.name,
|
||||
@@ -80,5 +76,5 @@ internal class KotlinWasmD8(private val kotlinJsTest: KotlinJsTest) : KotlinJsTe
|
||||
|
||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> = emptySet()
|
||||
|
||||
override fun getPath(): String = "${kotlinJsTest.path}:kotlinTestFrameworkStub"
|
||||
override fun getPath(): String = "$testPath:kotlinTestFrameworkStub"
|
||||
}
|
||||
+15
-25
@@ -5,13 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.testing
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.Directory
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.process.ProcessForkOptions
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutionSpec
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutor
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.addWasmExperimentalArguments
|
||||
@@ -20,41 +18,33 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.writeWasmUnitTestRunner
|
||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||
import org.jetbrains.kotlin.gradle.utils.providerWithLazyConvention
|
||||
import java.nio.file.Path
|
||||
|
||||
internal class KotlinWasmNode(private val kotlinJsTest: KotlinJsTest) : KotlinJsTestFramework {
|
||||
internal class KotlinWasmNode(kotlinJsTest: KotlinJsTest) : KotlinJsTestFramework {
|
||||
override val settingsState: String = "KotlinWasmNode"
|
||||
|
||||
private val testPath = kotlinJsTest.path
|
||||
|
||||
@Transient
|
||||
override val compilation: KotlinJsIrCompilation = kotlinJsTest.compilation
|
||||
|
||||
@Transient
|
||||
private val target: KotlinJsIrTarget = compilation.target as KotlinJsIrTarget
|
||||
private val projectLayout = kotlinJsTest.project.layout
|
||||
|
||||
@Transient
|
||||
private val project: Project = target.project
|
||||
|
||||
private val projectLayout = project.layout
|
||||
|
||||
private val npmProjectDir by project.provider { compilation.npmProject.dir }
|
||||
|
||||
private val wasmTargetType: KotlinWasmTargetType? = target.wasmTargetType
|
||||
|
||||
override val workingDir: Provider<Directory>
|
||||
get() = if (wasmTargetType != KotlinWasmTargetType.WASI) {
|
||||
npmProjectDir
|
||||
} else {
|
||||
projectLayout.dir(kotlinJsTest.inputFileProperty.asFile.map { it.parentFile })
|
||||
override val workingDir: Provider<Directory> =
|
||||
(compilation.target as KotlinJsIrTarget).wasmTargetType.let { wasmTargetType ->
|
||||
if (wasmTargetType != KotlinWasmTargetType.WASI) {
|
||||
compilation.npmProject.dir
|
||||
} else {
|
||||
projectLayout.dir(kotlinJsTest.inputFileProperty.asFile.map { it.parentFile })
|
||||
}
|
||||
}
|
||||
|
||||
override fun createTestExecutionSpec(
|
||||
task: KotlinJsTest,
|
||||
forkOptions: ProcessForkOptions,
|
||||
nodeJsArgs: MutableList<String>,
|
||||
debug: Boolean
|
||||
debug: Boolean,
|
||||
): TCServiceMessagesTestExecutionSpec {
|
||||
val testRunnerFile = writeWasmUnitTestRunner(task.inputFileProperty.get().asFile)
|
||||
val testRunnerFile = writeWasmUnitTestRunner(workingDir.get().asFile.parentFile, task.inputFileProperty.get().asFile)
|
||||
|
||||
val clientSettings = TCServiceMessagesClientSettings(
|
||||
task.name,
|
||||
@@ -87,5 +77,5 @@ internal class KotlinWasmNode(private val kotlinJsTest: KotlinJsTest) : KotlinJs
|
||||
|
||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> = emptySet()
|
||||
|
||||
override fun getPath(): String = "${kotlinJsTest.path}:kotlinTestFrameworkStub"
|
||||
override fun getPath(): String = "$testPath:kotlinTestFrameworkStub"
|
||||
}
|
||||
+7
-7
@@ -624,13 +624,13 @@ internal fun createLoadWasm(npmProjectDir: File, file: File): File {
|
||||
val relativePath = file.relativeTo(static).invariantSeparatorsPath
|
||||
writer.println(
|
||||
"""
|
||||
import( /* webpackMode: "eager" */ "$relativePath")
|
||||
.then((exports) => {
|
||||
exports.default.startUnitTests();
|
||||
window.__karma__.loaded();
|
||||
}, (reason) => {
|
||||
window.__karma__.error("Problem with loading", void 0, void 0, void 0, reason)
|
||||
})
|
||||
import { startUnitTests } from "$relativePath"
|
||||
try {
|
||||
startUnitTests()
|
||||
window.__karma__.loaded();
|
||||
} catch (e) {
|
||||
window.__karma__.error("Problem with loading", void 0, void 0, void 0, e)
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
+8
-4
@@ -65,12 +65,16 @@ const val JS_MAP = "js.map"
|
||||
const val META_JS = "meta.js"
|
||||
const val HTML = "html"
|
||||
|
||||
internal fun writeWasmUnitTestRunner(compiledFile: File): File {
|
||||
val testRunnerFile = compiledFile.parentFile.resolve("runUnitTests.mjs")
|
||||
internal fun writeWasmUnitTestRunner(workingDir: File, compiledFile: File): File {
|
||||
val static = workingDir.resolve("static").also {
|
||||
it.mkdirs()
|
||||
}
|
||||
|
||||
val testRunnerFile = static.resolve("runUnitTests.mjs")
|
||||
testRunnerFile.writeText(
|
||||
"""
|
||||
import { startUnitTests } from './${compiledFile.name}';
|
||||
startUnitTests?.();
|
||||
import { startUnitTests } from './${compiledFile.relativeTo(static).invariantSeparatorsPath}';
|
||||
startUnitTests();
|
||||
""".trimIndent()
|
||||
)
|
||||
return testRunnerFile
|
||||
|
||||
+7
-7
@@ -24,13 +24,13 @@ class KotlinKarmaTest {
|
||||
|
||||
assertEquals(
|
||||
"""
|
||||
import( /* webpackMode: "eager" */ "../kotlin/main.mjs")
|
||||
.then((exports) => {
|
||||
exports.default.startUnitTests();
|
||||
window.__karma__.loaded();
|
||||
}, (reason) => {
|
||||
window.__karma__.error("Problem with loading", void 0, void 0, void 0, reason)
|
||||
})
|
||||
import { startUnitTests } from "../kotlin/main.mjs"
|
||||
try {
|
||||
startUnitTests()
|
||||
window.__karma__.loaded();
|
||||
} catch (e) {
|
||||
window.__karma__.error("Problem with loading", void 0, void 0, void 0, e)
|
||||
}
|
||||
""".trimIndent(),
|
||||
loadWasm.readText().trimIndent()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user