|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
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 |
18 | 26 |
|
19 | 27 | ThisBuild / baseVersion := "0.1"
|
20 | 28 |
|
21 | 29 | ThisBuild / organization := "org.scala-js"
|
22 | 30 | ThisBuild / organizationName := "Scala.js (https://www.scala-js.org/)"
|
23 | 31 |
|
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")) |
26 | 42 |
|
27 | 43 | ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6", "3.0.1")
|
28 | 44 |
|
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) |
0 commit comments