Skip to content

Commit df2f4d8

Browse files
authored
Merge pull request #14 from armanbilge/feature/webworker-test-output
Add output for webworker tests
2 parents 254dadb + 574221e commit df2f4d8

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

webworker/src/main/scala/org/scalajs/macrotaskexecutor/MacrotaskExecutorSuiteRunner.scala

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,53 @@ import org.junit.runner.notification.RunNotifier
2323
import org.scalajs.dom.webworkers.DedicatedWorkerGlobalScope
2424

2525
import scala.scalajs.js
26-
import scala.util
2726

2827
object MacrotaskExecutorSuiteRunner {
2928

30-
import MacrotaskExecutor.Implicits._
31-
3229
def postMessage(msg: js.Any): Unit =
3330
DedicatedWorkerGlobalScope.self.postMessage(msg)
3431

35-
def main(args: Array[String]): Unit =
32+
def main(args: Array[String]): Unit = {
3633
new MUnitRunner(
3734
classOf[MacrotaskExecutorSuite],
3835
() => new MacrotaskExecutorSuite
3936
).runAsync(new RunNotifier {
37+
38+
var count = new MacrotaskExecutorSuite().munitTests().size
39+
var overallSuccess = true
40+
def reportTest(success: Boolean): Unit = {
41+
overallSuccess &= success
42+
count -= 1
43+
if (count == 0) postMessage(overallSuccess)
44+
}
45+
4046
def fireTestStarted(description: Description): Unit = ()
41-
def fireTestSuiteStarted(description: Description): Unit = ()
47+
48+
def fireTestSuiteStarted(description: Description): Unit =
49+
postMessage(s"${classOf[MacrotaskExecutorSuite].getName}:")
50+
51+
// This doesn't account for async and fires before any tests are run!
4252
def fireTestSuiteFinished(description: Description): Unit = ()
53+
4354
def fireTestIgnored(description: Description): Unit = ()
44-
def fireTestFinished(description: Description): Unit = ()
45-
def fireTestFailure(failure: Failure): Unit = postMessage(false)
46-
def fireTestAssumptionFailed(failure: Failure): Unit = postMessage(false)
47-
}).onComplete {
48-
case util.Success(_) => postMessage(true)
49-
case util.Failure(_) => postMessage(false)
50-
}
55+
56+
def fireTestFinished(description: Description): Unit = {
57+
postMessage(s" + ${description.getMethodName}")
58+
reportTest(success = true)
59+
}
60+
61+
def fireTestFailure(failure: Failure): Unit = {
62+
postMessage(
63+
s"==> X ${classOf[MacrotaskExecutorSuite].getName}.${failure.description.getMethodName}"
64+
)
65+
reportTest(success = false)
66+
}
67+
68+
def fireTestAssumptionFailed(failure: Failure): Unit =
69+
reportTest(success = false)
70+
71+
})
72+
73+
()
74+
}
5175
}

webworker/src/test/scala/org/scalajs/macrotaskexecutor/WebWorkerMacrotaskSuite.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import scala.util.Try
2626
class WebWorkerMacrotaskSuite extends FunSuite {
2727

2828
import MacrotaskExecutor.Implicits._
29-
29+
3030
def scalaVersion = if (BuildInfo.scalaVersion.startsWith("2"))
3131
BuildInfo.scalaVersion.split("\\.").init.mkString(".")
3232
else
@@ -37,10 +37,12 @@ class WebWorkerMacrotaskSuite extends FunSuite {
3737
Try(js.isUndefined(js.Dynamic.global.window.Worker)).toOption
3838
.filterNot(identity)
3939
.foreach { _ =>
40-
test("macrotask executor should pass the suite on a webworker") {
40+
test("pass the MacrotaskSuite in a web worker") {
4141
val p = Promise[Boolean]()
4242

43-
val worker = new Worker(s"file://${targetDir}/scala-js-macrotask-executor-webworker-fastopt/main.js")
43+
val worker = new Worker(
44+
s"file://${targetDir}/scala-js-macrotask-executor-webworker-fastopt/main.js"
45+
)
4446

4547
worker.onmessage = { event =>
4648
event.data match {

0 commit comments

Comments
 (0)