/
test_runner.cljs
41 lines (31 loc) · 1.39 KB
/
test_runner.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(ns rand-cljc.test-runner
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :refer [timeout chan >! <! put!]]
[cljs.test :refer-macros [run-tests] :refer [empty-env report]]
[rand-cljc.core-test]))
(enable-console-print!)
;; As of CLJS-988's implementation, cljs.test doesn't give us a way to
;; get the test report summary map back from (run-tests) and friends
;; -- (run-tests) always returns nil. So, we have to keep track, very
;; statefully, of the error count ourselves. Delegating to the default
;; implementation of these methods performs the printing.
(def error-count (atom 0))
(defmethod report [::test :pass] [m]
((get-method report [:cljs.test/default :pass]) m))
(defmethod report [::test :begin-test-ns] [m]
((get-method report [:cljs.test/default :begin-test-ns]) m))
(defmethod report [::test :error] [m]
(swap! error-count inc)
((get-method report [:cljs.test/default :error]) m))
(defmethod report [::test :fail] [m]
(swap! error-count inc)
((get-method report [:cljs.test/default :fail]) m))
(defmethod report [::test :summary] [m]
((get-method report [:cljs.test/default :summary]) m))
(defn runner
[]
(run-tests (empty-env ::test) 'rand-cljc.core-test)
;; The phantomjs test runner expects this variable to be set. See
;; phantom/test.js.
(set! (.-rand_cljc_error_count js/window) @error-count))
(runner)