Skip to content

Commit

Permalink
Add test reporter for Kotlin/JS (#3757)
Browse files Browse the repository at this point in the history
This PR adds test reporter for Kotlin/JS. It is based on
[XUnit](https://mochajs.org/#xunit) reporter provided by Mocha - XML
will be generated anyway, irrespective of the `TestModule.testReportXml`
option, because structured output is needed in order to be able to parse
it.

So as a result it will be XML file + test result message, which can be
seen in the tests.

Adding HTML reporter is not yet possible without using 3rd party
packages, because the one provided OOTB by Mocha is [not intended for
CLI usage](https://mochajs.org/#html-reporter).

I also had to modify the `Jvm.runSubprocess` method, so it doesn't throw
if exit code is not 0, but returns result. To comply with the old
behavior, all the old call sites will just call `getOrThrow` on the
result.

This change is needed, because if there is a test failure, `node`
process will exit with code 1, but we still need to process and catching
generic `Exception` is not an option (because maybe it is not because of
the exit code).

Upd: Binary compatibility check now complains that `Jvm.runSubprocess`
has a different return type, but I'm not sure if it should be a problem,
because before it was simply returning `Unit`. But if it is a problem, I
can introduce a new method instead.

---------

Co-authored-by: 0xnm <[email protected]>
Co-authored-by: Li Haoyi <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent ce21980 commit 9bae771
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 95 deletions.
6 changes: 3 additions & 3 deletions example/kotlinlib/web/3-hello-kotlinjs/build.mill
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Kotlin/JS support on Mill is still Work In Progress (WIP). As of time of writing it
// supports Node.js, but lacks support of Browser, Webpack, test runners, reporting, etc.
// supports Node.js, but lacks support of Browser, Webpack, test runners, etc.
//
// The example below demonstrates only the minimal compilation, running, and testing of
// a single Kotlin/JS module using a single third-party dependency. For more details in
Expand All @@ -13,7 +13,7 @@ import mill._, kotlinlib._, kotlinlib.js._
object `package` extends RootModule with KotlinJsModule {
def moduleKind = ModuleKind.ESModule
def kotlinVersion = "1.9.25"
def kotlinJSRunTarget = Some(RunTarget.Node)
def kotlinJsRunTarget = Some(RunTarget.Node)
def ivyDeps = Agg(
ivy"org.jetbrains.kotlinx:kotlinx-html-js:0.11.0",
)
Expand All @@ -33,7 +33,7 @@ Compiling 1 Kotlin sources to .../out/test/compile.dest/classes...
Linking IR to .../out/test/linkBinary.dest/binaries
produce executable: .../out/test/linkBinary.dest/binaries
...
error: ...AssertionFailedError: expected:<"<h1>Hello World Wrong</h1>"> but was:<"<h1>Hello World</h1>...
error: ... expected:<"<h1>Hello World Wrong</h1>"> but was:<"<h1>Hello World</h1>...
...

> cat out/test/linkBinary.dest/binaries/test.js # Generated javascript on disk
Expand Down
2 changes: 1 addition & 1 deletion kotlinlib/src/mill/kotlinlib/KotlinWorkerManagerImpl.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Original code copied from https://github.com/lefou/mill-kotlin
* Original code published under the Apache License Version 2
* Original Copyright 2020-20 24 Tobias Roeser
* Original Copyright 2020-2024 Tobias Roeser
*/
package mill.kotlinlib

Expand Down
Loading

0 comments on commit 9bae771

Please sign in to comment.