/
test.clj
47 lines (40 loc) · 2.08 KB
/
test.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
36
37
38
39
40
41
42
43
44
45
46
47
(ns caioaao.kaocha-greenlight.test
(:require [clojure.spec.alpha :as s]
[clojure.test :as t]
[com.stuartsierra.component :as component]
[kaocha.hierarchy :as hierarchy]
[kaocha.load :as load]
[kaocha.testable :as testable]
[kaocha.type.ns :as type.ns]
[caioaao.kaocha-greenlight.report]))
(defn- ns->testable [ns]
(assoc (type.ns/->testable ns) :kaocha.testable/type ::ns))
(defn get-system [system-fn-symbol]
(let [ns-name (symbol (namespace system-fn-symbol))]
(when-not (find-ns ns-name)
(require ns-name))
((resolve system-fn-symbol))))
(defmethod testable/-load :caioaao.kaocha-greenlight/test
[{:caioaao.kaocha-greenlight/keys [new-system] :as testable}]
(assoc (load/load-test-namespaces testable ns->testable)
::testable/desc (str (name (::testable/id testable)) " (greenlight)")
:caioaao.kaocha-greenlight/system (get-system new-system)))
;; TODO add configuration parameter to restart system on each name space instead of here
(defmethod testable/-run :caioaao.kaocha-greenlight/test
[{:caioaao.kaocha-greenlight/keys [system] :as testable} test-plan]
(t/do-report {:type :begin-test-suite})
(let [system (component/start system)
results (try
(testable/run-testables (:kaocha.test-plan/tests testable)
(assoc test-plan ::system system))
(finally (component/stop system)))
testable (-> testable
(dissoc :kaocha.test-plan/tests)
(assoc :kaocha.result/tests results))]
(t/do-report {:type :end-test-suite})
testable))
(s/def :caioaao.kaocha-greenlight/new-system symbol?)
(s/def :caioaao.kaocha-greenlight/test (s/keys :req [::testable/type ::testable/id
:kaocha/ns-patterns :kaocha/source-paths :kaocha/test-paths
:caioaao.kaocha-greenlight/new-system]))
(hierarchy/derive! :caioaao.kaocha-greenlight/test :kaocha.testable.type/suite)