Skip to content

Commit

Permalink
Added cross-compilation for scala 2.13.x and scala-js 1.x, fixed shog…
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Feb 9, 2021
1 parent 3730e7a commit caf91a6
Show file tree
Hide file tree
Showing 24 changed files with 438 additions and 261 deletions.
27 changes: 16 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
language: scala
sudo: required
jdk:
- oraclejdk8
dist: trusty

language: scala

scala:
- 2.12.2

jdk:
- oraclejdk8

# - 2.13.1 #TODO
env:
- SCALAJS_VERSION=0.6.31
# - SCALAJS_VERSION=1.1.0 #TODO
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

before_script:
- wget -N http://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
Expand All @@ -29,7 +28,13 @@ before_script:
- ". $HOME/.nvm/nvm.sh"
- "nvm install node"
- "nvm use node"

script:
- sbt ++$TRAVIS_SCALA_VERSION fastOptJS::webpack
- sbt ++$TRAVIS_SCALA_VERSION it:test
- sbt ++$TRAVIS_SCALA_VERSION fastOptJS::webpack it:test
cache:
directories:
- "$HOME/.ivy2/cache"
- "$HOME/.sbt"
before_cache:
# Cleanup the cached directories to avoid unnecessary cache updates
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete
- find $HOME/.sbt -name "*.lock" -print -delete
45 changes: 18 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,22 @@ val ReactRouterVersion = "^4.0.0"
val ReactRouterReduxVersion = "next"
val ReduxVersion = "^3.6.0"
val ReduxDevToolsVersion = "^2.13.0"
val WebpackVersion = "^2.3.2"

val StaticTagsVersion = "[2.4.0,3.0.0["

val JettyVersion = "9.+"
val SeleniumVersion = "[3.4.0,4.0.0["
val ScalaTestVersion = "[3.1.0,4.0.0["

crossScalaVersions := Seq("2.12.2")

publishTo := {
val nexus = "https://oss.sonatype.org/"
isSnapshot.value match {
case true => Some("snapshots" at nexus + "content/repositories/snapshots")
case false => Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
}
publishArtifact := false
val StaticTagsVersion = "2.5.0" //TODO: 2.6.0

val commonSettings = Seq(
organization := "io.github.shogowada",
name := "scalajs-reactjs",
version := "0.14.0",
version := "0.15.0-SNAPSHOT",
licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")),
homepage := Some(url("https://github.com/shogowada/scalajs-reactjs")),

crossScalaVersions := Seq("2.12.2", "2.13.1"),
scalaVersion := "2.12.2",
ivyScala := ivyScala.value.map {
_.copy(overrideScalaVersion = true)
},
scalacOptions ++= Seq(
"-deprecation", "-unchecked", "-feature", "-Xcheckinit", "-target:jvm-1.8", "-Xfatal-warnings"
),

publishMavenStyle := true,
publishTo := {
val nexus = "https://oss.sonatype.org/"
Expand All @@ -61,15 +48,14 @@ lazy val core = project.in(file("core"))
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.9.+",
"org.scala-js" %%% "scalajs-dom" % "0.9.8",
"io.github.shogowada" %%% "statictags" % StaticTagsVersion
),
npmDependencies in Compile ++= Seq(
"create-react-class" -> CreateReactClassVersion,
"react" -> ReactVersion,
"react-dom" -> ReactVersion
),
(version in webpack) := WebpackVersion,
(webpack in(Compile, fastOptJS)) := Seq(),
(webpack in(Compile, fullOptJS)) := Seq(),
publishArtifact := true
Expand Down Expand Up @@ -162,6 +148,7 @@ lazy val routerRedux = project.in(file("router-redux"))

val exampleCommonSettings = commonSettings ++ Seq(
name += "-example",
scalaJSUseMainModuleInitializer := true,
(unmanagedResourceDirectories in Compile) += baseDirectory.value / "src" / "main" / "webapp"
)

Expand Down Expand Up @@ -268,11 +255,15 @@ lazy val exampleTest = project.in(file("example") / "test")
.settings(
name += "-example-test",
libraryDependencies ++= Seq(
"org.eclipse.jetty" % "jetty-server" % JettyVersion,
"org.seleniumhq.selenium" % "selenium-java" % SeleniumVersion,
"org.eclipse.jetty" % "jetty-server" % "9.+",

"org.scalatestplus" %% "selenium-3-141" % "3.2.2.0",
"org.scalatest" %% "scalatest" % "3.2.2"
).map(_ % "it,test"),

parallelExecution in Test := false,
parallelExecution in IntegrationTest := false,

"org.scalatest" %% "scalatest" % ScalaTestVersion
),
javaOptions ++= Seq(
s"-Dtarget.path.custom-virtual-dom=${(crossTarget in exampleCustomVirtualDOM).value}",
s"-Dtarget.path.helloworld=${(crossTarget in exampleHelloWorld).value}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import io.github.shogowada.scalajs.reactjs.elements.ReactElement
import io.github.shogowada.scalajs.reactjs.example.customvirtualdom.CustomVirtualDOM._
import org.scalajs.dom

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object HelloWorld {
def apply(): ReactElement = E.div(A.id := "hello-world")("Hello, World!")
}

object Main extends JSApp {
override def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
val mountNode = dom.document.getElementById("mount-node")
ReactDOM.render(HelloWorld(), mountNode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import io.github.shogowada.scalajs.reactjs.ReactDOM
import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import org.scalajs.dom

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object Main extends JSApp {
def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
object HelloWorld {
def apply(name: String) = <.div(^.id := "hello-world")(s"Hello, ${name}!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.scalajs.reactjs.{React, ReactDOM}
import org.scalajs.dom

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object Main extends JSApp {
def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
case class WrappedProps(name: String)

val reactClass = React.createClass[WrappedProps, Unit](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import io.github.shogowada.scalajs.reactjs.{React, ReactDOM}
import org.scalajs.dom
import org.scalajs.dom.raw.HTMLInputElement

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object Main extends JSApp {
def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
val mountNode = dom.document.getElementById("mount-node")
ReactDOM.render(<(InteractiveHelloWorld()).empty, mountNode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.scalajs.reactjs.{React, ReactDOM}
import org.scalajs.dom

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object App {
case class State(
Expand Down Expand Up @@ -53,8 +53,10 @@ object App {
)
}

object Main extends JSApp {
override def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
val mountNode = dom.document.getElementById("mount-node")
ReactDOM.render(<(App()).empty, mountNode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import io.github.shogowada.scalajs.reactjs.{React, ReactDOM}
import org.scalajs.dom
import org.scalajs.dom.raw.HTMLInputElement

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object Main extends JSApp {
override def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
val store = Redux.createStore[State](
Reducer(_, _),
ReduxDevTools.devToolsEnhancer() // Just add the enhancer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.scalajs.dom.raw.HTMLInputElement

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scala.util.{Failure, Success}

/*
Expand Down Expand Up @@ -106,8 +106,10 @@ object Middleware {
}
}

object Main extends JSApp {
def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
/*
* Use Redux.applyMiddleware to create an enhancer for middlewares.
* You can also use them with ReduxDevTools.composeWithDevTools to enable React DevTools.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.scalajs.dom.raw.HTMLInputElement

import scala.annotation.meta.field
import scala.scalajs.js
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

/*
Expand Down Expand Up @@ -64,8 +63,10 @@ object Reducer {
}
}

object Main extends JSApp {
override def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
/*
* You can use one of the following histories:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.github.shogowada.scalajs.reactjs.{React, ReactDOM}
import org.scalajs.dom
import org.scalajs.dom.raw.HTMLInputElement

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

/*
* If you are not yet familiar with react-router, check it our first:
Expand All @@ -26,8 +26,10 @@ import scala.scalajs.js.JSApp
* - import io.github.shogowada.scalajs.reactjs.router.dom.RouterDOM._
* */

object Main extends JSApp {
override def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
val mountNode = dom.document.getElementById("mount-node")
ReactDOM.render(
<.HashRouter()(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.scalajs.reactjs.elements.ReactElement
import org.scalajs.dom

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object Main extends JSApp {
override def main(): Unit = {
object Main {

@JSExport
def main(args: Array[String]): Unit = {
val mountNode = dom.document.createElement("div")
dom.document.body.appendChild(mountNode)
ReactDOM.render(Main(), mountNode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
package io.github.shogowada.scalajs.reactjs.example

import org.openqa.selenium.UnexpectedAlertBehaviour
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.{ChromeDriver, ChromeOptions}
import org.openqa.selenium.remote.{CapabilityType, DesiredCapabilities}
import org.openqa.selenium.{UnexpectedAlertBehaviour, WebDriver}
import org.scalatest.concurrent.Eventually
import org.scalatest.selenium.{Driver, WebBrowser}
import org.scalatest.{Matchers, path}
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatestplus.selenium._

object BaseTest {
val webDriver = {

private lazy val webDriver: WebDriver = {
val capabilities = new DesiredCapabilities()
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE)
new ChromeDriver(capabilities)
new ChromeDriver(new ChromeOptions().merge(capabilities))
}

Runtime.getRuntime.addShutdownHook(new Thread(() => webDriver.quit()))
}

trait BaseTest extends path.FreeSpec
with WebBrowser with Driver
with Matchers
trait BaseTest extends AnyFreeSpec
with WebBrowser
with Driver
with should.Matchers
with Eventually {
override implicit val webDriver = BaseTest.webDriver

override implicit val patienceConfig: PatienceConfig = PatienceConfig(
timeout = scaled(Span(1, Seconds)),
interval = scaled(Span(50, Millis))
)

implicit val webDriver: WebDriver = BaseTest.webDriver
}
Loading

0 comments on commit caf91a6

Please sign in to comment.