Gradle のタスクで JsTestDriver を実行する。
eriwen/gradle-js-plugin の issue を参考にして、ここでは JsTestDriver.jar を maven central repository からダウンロードして使うように変更してみた。
build.groovy
configurations {
jsTestDriver
}
dependencies {
jsTestDriver 'com.google.jstestdriver:jstestdriver:1.3.5'
}
task jstd(type: Exec, description: 'runs JS tests through JsTestDriver') {
def firefoxPath = '/Applications/Firefox.app/Contents/MacOS/firefox'
if ("uname".execute().text.trim() != 'Darwin') {
firefoxPath = "which firefox".execute().text
}
commandLine = [
'/usr/bin/env',
'DISPLAY=:1',
'java',
'-jar', configurations.jsTestDriver.asPath,
'--config', "${projectDir}/src/test/resources/jsTestDriver.conf",
'--port', '4224',
'--browser', firefoxPath,
'--tests', 'all',
'--testOutput', buildDir,
'--basePath', projectDir
]
}
実行結果
% gradle jstd
:jstd
setting runnermode QUIET
.....Total 5 tests (Passed: 5; Fails: 0; Errors: 0) (2.00 ms)
Firefox 21.0 Mac OS: Run 5 tests (Passed: 5; Fails: 0; Errors 0) (2.00 ms)
BUILD SUCCESSFUL
Total time: 5.194 secs
これならシェルスクリプトで curl -O JsTestDriver.jar して java -jar JsTestDriver.jar するようなものだけど、groovy で書けることとビルドに必要な機能が備わっていることと、ビルドファイルとしてまとまっている点で Gradle で実行すると便利だと思う。