LoginSignup
1
0

More than 5 years have passed since last update.

Karma で走らせたテストの結果を CircleCI で集計する

Posted at

CircleCI の案内に Karma が無かったので書いておく.

前提

Karma 1.3.0 以上
CircleCI は 2016/11/06 時点

karma-junit-reporter を追加

CircleCI では Cucumber JSON か JUnit XML の形式がサポートされているので, JUnit 形式で出力してくれる npm パッケージを npm の依存関係に追加する.
bash
npm install karma-junit-reporter --save-dev

karma.conf.js を編集

注意するのは,CircleCI のレポート出力先は環境変数で指定しなければいけないので,Karma の設定ファイル内で環境変数を読む必要があるところ.Node.js の process.env が使える.
ローカルで回したときはレポート用の JUnit は必要ないけれども,一応ビルド成果物の出るディレクトリ (下の例なら dist) に吐き出しておく.

 module.exports = function(config) {

+  var reportDir = process.env['CIRCLE_TEST_REPORTS'] || 'dist/tests';

   config.set({
     ...
     plugins: [
       ...
+      'karma-junit-repoter'
     ],
     ...
     reporters: [
       'dots',
+      'junit'
     ],
+    junitReporter: {
+      outputDir: reportDir + '/junit',
+      outputFile: 'test-results.xml',
+      suite: '',
+      useBrowserName: false
+   },
  ...
   })
 }
1
0
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
1
0