I\'m using SBT with Play Framework.
I created a custom TaskKey
to run JavaScript tests in my project:
import sbt._
import sbt.Process._
Play 2.2.x uses SBT 0.13 (see What’s new in Play 2.2). That brings some new means of composing tasks in build.sbt
itself (without resorting to a Scala file in project/
subdirectory).
If you happen to use Play 2.2.x you could define the dependency between the tasks in build.sbt
as follows:
lazy val testJsTask = taskKey[Unit]("Run JavaScript tests.")
testJsTask := {
println("Running JavaScript tests...")
java.util.concurrent.TimeUnit.SECONDS.sleep(3)
println("...done.")
}
test in Test := {
testJsTask.value
(test in Test).value
}
See Tasks in the official documentation of SBT for more details.
This is one way to do it:
Define the task key:
val testJsTask = TaskKey[Unit]("testJs", "Run javascript tests.")
Define the task in your projects settings:
testJsTask <<= testJs
Make test dependent on it:
(test in Test) <<= (test in Test) dependsOn (testJs)
testJs can be defined as follows:
def testJs = (streams) map { (s) => {
s.log.info("Executing task testJs")
// Your implementation
}
[EDIT] You have to define the task dependencies within the projects settings. For a "normal" project, you would do it the following way:
lazy val testProject = Project(
"testProject",
file("testProject"),
settings = defaultSettings ++ Seq(
testJsTask <<= testJs,
(test in Test) <<= (test in Test) dependsOn (testJsTask)
)
)