From 6e8e3d8316bf91b11a8cd6a3272fbe0935d76e16 Mon Sep 17 00:00:00 2001
From: Tom Robinson <tlrobinson@gmail.com>
Date: Wed, 28 Sep 2016 22:32:53 -0700
Subject: [PATCH] Use junit xml reporters so Circle can report them more better

---
 .gitignore                        | 2 ++
 frontend/test/e2e/support/init.js | 7 +++++++
 frontend/test/karma.conf.js       | 6 +++++-
 package.json                      | 2 ++
 project.clj                       | 7 +++++--
 5 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index adac85c4d34..fe994e13fd6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,3 +42,5 @@ bin/release/aws-eb/metabase-aws-eb.zip
 /npm-debug.log
 /screenshots
 /plugins
+/build.xml
+/test-report-*
diff --git a/frontend/test/e2e/support/init.js b/frontend/test/e2e/support/init.js
index 35f574a755d..7314de0651c 100644
--- a/frontend/test/e2e/support/init.js
+++ b/frontend/test/e2e/support/init.js
@@ -8,3 +8,10 @@ if (!global.jasmineRequire) {
     global.jasmineRequire = jasmineRequire;
 }
 require('jasmine-promises');
+
+var jasmineReporters = require('jasmine-reporters');
+var junitReporter = new jasmineReporters.JUnitXmlReporter({
+    savePath: (process.env["CIRCLE_TEST_REPORTS"] || ".") + "/test-report-e2e",
+    consolidateAll: false
+});
+jasmine.getEnv().addReporter(junitReporter);
diff --git a/frontend/test/karma.conf.js b/frontend/test/karma.conf.js
index 0ca65f241d2..20644aae5a4 100644
--- a/frontend/test/karma.conf.js
+++ b/frontend/test/karma.conf.js
@@ -22,7 +22,8 @@ module.exports = function(config) {
         ],
         reporters: [
             'progress',
-            'coverage'
+            'coverage',
+            'junit'
         ],
         webpack: {
             resolve: webpackConfig.resolve,
@@ -42,6 +43,9 @@ module.exports = function(config) {
                 { type: 'html' }
             ]
         },
+        junitReporter: {
+            outputDir: (process.env["CIRCLE_TEST_REPORTS"] || "..") + "/test-report-frontend"
+        },
         port: 9876,
         colors: true,
         logLevel: config.LOG_INFO,
diff --git a/package.json b/package.json
index 7d48eb6ea57..687d251fb10 100644
--- a/package.json
+++ b/package.json
@@ -100,12 +100,14 @@
     "jasmine": "^2.4.1",
     "jasmine-core": "^2.4.1",
     "jasmine-promises": "^0.4.1",
+    "jasmine-reporters": "^2.2.0",
     "jasmine-spec-reporter": "^2.7.0",
     "json-loader": "^0.5.4",
     "karma": "^0.13.9",
     "karma-chrome-launcher": "^0.2.0",
     "karma-coverage": "^0.5.3",
     "karma-jasmine": "^0.3.5",
+    "karma-junit-reporter": "^1.1.0",
     "karma-nyan-reporter": "^0.2.2",
     "karma-webpack": "^1.7.0",
     "loader-utils": "^0.2.12",
diff --git a/project.clj b/project.clj
index eec13d8828f..d09fe208aed 100644
--- a/project.clj
+++ b/project.clj
@@ -71,7 +71,8 @@
                  [ring/ring-jetty-adapter "1.5.0"]                    ; Ring adapter using Jetty webserver (used to run a Ring server for unit tests)
                  [ring/ring-json "0.4.0"]                             ; Ring middleware for reading/writing JSON automatically
                  [stencil "0.5.0"]                                    ; Mustache templates for Clojure
-                 [swiss-arrows "1.0.0"]]                              ; 'Magic wand' macro -<>, etc.
+                 [swiss-arrows "1.0.0"]                               ; 'Magic wand' macro -<>, etc.
+                 [test2junit "1.2.2"]]                                ; Output test results in JUnit style for CI
   :repositories [["bintray" "https://dl.bintray.com/crate/crate"]]
   :plugins [[lein-environ "1.0.3"]                                    ; easy access to environment variables
             [lein-ring "0.9.7"                                        ; start the HTTP server with 'lein ring server'
@@ -82,6 +83,7 @@
   :jvm-opts ["-Djava.awt.headless=true"]                              ; prevent Java icon from randomly popping up in dock when running `lein ring server`
   :javac-options ["-target" "1.7", "-source" "1.7"]
   :uberjar-name "metabase.jar"
+  :test2junit-output-dir (str (or (System/getenv "CIRCLE_TEST_REPORTS") ".") "/test-report-backend")
   :ring {:handler metabase.core/app
          :init metabase.core/init!
          :destroy metabase.core/destroy}
@@ -109,7 +111,8 @@
                              [lein-expectations "0.0.8"]              ; run unit tests with 'lein expectations'
                              [lein-instant-cheatsheet "2.2.1"         ; use awesome instant cheatsheet created by yours truly w/ 'lein instant-cheatsheet'
                               :exclusions [org.clojure/clojure
-                                           org.clojure/tools.namespace]]]
+                                           org.clojure/tools.namespace]]
+                             [test2junit "1.2.2"]]
                    :env {:mb-run-mode "dev"}
                    :jvm-opts ["-Dlogfile.path=target/log"
                               "-Xms1024m"                             ; give JVM a decent heap size to start with
-- 
GitLab