Skip to content

Commit d9e8104

Browse files
committed
Add ESModule support
1 parent fe57fdb commit d9e8104

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea
12
*.class
23
*.log
34

seleniumJSEnv/src/main/scala/org/scalajs/jsenv/selenium/SeleniumRun.scala

+16-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import scala.util.control.NonFatal
1010

1111
import java.util.concurrent.{ConcurrentLinkedQueue, Executors}
1212
import java.util.function.Consumer
13+
import java.nio.file.Path
1314

1415
private sealed class SeleniumRun(
1516
driver: WebDriver with JavascriptExecutor,
@@ -129,9 +130,13 @@ private[selenium] object SeleniumRun {
129130
newRun: Ctor[T], failed: Throwable => T): T = {
130131
validator.validate(runConfig)
131132

132-
val scripts = input.map {
133-
case Input.Script(s) => s
134-
case _ => throw new UnsupportedInputException(input)
133+
var scripts: Seq[Path] = Seq.empty
134+
var modules: Seq[Path] = Seq.empty
135+
136+
input.foreach {
137+
case Input.Script(s) => scripts :+= s
138+
case Input.ESModule(s) => modules :+= s
139+
case _ => throw new UnsupportedInputException(input)
135140
}
136141

137142
try {
@@ -141,7 +146,9 @@ private[selenium] object SeleniumRun {
141146
scripts.map(m.materialize)
142147
)
143148

144-
val page = m.materialize("scalajsRun.html", htmlPage(allScriptURLs))
149+
val allModuleURLs = modules.map(m.materialize)
150+
151+
val page = m.materialize("scalajsRun.html", htmlPage(allScriptURLs, allModuleURLs))
145152

146153
withCleanup(newDriver())(maybeCleanupDriver(_, config)) { driver =>
147154
driver.navigate().to(page)
@@ -171,13 +178,14 @@ private[selenium] object SeleniumRun {
171178
private def maybeCleanupDriver(d: WebDriver, config: SeleniumJSEnv.Config) =
172179
if (!config.keepAlive) d.close()
173180

174-
private def htmlPage(scripts: Seq[java.net.URL]): String = {
175-
val scriptTags =
176-
scripts.map(path => s"<script src='${path.toString}'></script>")
181+
private def htmlPage(scripts: Seq[java.net.URL], modules: Seq[java.net.URL]): String = {
182+
val scriptTags = scripts.map(path => s"<script src='${path.toString}'></script>")
183+
val moduleTags = modules.map(path => s"<script type='module' src='${path.toString}'></script>")
184+
val allTags = scriptTags ++ moduleTags
177185
s"""<html>
178186
| <meta charset="UTF-8">
179187
| <body>
180-
| ${scriptTags.mkString("\n ")}
188+
| ${allTags.mkString("\n ")}
181189
| </body>
182190
|</html>
183191
""".stripMargin

0 commit comments

Comments
 (0)