How to run a custom task (functional tests written in the protractor) when the "run" task is running?

I am working on a web application built on top of the Play Framework.

The goal I want to achieve is to create a custom sbt task that works like this:

  • start playback application
  • run my custom task (functional tests written in javascript that depend on the running application)
  • stop app after my custom task is done

Now I am stuck on the second step.

I have this sbt script that works:

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 it myCustomTask

depend on the task run

(which launches the application to play) by changing the script like this:

myCustomTask <<= myCustomTask.dependsOn(runTask _)

      

I am getting the following error:

error: type of mismatch; found: (sbt.Configuration, String, Seq [String]) => sbt.Def.Initialize [sbt.Task [Unit]] requires: sbt.Scoped.AnyInitTask (which expands to) sbt.Def.Initialize [sbt.Task [T]] forSome {type T}

How can I solve this problem?

Finally, I ended up with a specs2 class:

  "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),
      _ => ())
  }

      

+2


source to share


2 answers


Launch is an Input Task , if you want to use it in combination with a normal task, you need to convert it to a task first.

You can get an assignment from an input task using a method toTask

as described in the documentation .



myCustomTask <<= myCustomTask.dependsOn((run in Compile).toTask(""))

      

+4


source


I would use the following to depend on the task run

:

myCustomTask <<= myCustomTask dependsOn run

      

When changing the assembly, I also used the sbt.Process API to execute git status

.



"git version".!

      

It should work fine (r) with changes.

0


source







All Articles