scala-js/scala-2.12-junit-mixin-plugin

Incomplete setup documentation

Closed this issue · 2 comments

For the shapeless build for 2.12.0-M5 I followed the instructions in the README and saw the following,

[error] (coreJS/compile:compileIncremental)
  scala.reflect.internal.MissingRequirementError:
    object org.junit.Test in compiler mirror not found.

both when building for the JVM and JS. The fix in my case was to depend on junit-interface everywhere,

@@ -60,9 +60,9 @@ lazy val commonSettings = Seq(
 def configureJUnit(crossProject: CrossProject) = {
   crossProject
   .jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
-  .jvmSettings(
+  .settings(
     libraryDependencies +=
-      "com.novocode" % "junit-interface" % "0.9" % "test"
+      "com.novocode" % "junit-interface" % "0.9"
   )
 }
sjrd commented

Ah, that is an issue. You shouldn't have to depend on junit-interface in your compile configuration. This might also explain the linking errors you were experiencing, since you have the JVM artifact of junit-interface in the classpath of your JS project, which will cause clashes.

Try with this alternative configuration:

    /* The `test-plugin` configuration adds a plugin only to the `test`
     * configuration. It is a refinement of the `plugin` configuration which adds
     * it to both `compile` and `test`.
     */
    ivyConfigurations += config("test-plugin").hide,
    libraryDependencies ++= {
      if (scalaVersion.value.startsWith("2.12."))
        Seq("org.scala-js" % "scala-junit-mixin-plugin" % "0.1.0" % "test-plugin" cross CrossVersion.full)
      else
        Seq.empty
    },
    scalacOptions in Test ++= {
      val report = update.value
      val jars = report.select(configurationFilter("test-plugin"))
      for {
        jar <- jars
        jarPath = jar.getPath
        // This is a hack to filter out the dependencies of the plugins
        if jarPath.contains("plugin")
      } yield {
        s"-Xplugin:$jarPath"
      }
    }

That did the trick ... thanks.