くりにっき

フルスタックキュアエンジニアです

JenkinsでJavaScriptのテストをやってみる

調べてたらphantomjsを使うかnodeを使うかの2つが主流だったのですが、自分の場合元々phantomjsでの自動テストの仕組みがあったため前者でいくことにしました。

phantomjsでのJavaScriptのテストの自動化については過去のエントリを御覧ください

AZusaar! を全面リファクタリングしました - くりにっき

1. phantomjsをインストールする

Build Instructions を参考にコンパイルする。

build.shの冒頭で

----------------------------------------
               WARNING
----------------------------------------

Building PhantomJS from source takes a very long time, anywhere from 30 minutes
to several hours (depending on the machine configuration). It is recommended to
use the premade binary packages on supported operating systems.

For details, please go the the web site: http://phantomjs.org/download.html.

とあるようにコンパイルにすごく時間がかかります。

参考

  • さくらVPS 2G: 15〜20分くらい
  • EC2 micro: 一晩w

無事コンパイルができたらパスが通っているところにバイナリをコピーします

sudo cp bin/phantomjs /usr/local/bin/

バイナリで43MBとかどういうことですか (;´Д`)

$ ls -l /usr/local/bin/phantomjs
-rwxr-xr-x 1 root root 43212931  116 01:44 2013 /usr/local/bin/phantomjs

3. ジョブの設定

TAPの結果をファイルに出力して、それをTAP pluginに食わせてやればOK

自分の場合はこんな感じ
f:id:sue445:20130120000452p:plain

./test/phantomjs_test.sh の中身はこういう風になっています
https://github.com/sue445/azusaar_js/blob/master/test/phantomjs_test.sh