如何在“运行"时运行自定义任务(用量角器编写的功能测试).任务已启动并正在运行? [英] How to run a custom task(functional tests written in protractor) while the "run" task is up and running?

查看:76
本文介绍了如何在“运行"时运行自定义任务(用量角器编写的功能测试).任务已启动并正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于Play框架构建的网络应用.

I am working on a web app that's built atop Play Framework.

我要实现的目标是创建一个自定义sbt任务,其工作方式如下:

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

  1. 启动播放应用程序
  2. 运行我的自定义任务(取决于正在运行的应用程序,使用javascript编写的功能测试)
  3. 自定义任务完成后停止应用程序

现在,我被困在第二步.

Now I am stuck on step two.

我有这个正在工作的sbt脚本:

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)

但是,如果我尝试通过修改如下脚本来使myCustomTask依赖于run任务(启动播放应用程序),则该脚本:

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 _)

我收到以下错误:

错误:类型不匹配;找到:(sbt.Configuration,String, Seq [String])=> sbt.Def.Initialize [sbt.Task [Unit]]必需: sbt.Scoped.AnyInitTask (扩展为)sbt.Def.Initialize [sbt.Task [T]] forSome {type T}

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?

最后,我最终得到了一个specs2类,如下所示:

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

推荐答案

运行是

Run is an Input Task, if you want to use it in conjunction with a normal task, you have to convert it to a task first.

您可以使用toTask方法从输入任务中获取任务,如

You can get a task from an input task by using toTask method as it is described in the documentation.

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

这篇关于如何在“运行"时运行自定义任务(用量角器编写的功能测试).任务已启动并正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆