[Wasm, tests] Cleanup and improvements in wasm test infra
- Remove no longer necessary separate generation to run inside browsers - Generate index.html in DEBUG mode instead of SUPER_DEBUG - Print link to index.html using IDEA builtin server (0.0.0.0:63342) - Small improvements in generated index.html
This commit is contained in:
@@ -173,14 +173,41 @@ abstract class BasicWasmBoxTest(
|
||||
|
||||
val testJs = if (debugMode >= DebugMode.DEBUG) testJsVerbose else testJsQuiet
|
||||
|
||||
fun compileAndRunD8Test(name: String, res: WasmCompilerResult) {
|
||||
fun writeToFilesAndRunD8Test(name: String, res: WasmCompilerResult) {
|
||||
val dir = File(outputDirBase, name)
|
||||
dir.mkdirs()
|
||||
|
||||
if (debugMode >= DebugMode.DEBUG) {
|
||||
val path = dir.absolutePath
|
||||
println(" ------ $name WAT file://$path/index.wat")
|
||||
println(" ------ $name WASM file://$path/index.wasm")
|
||||
println(" ------ $name Wat file://$path/index.wat")
|
||||
println(" ------ $name Wasm file://$path/index.wasm")
|
||||
println(" ------ $name JS file://$path/index.mjs")
|
||||
println(" ------ $name Test file://$path/test.mjs")
|
||||
val projectName = "kotlin"
|
||||
println(" ------ $name HTML http://0.0.0.0:63342/$projectName/${dir.path}/index.html")
|
||||
|
||||
File(dir, "index.html").writeText(
|
||||
"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<span id="test">UNKNOWN</span>
|
||||
<script type="module">
|
||||
let test = document.getElementById("test")
|
||||
try {
|
||||
await import("./test.mjs");
|
||||
test.style.backgroundColor = "#0f0";
|
||||
test.textContent = "OK"
|
||||
} catch(e) {
|
||||
test.style.backgroundColor = "#f00";
|
||||
test.textContent = "NOT OK"
|
||||
throw e;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
writeCompilationResult(res, dir)
|
||||
@@ -196,36 +223,8 @@ abstract class BasicWasmBoxTest(
|
||||
)
|
||||
}
|
||||
|
||||
compileAndRunD8Test("d8", compilerResult)
|
||||
compileAndRunD8Test("d8-dce", compilerResultWithDCE)
|
||||
|
||||
if (debugMode >= DebugMode.SUPER_DEBUG) {
|
||||
fun writeBrowserTest(name: String, res: WasmCompilerResult) {
|
||||
val dir = File(outputDirBase, name)
|
||||
writeCompilationResult(res, dir)
|
||||
File(dir, "test.mjs").writeText(testJsVerbose)
|
||||
File(dir, "index.html").writeText(
|
||||
"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<script src="test.mjs" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
""".trimIndent()
|
||||
)
|
||||
val path = dir.absolutePath
|
||||
println(" ------ $name WAT file://$path/index.wat")
|
||||
println(" ------ $name WASM file://$path/index.wasm")
|
||||
println(" ------ $name JS file://$path/index.mjs")
|
||||
println(" ------ $name TEST file://$path/test.mjs")
|
||||
println(" ------ $name HTML file://$path/index.html")
|
||||
}
|
||||
|
||||
writeBrowserTest("browser", compilerResult)
|
||||
writeBrowserTest("browser-dce", compilerResultWithDCE)
|
||||
}
|
||||
|
||||
writeToFilesAndRunD8Test("d8", compilerResult)
|
||||
writeToFilesAndRunD8Test("d8-dce", compilerResultWithDCE)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user