generator-angularでつくったプロジェクトでE2Eテストを実行する

モリモリ盛り上がってるAngularJSのプロジェクトひな形を作ってくれるgenerator-angular でE2Eテストをするためのメモ。

$ yo angular

でひな形をつくった時点で、

$ grunt test

でユニットテストをすぐ実行することができる。
が、E2Eテストを実行するタスクが見当たらない。
karma-e2e.conf.js というE2Eテスト用のkarmaの設定ファイルはつくられている。

ということで、karma-e2e.conf.jsのこの部分を

// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
//   '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'

コメントアウトする。

// Uncomment the following lines if you are using grunt's server to run the tests
proxies: {
  '/': 'http://localhost:9000/'
},
// URL root prevent conflicts with the site root
urlRoot: '_karma_'

testディレクトリ以下にe2eというディレクトリをつくって

$ mkdir test/e2e

この下にE2Eのテストを置く。

test/e2e/sample.js
describe('E2E: Testing Routes:',  function () {
  'use strict';

  beforeEach(function() {
    browser().navigateTo('/');
  });

  it('should display message',  function() {
    var message = element('h1').text();
    expect(message).toEqual("'Allo,  'Allo!");
  });
});

そして、おもむろにターミナルでサーバーを起動して。。

$ grunt serve

さらに別のターミナルでkarmaコマンドを叩けばtest/e2e以下のE2Eテストが実行される。

$ karma start karma-e2e.conf.js

どうもE2Eテストのあり方が定まっていないらしく、現在こういう中途半端な状態になっている模様です。
Add an E2E Spec When a View is Created

Comments