nuteup/karma-cljs.test — pull request #1 by codenarian (2014-12-22 04:38:45+00:00)
Title: Add ability to configure adapter

This changeset generalizes the usefulness of this adapter. Instead of
hard-coding the bootstrapping namespace, it can be configured in the
karma config as follows:

```js
module.exports = function(config) {
config.set({

...

frameworks: ["cljsTest"],

client: {
cljsTest: {
main: "my-tests.namespace",
entry: "run-all-the-karma-tests" // optional: defaults to `run`.
}
},

...
})
};
```

In the example given above, the adapter expects the find the following:

```clj
(ns my-tests.namespace
(:require [clojure.string :as string]
[cemerick.cljs.test :as test]))

(defn get-total-test-count []
(reduce + (map count (vals @test/registered-tests))))

(defn run-karma-test! [test-name test]
(let [log-output (atom '())
start (.getTime (js/Date.))]
(test/set-print-fn! (fn [x] (swap! log-output conj x)))
(let
;; [{:result result :time time} (run-test-with-time test)]
[result (test/test-function test)]
(.result js/__karma__
(clj->js
{ "id" ""
"description" (-> test-name name)
"suite" [(-> test-name namespace str)]
"success" (and (zero? (:error result))
(zero? (:fail result)))
"skipped" nil
"time" (- (.getTime (js/Date.)) start)
"log" [(string/join "\n" (reverse @log-output))]})))))

(defn ^:export run-all-the-karma-tests []
(do (.info js/__karma__ (clj->js {:total (get-total-test-count)}))
(doseq [[ns ns-tests] @test/registered-tests ]
(doseq [[test-name test] ns-tests]
(run-karma-test! test-name test)))
(.complete js/__karma__ (clj->js {}))))

```

TODO: Add docs.