Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions modules/cli/src/main/scala/scala/cli/commands/run/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
)
}
}
process.onExit().thenApply(_ => if os.exists(jsDest) then os.remove(jsDest))
process.onExit().thenApply(_ => if os.exists(jsDest) then os.remove.all(jsDest))
Right((process, None))
}
}
Expand Down Expand Up @@ -613,7 +613,9 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
esModule = esModule
)
}
process.onExit().thenApply(_ => if os.exists(jsDest) then os.remove(jsDest))
process.onExit().thenApply(_ =>
if os.exists(jsDest) then os.remove.all(jsDest)
)
Right((process, None))
}
}
Expand Down Expand Up @@ -842,7 +844,10 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
noOpt = noOpt,
logger = logger
).map(outputPath => f(outputPath))
finally if os.exists(dest) then os.remove(dest)
// `dest` starts as a file, but `linkJs` replaces it with a directory when the linker emits
// several files (Wasm, or JS module splitting), so a plain `os.remove` would throw
// `DirectoryNotEmptyException` and fail the command after it already succeeded.
finally if os.exists(dest) then os.remove.all(dest)
}

def withNativeLauncher[T](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,26 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
}
}

test("successful test Wasm") {
successfulTestInputs().fromRoot { root =>
// The Wasm backend emits several files (main.js, __loader.js, main.wasm), so the linked
// output is a directory: the command must still exit 0 after cleaning it up.
val output = os.proc(
TestUtil.cli,
"--power",
"test",
extraOptions,
".",
"--js-emit-wasm",
"--js-module-kind",
"es"
)
.call(cwd = root)
.out.text()
expect(output.contains("Hello from tests"))
}
}

test("successful test esmodule import JS") {
successfulESModuleTestInputs.fromRoot { root =>
val output = os.proc(TestUtil.cli, "test", extraOptions, ".", "--js")
Expand Down