-
Notifications
You must be signed in to change notification settings - Fork 8
/
karma.clj
35 lines (32 loc) · 1.11 KB
/
karma.clj
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
(ns jx.reporter.karma
(:require [cljs.env :as env]
[cljs.analyzer :as ana]
[cljs.analyzer.api :as api]))
(defmacro tests-count
[& namespaces]
`(+ ~@(map (fn [[_ ns]]
(count
(filter #(true? (get-in % [1 :test]))
(cljs.analyzer.api/ns-publics ns))))
namespaces)))
(defmacro run-tests
"Runs all tests in the given namespaces."
[karma & namespaces]
`(if (nil? ~karma)
(cljs.test/run-tests ~@namespaces)
(do (jx.reporter.karma/start ~karma (tests-count ~@namespaces))
(cljs.test/run-tests (cljs.test/empty-env ::karma) ~@namespaces))))
(defmacro run-all-tests
"Runs all tests in all namespaces.
Optional argument is a regular expression; only namespaces with
names matching the regular expression (with re-matches) will be
tested."
([karma]
`(jx.reporter.karma/run-all-tests ~karma #".*"))
([karma re]
`(jx.reporter.karma/run-tests
~karma
~@(into '()
(comp (filter #(re-matches re (name %)))
(map (fn [ns] `(quote ~ns))))
(api/all-ns)))))