Skip to content

Commit

Permalink
Upgrade to Scala.js 1.0.0-RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
gzm0 committed Nov 25, 2019
1 parent ca640d8 commit 75ddf98
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M7")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-RC1")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.18")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import java.nio.file._
import java.net._
import java.util.Arrays

import org.scalajs.io._

private[selenium] sealed abstract class FileMaterializer {
private val tmpSuffixRE = """[a-zA-Z0-9-_.]*$""".r

private[this] var tmpFiles: List[Path] = Nil

def materialize(vf: VirtualBinaryFile): URL = {
val tmp = newTmp(vf.path)
val in = vf.inputStream
Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING)
def materialize(path: Path): URL = {
val tmp = newTmp(path.toString)
Files.copy(path, tmp, StandardCopyOption.REPLACE_EXISTING)
toURL(tmp)
}

Expand Down Expand Up @@ -54,9 +51,13 @@ object FileMaterializer {

/** materializes virtual files in a temp directory (uses file:// schema). */
private class TempDirFileMaterializer extends FileMaterializer {
override def materialize(vf: VirtualBinaryFile): URL = vf match {
case vf: FileVirtualBinaryFile => vf.file.toURI.toURL
case vf => super.materialize(vf)
override def materialize(path: Path): URL = {
try {
path.toFile.toURI.toURL
} catch {
case _: UnsupportedOperationException =>
super.materialize(path)
}
}

protected def createTmp(suffix: String) = Files.createTempFile(null, suffix)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.scalajs.jsenv.selenium

import org.scalajs.io._

private[selenium] object JSSetup {
def setupCode(enableCom: Boolean): String = {
s"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ final class SeleniumJSEnv(capabilities: Capabilities, config: SeleniumJSEnv.Conf

val name: String = s"SeleniumJSEnv ($capabilities)"

def start(input: Input, runConfig: RunConfig): JSRun =
def start(input: Seq[Input], runConfig: RunConfig): JSRun =
SeleniumRun.start(newDriver _, input, config, runConfig)

def startWithCom(input: Input, runConfig: RunConfig, onMessage: String => Unit): JSComRun =
def startWithCom(input: Seq[Input], runConfig: RunConfig, onMessage: String => Unit): JSComRun =
SeleniumRun.startWithCom(newDriver _, input, config, runConfig, onMessage)

private def newDriver() = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.scalajs.jsenv.selenium

import org.openqa.selenium._

import org.scalajs.io._
import org.scalajs.jsenv._

import scala.annotation.tailrec
Expand Down Expand Up @@ -111,33 +110,34 @@ private[selenium] object SeleniumRun {
.supportsOnOutputStream()
}

def start(newDriver: () => JSDriver, input: Input, config: Config, runConfig: RunConfig): JSRun = {
def start(newDriver: () => JSDriver, input: Seq[Input], config: Config,
runConfig: RunConfig): JSRun = {
startInternal(newDriver, input, config, runConfig, enableCom = false)(
new SeleniumRun(_, _, _, _), JSRun.failed _)
}

def startWithCom(newDriver: () => JSDriver, input: Input, config: Config,
def startWithCom(newDriver: () => JSDriver, input: Seq[Input], config: Config,
runConfig: RunConfig, onMessage: String => Unit): JSComRun = {
startInternal(newDriver, input, config, runConfig, enableCom = true)(
new SeleniumComRun(_, _, _, _, onMessage), JSComRun.failed _)
}

private type Ctor[T] = (JSDriver, Config, Streams, FileMaterializer) => T

private def startInternal[T](newDriver: () => JSDriver, input: Input,
private def startInternal[T](newDriver: () => JSDriver, input: Seq[Input],
config: Config, runConfig: RunConfig, enableCom: Boolean)(
newRun: Ctor[T], failed: Throwable => T): T = {
validator.validate(runConfig)

val scripts = input match {
case Input.ScriptsToLoad(s) => s
case _ => throw new UnsupportedInputException(input)
val scripts = input.map {
case Input.Script(s) => s
case _ => throw new UnsupportedInputException(input)
}

try {
withCleanup(FileMaterializer(config.materialization))(_.close()) { m =>
val allScriptURLs = (
m.materialize("setup.js", JSSetup.setupCode(enableCom)) ::
m.materialize("setup.js", JSSetup.setupCode(enableCom)) +:
scripts.map(m.materialize)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class KeepAliveTest {
}

private def runNoCom(env: JSEnv) = {
val run = env.start(Input.ScriptsToLoad(Nil), RunConfig())
val run = env.start(Nil, RunConfig())
run.close()
Await.ready(run.future, 1.minute)
}

private def runWithCom(env: JSEnv) = {
val run = env.startWithCom(Input.ScriptsToLoad(Nil), RunConfig(), _ => ())
val run = env.startWithCom(Nil, RunConfig(), _ => ())
run.close()
Await.ready(run.future, 1.minute)
}
Expand Down

0 comments on commit 75ddf98

Please sign in to comment.