LoginSignup
23
25

More than 5 years have passed since last update.

Circle CIを使ったNode.jsプロジェクトのテスト

Last updated at Posted at 2014-02-16

話題のCircle CIをNode.jsで試してみる。
Continuous Integration and Deployment - CircleCI

Githubプロジェクトの用意

まず、Githubにプロジェクトを用意。

今回は以下のような最小限のプロジェクトを用意。テストライブラリはMochaを利用。

calc.js : テスト対象

exports.add = function(x, y){
  return x + y;
}

test/calc.js : テストスクリプト

var expect = require('expect.js');

describe('calc', function(){
  it('add', function(){
    expect(1+1).to.be(2);
  });
});

test/mocha.opts : Mochaのオプションファイル

--reporter spec
--ui bdd
--timeout 3000

package.json : 依存ライブラリとテストスクリプトの設定を記述

{
  "name": "circle-node",
  "devDependencies": {
    "mocha": "~1.17.1",
    "expect.js": "~0.2.0"
  },
  "scripts": {
    "test": "./node_modules/.bin/mocha"
  }
}

Circle CIの画面上の操作

Circle CIは2週間であればトライアルで無料で使える。

プロジェクトの追加画面から対象のプロジェクトの"Setup"ボタンをクリックするとさっそくビルドが始まる。

gaishimo_-_CircleCI.png

しばらくすると、、、

テストが無事、実行された!

とてもあっけなく。。

_3_-_gaishimo_circle-node_-_CircleCI.png

package.json で scripts.test の記述をしておけば、Circle CIが自動で判断してくれてそれを実行してくれる。また、npm install も勝手にやってくれるので特に設定をする必要はない。

circle.yml

もしも細かな独自設定が必要になった場合は、circle.ymlファイルに記述する。
Configuring CircleCI - CircleCI

例えばNode.jsのバージョンを指定する場合は以下のように記述する。

machine:
  node:
    version: 0.11.11
23
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
25