@@ -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,10 @@ 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 setupJsUrl = m.materialize(" setup.js" , JSSetup .setupCode(enableCom))
137
+ val page = m.materialize(" scalajsRun.html" , htmlPage(setupJsUrl, input, m))
146
138
withCleanup(newDriver())(maybeCleanupDriver(_, config)) { driver =>
147
139
driver.navigate().to(page)
148
140
@@ -171,13 +163,25 @@ private[selenium] object SeleniumRun {
171
163
private def maybeCleanupDriver (d : WebDriver , config : SeleniumJSEnv .Config ) =
172
164
if (! config.keepAlive) d.close()
173
165
174
- private def htmlPage (scripts : Seq [java.net.URL ]): String = {
175
- val scriptTags =
176
- scripts.map(path => s " <script src=' ${path.toString}'></script> " )
166
+ private def htmlPage (setupJsUrl : URL , input : Seq [Input ], materializer : FileMaterializer ): String = {
167
+ val setupJs = s " <script src=' ${setupJsUrl.toString}'></script> "
168
+
169
+ val tags = input.map {
170
+ case Input .Script (path) =>
171
+ val url = materializer.materialize(path)
172
+ s " <script src=' ${url.toString}'></script> "
173
+ case Input .ESModule (path) =>
174
+ val url = materializer.materialize(path)
175
+ s " <script type='module' src=' ${url.toString}'></script> "
176
+ case _ => throw new UnsupportedInputException (input)
177
+ }
178
+
179
+ val allTags = setupJs +: tags
180
+
177
181
s """ <html>
178
182
| <meta charset="UTF-8">
179
183
| <body>
180
- | ${scriptTags .mkString(" \n " )}
184
+ | ${allTags .mkString(" \n " )}
181
185
| </body>
182
186
|</html>
183
187
""" .stripMargin
0 commit comments