title: How to attach custom task to execute before the test task in sbt?
body: <p>I'm using SBT with Play Framework.</p>
  
  <p>I created a custom <code>TaskKey</code> to run JavaScript tests in my project:</p>
  
  <pre><code>import sbt._
  import sbt.Process._
  import PlayProject._
  
  object ApplicationBuild extends Build {
  
    val testJsTask = TaskKey[Unit]("testJs", "Run javascript tests.") := {}
  
    val main = PlayProject("xxx", 1.0, Seq())
      .settings(defaultScalaSettings: _*)
      .settings(testJsTask)
  }
  </code></pre>
  
  <p>So far so good.</p>
  
  <p>I want to run this <code>testJsTask</code> always when someone executes the <code>test</code> task.</p>
  
  <p>I guess it should be something as follows:</p>
  
  <pre><code>test in Test &lt;&lt;= (test in Test).dependsOn(testJsTask)
  </code></pre>
  
  <p>I've no idea how it should be defined exactly. How to add a dependency to an existing task like 'test' or 'build'?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After changes proposed by @Christian the build definition looks as follows:</p>
  
  <pre><code>object ApplicationBuild extends Build {
    val testJsTask = TaskKey[Unit]("testJs", "Run tests for javascript client.")
    def testJs = {}
  
    val main = PlayProject("xxx", 1.0, Seq())
      .settings(defaultScalaSettings: _*)
      .settings(testJsTask := testJs)
  
    (test in Test) &lt;&lt;= (test in Test) dependsOn (testJs)
  }
  </code></pre>
  
  <p>Unfortunately, the solution doesn't work either:</p>
  
  <pre><code>[error] /xxx/project/Build.scala:21: not found: value test
  [error]   (test in Test) &lt;&lt;= (test in Test) dependsOn (testJs)
  [error]    ^
  [error] one error found
  [error] {file:/xxx/project/}default-f468ae/compile:compile: Compilation failed
  </code></pre>