[Gradle, Js] Use dynamic import to catch exceptions during wasm compilation

This commit is contained in:
Ilya Goncharov
2023-06-08 21:30:23 +02:00
committed by teamcity
parent 9d128c8d0d
commit 90f6c53bf8
2 changed files with 16 additions and 12 deletions
@@ -603,16 +603,18 @@ internal fun createLoadWasm(npmProjectDir: File, file: File): File {
val static = npmProjectDir.resolve("static").also { val static = npmProjectDir.resolve("static").also {
it.mkdirs() it.mkdirs()
} }
val loadJs = static.resolve("load.js") val loadJs = static.resolve("load.mjs")
loadJs.printWriter().use { writer -> loadJs.printWriter().use { writer ->
val relativePath = file.relativeTo(static).invariantSeparatorsPath val relativePath = file.relativeTo(static).invariantSeparatorsPath
writer.println( writer.println(
""" """
import exports from "$relativePath"; import( /* webpackMode: "eager" */ "$relativePath")
.then((exports) => {
exports.startUnitTests(); exports.default.startUnitTests();
window.__karma__.loaded();
window.__karma__.loaded(); }, (reason) => {
window.__karma__.error("Problem with loading", void 0, void 0, void 0, reason)
})
""".trimIndent() """.trimIndent()
) )
} }
@@ -18,17 +18,19 @@ class KotlinKarmaTest {
val loadWasm = createLoadWasm(npmProjectDir.toFile(), executableFile.toFile()) val loadWasm = createLoadWasm(npmProjectDir.toFile(), executableFile.toFile())
assertEquals( assertEquals(
"static/load.js", "static/load.mjs",
loadWasm.relativeTo(npmProjectDir.toFile()).invariantSeparatorsPath loadWasm.relativeTo(npmProjectDir.toFile()).invariantSeparatorsPath
) )
assertEquals( assertEquals(
""" """
import exports from "../kotlin/main.mjs"; import( /* webpackMode: "eager" */ "../kotlin/main.mjs")
.then((exports) => {
exports.startUnitTests(); exports.default.startUnitTests();
window.__karma__.loaded();
window.__karma__.loaded(); }, (reason) => {
window.__karma__.error("Problem with loading", void 0, void 0, void 0, reason)
})
""".trimIndent(), """.trimIndent(),
loadWasm.readText().trimIndent() loadWasm.readText().trimIndent()
) )