11import sbt ._
22import sbt .Keys ._
3+ import java .util .concurrent .TimeUnit
4+ import org .openqa .selenium .{Capabilities , WebDriver }
5+ import org .openqa .selenium .chrome .{ChromeDriver , ChromeOptions }
6+ import org .openqa .selenium .firefox .{FirefoxOptions , FirefoxProfile }
7+ import org .openqa .selenium .remote .server .{DriverFactory , DriverProvider }
8+ import org .scalajs .jsenv .jsdomnodejs .JSDOMNodeJSEnv
9+ import org .scalajs .jsenv .selenium .SeleniumJSEnv
10+ import org .scalajs .sbtplugin .ScalaJSJUnitPlugin
311import org .scalajs .sbtplugin .ScalaJSPlugin
412import org .scalajs .sbtplugin .ScalaJSPlugin .autoImport ._
13+ import sbtbuildinfo .BuildInfoPlugin
14+ import sbtbuildinfo .BuildInfoPlugin .autoImport ._
515import scalafix .sbt .ScalafixPlugin
616import scalafix .sbt .ScalafixPlugin .autoImport ._
717import scalatex .ScalatexReadme
@@ -21,6 +31,11 @@ object Build {
2131 .aggregate(
2232 scalafixRules,
2333 dom,
34+ testsShared,
35+ testsWebworker,
36+ testsChrome,
37+ testsFirefox,
38+ testsNodeJsdom,
2439 example,
2540 // readme, // This is a Scala 2.12 only module
2641 )
@@ -43,6 +58,85 @@ object Build {
4358 libraryDependencies += Dep .scalafixCore.value,
4459 )
4560
61+ lazy val testsShared = project
62+ .in(file(" tests-shared" ))
63+ .dependsOn(dom)
64+ .enablePlugins(ScalaJSPlugin , ScalaJSJUnitPlugin )
65+ .configure(commonSettings, crossScala, preventPublication, moveTestLibsToCompile)
66+
67+ lazy val testsWebworker = project
68+ .in(file(" tests-webworker" ))
69+ .dependsOn(testsShared)
70+ .enablePlugins(ScalaJSPlugin , ScalaJSJUnitPlugin , BuildInfoPlugin )
71+ .configure(commonSettings, crossScala, preventPublication, moveTestLibsToCompile)
72+ .settings(
73+ buildInfoKeys := Seq [BuildInfoKey ](
74+ " wwJsPath" -> (Compile / fastOptJS / artifactPath).value.absolutePath,
75+ ),
76+ buildInfoPackage := " org.scalajs.dom.tests.webworker" ,
77+ scalaJSUseMainModuleInitializer := true ,
78+ )
79+
80+ def testsWebworkers : Project => Project = _
81+ .dependsOn(testsWebworker)
82+ .settings(
83+ Test / test := {
84+ val _ = (testsWebworker / Compile / fastOptJS).value
85+ (Test / test).value
86+ },
87+ )
88+
89+ lazy val testsChrome = project
90+ .in(file(" tests-chrome" ))
91+ .dependsOn(testsShared % Test )
92+ .enablePlugins(ScalaJSPlugin , ScalaJSJUnitPlugin )
93+ .configure(commonSettings, crossScala, preventPublication, testsWebworkers)
94+ .settings(
95+ Test / jsEnv := {
96+ System .setProperty(" webdriver.chrome.silentOutput" , " true" )
97+ val o = new ChromeOptions ()
98+ o.setHeadless(true )
99+ o.addArguments(" --allow-file-access-from-files" )
100+ val df = new DriverFactory {
101+ private [this ] val default = SeleniumJSEnv .Config ().driverFactory
102+ override def newInstance (c : Capabilities ): WebDriver = {
103+ val d = default.newInstance(c).asInstanceOf [ChromeDriver ]
104+ d.manage.timeouts.pageLoadTimeout(if (inCI) 10 else 1 , TimeUnit .MINUTES )
105+ d.manage.timeouts.setScriptTimeout(if (inCI) 10 else 1 , TimeUnit .MINUTES )
106+ d
107+ }
108+ override def registerDriverProvider (p : DriverProvider ): Unit =
109+ default.registerDriverProvider(p)
110+ }
111+ new SeleniumJSEnv (o, SeleniumJSEnv .Config ().withDriverFactory(df))
112+ },
113+ )
114+
115+ lazy val testsFirefox = project
116+ .in(file(" tests-firefox" ))
117+ .dependsOn(testsShared % Test )
118+ .enablePlugins(ScalaJSPlugin , ScalaJSJUnitPlugin )
119+ .configure(commonSettings, crossScala, preventPublication, testsWebworkers)
120+ .settings(
121+ Test / jsEnv := {
122+ val p = new FirefoxProfile ()
123+ p.setPreference(" privacy.file_unique_origin" , false )
124+ val o = new FirefoxOptions ()
125+ o.setProfile(p)
126+ o.setHeadless(true )
127+ new SeleniumJSEnv (o)
128+ },
129+ )
130+
131+ lazy val testsNodeJsdom = project
132+ .in(file(" tests-node-jsdom" ))
133+ .dependsOn(testsShared % Test )
134+ .enablePlugins(ScalaJSPlugin , ScalaJSJUnitPlugin )
135+ .configure(commonSettings, crossScala, preventPublication)
136+ .settings(
137+ Test / jsEnv := new JSDOMNodeJSEnv ,
138+ )
139+
46140 lazy val example = project
47141 .dependsOn(dom)
48142 .enablePlugins(ScalaJSPlugin )
0 commit comments