Skip to content
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

Add JSDOMNodeJSEnv to ci matrix and fix polyfill #2191

Merged
merged 5 commits into from
Aug 5, 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
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:
- adopt@1.11
- adopt@1.16
- graalvm-ce-java8@21.1
ci: [ciJVM, ciJS, ciFirefox, ciChrome]
ci: [ciJVM, ciJS, ciFirefox, ciChrome, ciJSDOMNodeJS]
exclude:
- ci: ciJS
java: adopt@1.11
Expand Down Expand Up @@ -66,6 +66,18 @@ jobs:
scala: 2.12.14
- os: windows-latest
ci: ciChrome
- ci: ciJSDOMNodeJS
java: adopt@1.11
- ci: ciJSDOMNodeJS
java: adopt@1.16
- ci: ciJSDOMNodeJS
java: graalvm-ce-java8@21.1
- os: windows-latest
scala: 3.0.1
- os: windows-latest
scala: 2.12.14
- os: windows-latest
ci: ciJSDOMNodeJS
- java: adopt@1.16
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/setup-node@v2.1.2
with:
node-version: 14

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

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

# npm
node_modules/
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 = "graalvm-ce-java8@21.1"
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"),
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))
vasilmkd marked this conversation as resolved.
Show resolved Hide resolved

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 }
vasilmkd marked this conversation as resolved.
Show resolved Hide resolved
js.Dynamic.global.postMessage("", "*")
js.Dynamic.global.onmessage = oldOnMessage
postMessageIsAsynchronous
} catch {
case NonFatal(_) =>
vasilmkd marked this conversation as resolved.
Show resolved Hide resolved
false
}
} else {
false
}
Expand Down
Loading