Skip to content

Enable/disable webworker test depending on JSEnv #20

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 6 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
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("${{ matrix.ci }}")

replaceCommandAlias("ci", ciVariants.mkString("; ", "; ", ""))

addCommandAlias("ciNode", "; set useJSEnv := JSEnv.NodeJS; core/test; core/doc")
addCommandAlias("ciFirefox", "; set useJSEnv := JSEnv.Firefox; all core/test webworker/test; set useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciChrome", "; set useJSEnv := JSEnv.Chrome; all core/test webworker/test; set useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciJSDOMNodeJS", "; set useJSEnv := JSEnv.JSDOMNodeJS; core/test; set useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciNode", "; set Global / useJSEnv := JSEnv.NodeJS; test; core/doc")
addCommandAlias("ciFirefox", "; set Global / useJSEnv := JSEnv.Firefox; test; set Global / useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciChrome", "; set Global / useJSEnv := JSEnv.Chrome; test; set Global / useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciJSDOMNodeJS", "; set Global / useJSEnv := JSEnv.JSDOMNodeJS; test; set Global / useJSEnv := JSEnv.NodeJS")
Comment on lines +69 to +72
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it was configured in CE. Just an omission, or is Global a weird/bad way to do things?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah. Global is actually fine and it is the correct thing to do here.


// release configuration

Expand Down Expand Up @@ -161,6 +161,6 @@ lazy val webworker = project
"org.scalameta" %%% "munit" % MUnitVersion % Test,
),
(Test / test) := (Test / test).dependsOn(Compile / fastOptJS).value,
buildInfoKeys := Seq[BuildInfoKey](scalaVersion, baseDirectory),
buildInfoKeys := Seq(scalaVersion, baseDirectory, BuildInfoKey("isBrowser" -> useJSEnv.value.isBrowser)),
buildInfoPackage := "org.scalajs.macrotaskexecutor")
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin, NoPublishPlugin)
10 changes: 5 additions & 5 deletions project/JSEnv.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sealed abstract class JSEnv
sealed abstract class JSEnv(val isBrowser: Boolean)
object JSEnv {
case object Chrome extends JSEnv
case object Firefox extends JSEnv
case object JSDOMNodeJS extends JSEnv
case object NodeJS extends JSEnv
case object Chrome extends JSEnv(true)
case object Firefox extends JSEnv(true)
case object JSDOMNodeJS extends JSEnv(false)
case object NodeJS extends JSEnv(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,37 @@ import munit.FunSuite
import org.scalajs.dom.webworkers.Worker

import scala.concurrent.Promise
import scala.scalajs.js
import scala.util.Try

class WebWorkerMacrotaskSuite extends FunSuite {

import MacrotaskExecutor.Implicits._

def scalaVersion = if (BuildInfo.scalaVersion.startsWith("2"))
BuildInfo.scalaVersion.split("\\.").init.mkString(".")
BuildInfo.scalaVersion.split('.').init.mkString(".")
else
BuildInfo.scalaVersion

def targetDir = s"${BuildInfo.baseDirectory}/target/scala-${scalaVersion}"

Try(js.isUndefined(js.Dynamic.global.window.Worker)).toOption
.filterNot(identity)
.foreach { _ =>
test("pass the MacrotaskSuite in a web worker") {
val p = Promise[Boolean]()
override def munitIgnore = !BuildInfo.isBrowser

val worker = new Worker(
s"file://${targetDir}/scala-js-macrotask-executor-webworker-fastopt/main.js"
)
test("pass the MacrotaskSuite in a web worker") {
val p = Promise[Boolean]()

worker.onmessage = { event =>
event.data match {
case log: String => println(log)
case success: Boolean => p.success(success)
case _ => ()
}
}

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

worker.onmessage = { event =>
event.data match {
case log: String => println(log)
case success: Boolean => p.success(success)
case _ => ()
}
}

p.future.map(assert(_))

}

}