Skip to content

Add output for webworker tests #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 7, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,53 @@ import org.junit.runner.notification.RunNotifier
import org.scalajs.dom.webworkers.DedicatedWorkerGlobalScope

import scala.scalajs.js
import scala.util

object MacrotaskExecutorSuiteRunner {

import MacrotaskExecutor.Implicits._

def postMessage(msg: js.Any): Unit =
DedicatedWorkerGlobalScope.self.postMessage(msg)

def main(args: Array[String]): Unit =
def main(args: Array[String]): Unit = {
new MUnitRunner(
classOf[MacrotaskExecutorSuite],
() => new MacrotaskExecutorSuite
).runAsync(new RunNotifier {

var count = new MacrotaskExecutorSuite().munitTests().size
var overallSuccess = true
def reportTest(success: Boolean): Unit = {
overallSuccess &= success
count -= 1
if (count == 0) postMessage(overallSuccess)
}

def fireTestStarted(description: Description): Unit = ()
def fireTestSuiteStarted(description: Description): Unit = ()

def fireTestSuiteStarted(description: Description): Unit =
postMessage(s"${classOf[MacrotaskExecutorSuite].getName}:")

// This doesn't account for async and fires before any tests are run!
def fireTestSuiteFinished(description: Description): Unit = ()

def fireTestIgnored(description: Description): Unit = ()
def fireTestFinished(description: Description): Unit = ()
def fireTestFailure(failure: Failure): Unit = postMessage(false)
def fireTestAssumptionFailed(failure: Failure): Unit = postMessage(false)
}).onComplete {
case util.Success(_) => postMessage(true)
case util.Failure(_) => postMessage(false)
}

def fireTestFinished(description: Description): Unit = {
postMessage(s" + ${description.getMethodName}")
reportTest(success = true)
}

def fireTestFailure(failure: Failure): Unit = {
postMessage(
s"==> X ${classOf[MacrotaskExecutorSuite].getName}.${failure.description.getMethodName}"
)
reportTest(success = false)
}

def fireTestAssumptionFailed(failure: Failure): Unit =
reportTest(success = false)

})

()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import scala.util.Try
class WebWorkerMacrotaskSuite extends FunSuite {

import MacrotaskExecutor.Implicits._

def scalaVersion = if (BuildInfo.scalaVersion.startsWith("2"))
BuildInfo.scalaVersion.split("\\.").init.mkString(".")
else
Expand All @@ -37,10 +37,12 @@ class WebWorkerMacrotaskSuite extends FunSuite {
Try(js.isUndefined(js.Dynamic.global.window.Worker)).toOption
.filterNot(identity)
.foreach { _ =>
test("macrotask executor should pass the suite on a webworker") {
test("pass the MacrotaskSuite in a web worker") {
val p = Promise[Boolean]()

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

worker.onmessage = { event =>
event.data match {
Expand Down