I am working on a web app that's built atop Play Framework.
The goal I want to achieve is to create a custom sbt task that works like this:
- start the play application
- run my custom task (functional tests written in javascript that depends on the running application)
- stop the application after my custom task is done
Now I am stuck on step two.
I have this sbt script that's working:
lazy val anotherTask = taskKey[Unit]("run this first")
lazy val myCustomTask = taskKey[Unit]("try to run shell in sbt")
anotherTask := {
println("i am the first task")
}
myCustomTask := {
println("try to run shell")
import scala.sys.process._
println("git status" !!)
println("the shell command worked, yeah!")
}
myCustomTask <<= myCustomTask.dependsOn(anotherTask)
But if I try to make myCustomTask
depend on the run
task (which starts the play app) by modifying the script like this:
myCustomTask <<= myCustomTask.dependsOn(runTask _)
I get the following error:
error: type mismatch; found : (sbt.Configuration, String, Seq[String]) => sbt.Def.Initialize[sbt.Task[Unit]] required: sbt.Scoped.AnyInitTask (which expands to) sbt.Def.Initialize[sbt.Task[T]] forSome { type T }
How should I solve this problem?
At last, I ended up with a specs2 class like this:
"my app" should {
"pass the protractor tests" in {
running(TestServer(9000)) {
Await.result(WS.url("http://localhost:9000").get, 2 seconds).status === 200
startProtractor(getProcessIO) === 0
}
}
}
private def startProtractor(processIO: ProcessIO): Int = {
Process("protractor", Seq( """functional-test/config/buildspike.conf.js"""))
.run(processIO)
.exitValue()
}
private def getProcessIO: ProcessIO = {
new ProcessIO(_ => (),
stdout => fromInputStream(stdout).getLines().foreach(println),
_ => ())
}