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 3 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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
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("jsEnv" -> useJSEnv.value.toString)),
buildInfoPackage := "org.scalajs.macrotaskexecutor")
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin, NoPublishPlugin)
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 = !Set("Firefox", "Chrome").contains(BuildInfo.jsEnv)
Copy link
Member Author

Choose a reason for hiding this comment

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

@djspiewak how about this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we put the browser check into the buildInfoKeys calculation instead? Basically turn the build info into something more like "isBrowser" -> .... That does a better job of centralizing things so that we can add/remove browsers more easily

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Also this is busted right now anyway lol.


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(_))

}

}