@@ -10,6 +10,8 @@ import scala.util.control.NonFatal
10
10
11
11
import java .util .concurrent .{ConcurrentLinkedQueue , Executors }
12
12
import java .util .function .Consumer
13
+ import java .nio .file .Path
14
+ import java .net .URL
13
15
14
16
private sealed class SeleniumRun (
15
17
driver : WebDriver with JavascriptExecutor ,
@@ -129,20 +131,11 @@ private[selenium] object SeleniumRun {
129
131
newRun : Ctor [T ], failed : Throwable => T ): T = {
130
132
validator.validate(runConfig)
131
133
132
- val scripts = input.map {
133
- case Input .Script (s) => s
134
- case _ => throw new UnsupportedInputException (input)
135
- }
136
-
137
134
try {
138
135
withCleanup(FileMaterializer (config.materialization))(_.close()) { m =>
139
- val allScriptURLs = (
140
- m.materialize(" setup.js" , JSSetup .setupCode(enableCom)) +:
141
- scripts.map(m.materialize)
142
- )
143
-
144
- val page = m.materialize(" scalajsRun.html" , htmlPage(allScriptURLs))
145
-
136
+ val setupJsScript = Input .Script (JSSetup .setupFile(enableCom))
137
+ val fullInput = setupJsScript +: input
138
+ val page = m.materialize(" scalajsRun.html" , htmlPage(fullInput, m))
146
139
withCleanup(newDriver())(maybeCleanupDriver(_, config)) { driver =>
147
140
driver.navigate().to(page)
148
141
@@ -171,18 +164,27 @@ private[selenium] object SeleniumRun {
171
164
private def maybeCleanupDriver (d : WebDriver , config : SeleniumJSEnv .Config ) =
172
165
if (! config.keepAlive) d.close()
173
166
174
- private def htmlPage (scripts : Seq [java.net.URL ]): String = {
175
- val scriptTags =
176
- scripts.map(path => s " <script src=' ${path.toString}'></script> " )
167
+ private def htmlPage (fullInput : Seq [Input ], materializer : FileMaterializer ): String = {
168
+ val tags = fullInput.map {
169
+ case Input .Script (path) => makeTag(path, " text/javascript" , materializer)
170
+ case Input .ESModule (path) => makeTag(path, " module" , materializer)
171
+ case _ => throw new UnsupportedInputException (fullInput)
172
+ }
173
+
177
174
s """ <html>
178
175
| <meta charset="UTF-8">
179
176
| <body>
180
- | ${scriptTags .mkString(" \n " )}
177
+ | ${tags .mkString(" \n " )}
181
178
| </body>
182
179
|</html>
183
180
""" .stripMargin
184
181
}
185
182
183
+ private def makeTag (path : Path , tpe : String , materializer : FileMaterializer ): String = {
184
+ val url = materializer.materialize(path)
185
+ s " <script defer type=' $tpe' src=' $url'></script> "
186
+ }
187
+
186
188
private class WindowOnErrorException (errs : List [String ]) extends Exception (s " JS error: $errs" )
187
189
188
190
private def consumer [A ](f : A => Unit ): Consumer [A ] = new Consumer [A ] {
0 commit comments