Technofara

Golangエンジニア!仕事で必要になって勉強した事とか、新しい事とか色々まとめたりを緩くやります。技術系と思考系だけにしておきます、

CI導入したいけど、構築とかてまやん?それならTravisCI

nodejsで何かを作ってて、jasmine-nodeで、テストをかいてたりしませんか? しますよね?

サンプルではそんな状況だと仮定して node 0.7 ~ 0.11までを使いCIテストを行いたいと思います。

なぜ、CIを使うのか?とかは今回はスルー

余り纏める時間がないので、nodejs環境構築済み、jasmine-node導入済み前提でいきます!!

package.jsonは以下の様に

{
  "name": "travis_node",
  "version": "1.0.2",
  "main": "index.js",
  "scripts": {
    "test": "node --harmony ./node_modules/jasmine-node/bin/jasmine-node spec"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/shinofara/travis_node.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/shinofara/travis_node/issues"
  },
  "homepage": "https://github.com/shinofara/travis_node",
  "dependencies": {
    "jasmine-node": "~1.13.1"
  },
  "devDependencies": {},
  "directories": {
    "test": "test"
  }
}

もう見覚えありますよね travis化する為にやったことと言えば

node --harmony ./node_modules/jasmine-node/bin/jasmine-node spec

というコマンドを

npm test

で実行出来るようにする為に

  "scripts": {
    "test": "node --harmony ./node_modules/jasmine-node/bin/jasmine-node spec"
  },

と書いたくらいですかね

ここまで来たら、あとはtravis用の設定を書く!!

ファイル名は、 .travis.yml で、内容は

language: node_js
node_js:
  - "0.11"
  - "0.10"
  - "0.8"
  - "0.6"

意味としては、node_jsを使います nodejsのテストを行うversionは0.6,8,10,11で行います

これで、準備は完了ですあとは、 githubのpublicリポジトリを作成して https://github.com/shinofara/travis_node

travisgithub連携をして、travisで使うリポジトリ選択画面がでるので、選択する 僕の場合はtravis_nodeを選択してます。

https://travis-ci.org/shinofara/travis_node こんな感じになれば、せいこう!

いつもどおりざっくり導入手順でした