Skip to content

Commit

Permalink
Add properties build from sys.props and forkEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-gilles-ultra committed May 13, 2024
1 parent d453d04 commit 2c18b55
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion scalajslib/src/mill/scalajslib/ScalaJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule {
T.testReporter,
TestRunnerUtils.globFilter(globSelectors())
)
val res = TestModule.handleResults(doneMsg, results, T.ctx(), testReportXml())
val res =
TestModule.handleResults(doneMsg, results, T.ctx(), testReportXml(), jsEnvConfig().env)
// Hack to try and let the Node.js subprocess finish streaming it's stdout
// to the JVM. Without this, the stdout can still be streaming when `close()`
// is called, and some of the output is dropped onto the floor.
Expand Down
9 changes: 7 additions & 2 deletions scalajslib/src/mill/scalajslib/api/ScalaJSApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ object ModuleSplitStyle {
implicit val rw: RW[ModuleSplitStyle] = macroRW
}

sealed trait JsEnvConfig
sealed trait JsEnvConfig {
val env: Map[String, String]
}
object JsEnvConfig {
implicit def rwNodeJs: RW[NodeJs] = macroRW
implicit def rwJsDom: RW[JsDom] = macroRW
Expand Down Expand Up @@ -130,7 +132,10 @@ object JsEnvConfig {
*/
final class Selenium private (
val capabilities: Selenium.Capabilities
) extends JsEnvConfig
) extends JsEnvConfig {
override val env: Map[String, String] = Map.empty
}

object Selenium {
implicit def rwCapabilities: RW[Capabilities] = macroRW

Expand Down
33 changes: 28 additions & 5 deletions scalalib/src/mill/scalalib/TestModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,16 @@ trait TestModule
else
try {
val jsonOutput = ujson.read(outputPath.toIO)
val (doneMsg, results) =
val (doneMsg, results) = {
upickle.default.read[(String, Seq[TestResult])](jsonOutput)
TestModule.handleResults(doneMsg, results, T.ctx(), testReportXml())
}
TestModule.handleResults(
doneMsg,
results,
T.ctx(),
testReportXml(),
sys.props.toMap ++ forkEnv()
)
} catch {
case e: Throwable =>
Result.Failure("Test reporting failed: " + e)
Expand Down Expand Up @@ -330,9 +337,10 @@ object TestModule {
doneMsg: String,
results: Seq[TestResult],
ctx: Ctx.Env with Ctx.Dest,
testReportXml: Option[String]
testReportXml: Option[String],
props: Map[String, String] = Map.empty
): Result[(String, Seq[TestResult])] = {
testReportXml.foreach(fileName => genTestXmlReport(results, ctx.dest / fileName))
testReportXml.foreach(fileName => genTestXmlReport(results, ctx.dest / fileName, props))
handleResults(doneMsg, results, Some(ctx))
}

Expand All @@ -344,7 +352,11 @@ object TestModule {
def scalacOptions: T[Seq[String]] = Seq.empty[String]
}

private def genTestXmlReport(results0: Seq[TestResult], out: os.Path): Unit = {
private def genTestXmlReport(
results0: Seq[TestResult],
out: os.Path,
props: Map[String, String]
): Unit = {
val timestamp = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(
LocalDateTime.ofInstant(
Instant.now.truncatedTo(ChronoUnit.SECONDS),
Expand All @@ -354,6 +366,16 @@ object TestModule {
def durationAsString(value: Long) = (value / 1000d).toString
def testcaseName(testResult: TestResult) =
testResult.selector.replace(s"${testResult.fullyQualifiedName}.", "")

def properties: Elem = {
val ps = props.map { case (key, value) =>
<property name={key} value={value}/>
}
<properties>
{ps}
</properties>
}

val suites = results0.groupBy(_.fullyQualifiedName).map { case (fqn, testResults) =>
val cases = testResults.map { testResult =>
val testName = testcaseName(testResult)
Expand All @@ -371,6 +393,7 @@ object TestModule {
skipped={testResults.count(_.status == Status.Skipped.toString).toString}
time={(testResults.map(_.duration).sum / 1000.0).toString}>
timestamp={timestamp}
{properties}
{cases}
</testsuite>
}
Expand Down

0 comments on commit 2c18b55

Please sign in to comment.