Skip to content

Commit 7128202

Browse files
committed
Adapted scaffolding from cats-effect
1 parent f916689 commit 7128202

File tree

6 files changed

+127
-5
lines changed

6 files changed

+127
-5
lines changed

Diff for: .github/workflows/ci.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
os: [ubuntu-latest]
2525
scala: [2.12.14, 2.13.6, 3.0.1]
2626
27+
ci: [ciNode, ciFirefox, ciChrome, ciJSDOMNodeJS]
2728
runs-on: ${{ matrix.os }}
2829
steps:
2930
- name: Checkout current branch (full)
@@ -48,7 +49,17 @@ jobs:
4849
~/Library/Caches/Coursier/v1
4950
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
5051

52+
- name: Setup NodeJS v14 LTS
53+
if: matrix.ci == 'ciNode' || matrix.ci == 'ciJSDOMNodeJS'
54+
uses: actions/[email protected]
55+
with:
56+
node-version: 14
57+
58+
- name: Install jsdom
59+
if: matrix.ci == 'ciJSDOMNodeJS'
60+
run: npm install
61+
5162
- name: Check that workflows are up to date
5263
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
5364

54-
- run: sbt ++${{ matrix.scala }} ci
65+
- run: sbt ++${{ matrix.scala }} '${{ matrix.ci }}'

Diff for: .jvmopts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-XX:+UseG1GC

Diff for: build.sbt

+103-4
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,115 @@
1414
* limitations under the License.
1515
*/
1616

17-
name := "scala-js-macrotask-executor"
17+
import org.openqa.selenium.WebDriver
18+
import org.openqa.selenium.chrome.{ChromeDriver, ChromeOptions}
19+
import org.openqa.selenium.firefox.{FirefoxOptions, FirefoxProfile}
20+
import org.openqa.selenium.remote.server.{DriverFactory, DriverProvider}
21+
22+
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
23+
import org.scalajs.jsenv.selenium.SeleniumJSEnv
24+
25+
import java.util.concurrent.TimeUnit
1826

1927
ThisBuild / baseVersion := "0.1"
2028

2129
ThisBuild / organization := "org.scala-js"
2230
ThisBuild / organizationName := "Scala.js (https://www.scala-js.org/)"
2331

24-
ThisBuild / publishGithubUser := "djspiewak"
25-
ThisBuild / publishFullName := "Daniel Spiewak"
32+
ThisBuild / developers := List(
33+
Developer("djspiewak", "Daniel Spiewak", "@djspiewak", url("https://github.com/djspiewak")),
34+
Developer("armanbilge", "Arman Bilge", "@armanbilge", url("https://github.com/armanbilge")))
35+
36+
ThisBuild / homepage := Some(url("https://github.com/scala-js/scala-js-macrotask-executor"))
37+
38+
ThisBuild / scmInfo := Some(
39+
ScmInfo(
40+
url("https://github.com/scala-js/scala-js-macrotask-executor"),
41+
"[email protected]:scala-js/scala-js-macrotask-executor.git"))
2642

2743
ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6", "3.0.1")
2844

29-
enablePlugins(ScalaJSPlugin)
45+
ThisBuild / githubWorkflowBuildPreamble ++= Seq(
46+
WorkflowStep.Use(
47+
UseRef.Public("actions", "setup-node", "v2.1.2"),
48+
name = Some("Setup NodeJS v14 LTS"),
49+
params = Map("node-version" -> "14"),
50+
cond = Some("matrix.ci == 'ciNode' || matrix.ci == 'ciJSDOMNodeJS'")),
51+
WorkflowStep.Run(
52+
List("npm install"),
53+
name = Some("Install jsdom"),
54+
cond = Some("matrix.ci == 'ciJSDOMNodeJS'")))
55+
56+
val ciVariants = List("ciNode", "ciFirefox", "ciChrome", "ciJSDOMNodeJS")
57+
58+
ThisBuild / githubWorkflowBuildMatrixAdditions += "ci" -> ciVariants
59+
60+
ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("${{ matrix.ci }}")))
61+
62+
replaceCommandAlias("ci", ciVariants.mkString("; ", "; ", ""))
63+
64+
addCommandAlias("ciNode", "; set useJSEnv := JSEnv.NodeJS; core/test; core/doc")
65+
addCommandAlias("ciFirefox", "; set useJSEnv := JSEnv.Firefox; all core/test webworker/test; set useJSEnv := JSEnv.NodeJS")
66+
addCommandAlias("ciChrome", "; set useJSEnv := JSEnv.Chrome; all core/test webworker/test; set useJSEnv := JSEnv.NodeJS")
67+
addCommandAlias("ciJSDOMNodeJS", "; set useJSEnv := JSEnv.JSDOMNodeJS; core/test; set useJSEnv := JSEnv.NodeJS")
68+
69+
lazy val useJSEnv =
70+
settingKey[JSEnv]("Use Node.js or a headless browser for running Scala.js tests")
71+
72+
Global / useJSEnv := JSEnv.NodeJS
73+
74+
ThisBuild / Test / jsEnv := {
75+
import JSEnv._
76+
77+
val old = (Test / jsEnv).value
78+
79+
useJSEnv.value match {
80+
case NodeJS => old
81+
case JSDOMNodeJS => new JSDOMNodeJSEnv()
82+
case Firefox =>
83+
val profile = new FirefoxProfile()
84+
profile.setPreference("privacy.file_unique_origin", false)
85+
val options = new FirefoxOptions()
86+
options.setProfile(profile)
87+
options.setHeadless(true)
88+
new SeleniumJSEnv(options)
89+
case Chrome =>
90+
val options = new ChromeOptions()
91+
options.setHeadless(true)
92+
options.addArguments("--allow-file-access-from-files")
93+
val factory = new DriverFactory {
94+
val defaultFactory = SeleniumJSEnv.Config().driverFactory
95+
def newInstance(capabilities: org.openqa.selenium.Capabilities): WebDriver = {
96+
val driver = defaultFactory.newInstance(capabilities).asInstanceOf[ChromeDriver]
97+
driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.HOURS)
98+
driver.manage().timeouts().setScriptTimeout(1, TimeUnit.HOURS)
99+
driver
100+
}
101+
def registerDriverProvider(provider: DriverProvider): Unit =
102+
defaultFactory.registerDriverProvider(provider)
103+
}
104+
new SeleniumJSEnv(options, SeleniumJSEnv.Config().withDriverFactory(factory))
105+
}
106+
}
107+
108+
lazy val root = project
109+
.aggregate(core, webworker)
110+
.enablePlugins(NoPublishPlugin)
111+
112+
lazy val core = project
113+
.in(file("core"))
114+
.settings(name := "scala-js-macrotask-executor")
115+
.enablePlugins(ScalaJSPlugin)
116+
117+
// this project solely exists for testing purposes
118+
lazy val webworker = project
119+
.in(file("webworker"))
120+
.dependsOn(core % "compile->test")
121+
.settings(
122+
name := "scala-js-macrotask-executor-webworker",
123+
scalaJSUseMainModuleInitializer := true,
124+
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.2.0").cross(CrossVersion.for3Use2_13),
125+
(Test / test) := (Test / test).dependsOn(Compile / fastOptJS).value,
126+
buildInfoKeys := Seq[BuildInfoKey](scalaVersion, baseDirectory),
127+
buildInfoPackage := "org.scalajs")
128+
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin, NoPublishPlugin)

Diff for: project/JSEnv.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sealed abstract class JSEnv
2+
object JSEnv {
3+
case object Chrome extends JSEnv
4+
case object Firefox extends JSEnv
5+
case object JSDOMNodeJS extends JSEnv
6+
case object NodeJS extends JSEnv
7+
}

Diff for: project/plugins.sbt

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "1.1.1"
2+
libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0"
3+
14
addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.22.0")
25
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.0")
6+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")

0 commit comments

Comments
 (0)