sbt play cross build project setup: uTest runner doesn't seperate client/server projects correctly

五迷三道 提交于 2019-12-06 11:41:12
Simon Lischka

sjrd's comment about removing aggregate pointed me to right path. Removing it stopped

server/test

from executing both server and client tests. As sjrd pointed out, the aggregate function used also runs every task that is run on server on the client.

Aggregation means that running a task on the aggregate project will also run it on the aggregated projects. (See: sbt doc)

As I also wanted to run shared tests on both client and server project when running test, I modified the aggregate function for the server project definition and added an additional aggregate to the client project definition. :

Server def.:

lazy val server = (project in file("server")).settings(
  scalaVersion := scalaV,
  scalaJSProjects := clients,
  pipelineStages := Seq(scalaJSProd/*, gzip*/),
  resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases",
  libraryDependencies ++= Seq(
    "com.vmunier" %% "play-scalajs-scripts" % "0.3.0",
    "be.doeraene" %% "scalajs-pickling-play-json" % "0.4.0",
    "com.lihaoyi" %% "utest" % "0.3.1" % "test"
  ),
  testFrameworks += new TestFramework("utest.runner.Framework")
).enablePlugins(PlayScala).
  /*
   * Executes shared tests compiled to JVM with server/test
   */
  aggregate(projectToRef(sharedJvm)). // Former: aggregate(clients.map(projectToRef): _*). before
  dependsOn(sharedJvm)

Client def.:

lazy val client = (project in file("client")).settings(
  scalaVersion := scalaV,
  persistLauncher := true,
  persistLauncher in Test := false,
  libraryDependencies ++= Seq(
    "org.scala-js" %%% "scalajs-dom" % "0.8.0"
  ),
  testFrameworks += new TestFramework("utest.runner.Framework")
).enablePlugins(ScalaJSPlugin, ScalaJSPlay).
  /*
   * Executes shared tests compiled to JS with client/test
   */
  aggregate(projectToRef(sharedJs)).
  dependsOn(sharedJs)

When running tests with play-with-scalajs-example/test now runs all tests, including the shared tests both compiled seperately for JS and JVM.

As for having to explicitly include the utest dependencies, it seems that client and server projects don't derive from crossProject and are thus disconnected - will look into finding a better way of handling that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!