Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- [email protected]
- [email protected]
- [email protected]
ci: [ciJVM, ciJS, ciFirefox, ciChrome]
ci: [ciJVM, ciJS, ciFirefox, ciChrome, ciJSDOMNodeJS]
exclude:
- ci: ciJS
java: [email protected]
Expand Down Expand Up @@ -66,6 +66,18 @@ jobs:
scala: 2.12.14
- os: windows-latest
ci: ciChrome
- ci: ciJSDOMNodeJS
java: [email protected]
- ci: ciJSDOMNodeJS
java: [email protected]
- ci: ciJSDOMNodeJS
java: [email protected]
- os: windows-latest
scala: 3.0.1
- os: windows-latest
scala: 2.12.14
- os: windows-latest
ci: ciJSDOMNodeJS
- java: [email protected]
os: windows-latest
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -98,11 +110,16 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Setup NodeJS v14 LTS
if: matrix.ci == 'ciJS'
if: matrix.ci == 'ciJS' || matrix.ci == 'ciJSDOMNodeJS'
uses: actions/[email protected]
with:
node-version: 14

- name: Install jsdom
if: matrix.ci == 'ciJSDOMNodeJS'
shell: bash
run: npm install jsdom

- name: Check that workflows are up to date
shell: bash
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ tags
.bloop/
metals.sbt
.vscode

# npm
node_modules/
package-lock.json
Copy link
Member Author

Choose a reason for hiding this comment

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

@vasilmkd @djspiewak Just want to make sure you're aware that I decided to ignore the lockfile (created by the JSDOM dependency), but not sure about this decision at all. @mpilquist, @ChristopherDavenport, @rossabaker, and I have been struggling with this same issue for fs2 and http4s.

In this case its just a test dependency, but @rossabaker makes a good point about repeatable builds. http4s/http4s#4938 (comment)

18 changes: 14 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.{ChromeDriver, ChromeOptions}
import org.openqa.selenium.firefox.{FirefoxOptions, FirefoxProfile}
import org.openqa.selenium.remote.server.{DriverFactory, DriverProvider}
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
import org.scalajs.jsenv.selenium.SeleniumJSEnv

import JSEnv._
Expand Down Expand Up @@ -66,12 +67,19 @@ val GraalVM8 = "[email protected]"
ThisBuild / githubWorkflowJavaVersions := Seq(ScalaJSJava, LTSJava, LatestJava, GraalVM8)
ThisBuild / githubWorkflowOSes := Seq(PrimaryOS, Windows)

ThisBuild / githubWorkflowBuildPreamble +=
ThisBuild / githubWorkflowBuildPreamble ++= Seq(
WorkflowStep.Use(
UseRef.Public("actions", "setup-node", "v2.1.2"),
name = Some("Setup NodeJS v14 LTS"),
params = Map("node-version" -> "14"),
cond = Some("matrix.ci == 'ciJS'"))
cond = Some("matrix.ci == 'ciJS' || matrix.ci == 'ciJSDOMNodeJS'")
),
WorkflowStep.Run(
List("npm install jsdom"),
name = Some("Install jsdom"),
cond = Some("matrix.ci == 'ciJSDOMNodeJS'")
)
)

ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("${{ matrix.ci }}")),
Expand All @@ -97,7 +105,7 @@ ThisBuild / githubWorkflowBuild := Seq(
)
)

val ciVariants = List("ciJVM", "ciJS", "ciFirefox", "ciChrome")
val ciVariants = List("ciJVM", "ciJS", "ciFirefox", "ciChrome", "ciJSDOMNodeJS")
val jsCiVariants = ciVariants.tail
ThisBuild / githubWorkflowBuildMatrixAdditions += "ci" -> ciVariants

Expand Down Expand Up @@ -132,6 +140,7 @@ ThisBuild / Test / jsEnv := {

useJSEnv.value match {
case NodeJS => old
case JSDOMNodeJS => new JSDOMNodeJSEnv()
case Firefox =>
val profile = new FirefoxProfile()
profile.setPreference("privacy.file_unique_origin", false)
Expand Down Expand Up @@ -177,7 +186,7 @@ val CoopVersion = "1.1.1"

replaceCommandAlias(
"ci",
"; project /; headerCheck; scalafmtSbtCheck; scalafmtCheck; clean; test; coreJVM/mimaReportBinaryIssues; root/unidoc213; set Global / useJSEnv := JSEnv.Firefox; testsJS/test; webWorkerTests/test; set Global / useJSEnv := JSEnv.Chrome; testsJS/test; webWorkerTests/test; set Global / useJSEnv := JSEnv.NodeJS"
"; project /; headerCheck; scalafmtSbtCheck; scalafmtCheck; clean; test; coreJVM/mimaReportBinaryIssues; root/unidoc213; set Global / useJSEnv := JSEnv.Firefox; testsJS/test; webWorkerTests/test; set Global / useJSEnv := JSEnv.Chrome; testsJS/test; webWorkerTests/test; set Global / useJSEnv := JSEnv.JSDOMNodeJS; testsJS/test; set Global / useJSEnv := JSEnv.NodeJS"
)

addCommandAlias(
Expand All @@ -192,6 +201,7 @@ def browserCiCommand(browser: JSEnv) =
s"; set Global / useJSEnv := JSEnv.$browser; project rootJS; headerCheck; scalafmtCheck; clean; testsJS/test; webWorkerTests/test; set Global / useJSEnv := JSEnv.NodeJS"
addCommandAlias("ciFirefox", browserCiCommand(Firefox))
addCommandAlias("ciChrome", browserCiCommand(Chrome))
addCommandAlias("ciJSDOMNodeJS", browserCiCommand(JSDOMNodeJS))

addCommandAlias("prePR", "; root/clean; scalafmtSbt; +root/scalafmtAll; +root/headerCreate")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import scala.collection.mutable
import scala.concurrent.ExecutionContext
import scala.scalajs.js
import scala.util.Random
import scala.util.control.NonFatal

/**
* Based on https://github.com/YuzuJS/setImmediate
Expand Down Expand Up @@ -47,11 +48,16 @@ private[unsafe] object PolyfillExecutionContext extends ExecutionContext {
var postMessageIsAsynchronous = true
val oldOnMessage = js.Dynamic.global.onmessage

js.Dynamic.global.onmessage = { () => postMessageIsAsynchronous = false }

js.Dynamic.global.postMessage("", "*")
js.Dynamic.global.onmessage = oldOnMessage
postMessageIsAsynchronous
try {
// This line throws `ReferenceError: onmessage is not defined` in JSDOMNodeJS environment
js.Dynamic.global.onmessage = { () => postMessageIsAsynchronous = false }
js.Dynamic.global.postMessage("", "*")
js.Dynamic.global.onmessage = oldOnMessage
postMessageIsAsynchronous
} catch {
case NonFatal(_) =>
false
}
} else {
false
}
Expand Down
1 change: 1 addition & 0 deletions project/JSEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ sealed abstract class JSEnv
object JSEnv {
case object Chrome extends JSEnv
case object Firefox extends JSEnv
case object JSDOMNodeJS extends JSEnv
case object NodeJS extends JSEnv
}
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "1.1.0"
libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0"

addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.21.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.6.0")
Expand Down
33 changes: 17 additions & 16 deletions webworker-tests/src/test/scala/cats/effect/WebWorkerIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package cats.effect

import org.scalajs.dom.webworkers.Worker
import org.scalajs.dom.window

import scala.concurrent.duration._
import scala.scalajs.js
import scala.util.Try

class WebWorkerIOSpec extends BaseSpec {
Expand All @@ -33,24 +33,25 @@ class WebWorkerIOSpec extends BaseSpec {

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

Try(window).toOption.foreach { _ =>
"io on webworker" should {
"pass the spec" in real {
for {
worker <- IO(
new Worker(s"file://${targetDir}/cats-effect-webworker-tests-fastopt/main.js"))
success <- IO.async_[Boolean] { cb =>
worker.onmessage = { event =>
event.data match {
case log: String => println(log)
case success: Boolean => cb(Right(success))
case _ => ()
Try(js.isUndefined(js.Dynamic.global.window.Worker)).toOption.filterNot(identity).foreach {
_ =>
"io on webworker" should {
"pass the spec" in real {
for {
worker <- IO(
new Worker(s"file://${targetDir}/cats-effect-webworker-tests-fastopt/main.js"))
success <- IO.async_[Boolean] { cb =>
worker.onmessage = { event =>
event.data match {
case log: String => println(log)
case success: Boolean => cb(Right(success))
case _ => ()
}
}
}
}
} yield success mustEqual true
} yield success mustEqual true
}
}
}
}

}