2016-05-01 13:45:37 +02:00
|
|
|
(ns reagenttest.runtests
|
2015-02-10 14:18:56 +01:00
|
|
|
(:require [reagenttest.testreagent]
|
|
|
|
[reagenttest.testcursor]
|
|
|
|
[reagenttest.testratom]
|
2015-09-12 18:34:10 +02:00
|
|
|
[reagenttest.testratomasync]
|
2015-09-19 19:03:29 +02:00
|
|
|
[reagenttest.testtrack]
|
2015-09-23 17:02:48 +02:00
|
|
|
[reagenttest.testwithlet]
|
2015-02-10 14:18:56 +01:00
|
|
|
[reagenttest.testwrap]
|
2018-04-27 23:17:25 +03:00
|
|
|
[reagent.impl.template-test]
|
2018-12-03 16:10:19 -06:00
|
|
|
[reagent.impl.util-test]
|
2019-12-17 14:32:45 +02:00
|
|
|
[clojure.test :as test]
|
2017-11-28 17:12:29 +02:00
|
|
|
[doo.runner :as doo :include-macros true]
|
2020-04-13 01:32:06 +03:00
|
|
|
[jx.reporter.karma :as karma]
|
2019-12-17 14:32:45 +02:00
|
|
|
[reagent.core :as r]))
|
2015-01-31 23:09:42 +01:00
|
|
|
|
2014-11-29 23:47:57 +01:00
|
|
|
(enable-console-print!)
|
2013-12-16 23:19:36 +01:00
|
|
|
|
2015-07-31 15:13:27 +02:00
|
|
|
(def test-results (r/atom nil))
|
2013-12-16 23:19:36 +01:00
|
|
|
|
2015-02-10 18:20:48 +01:00
|
|
|
(def test-box-style {:position 'absolute
|
|
|
|
:margin-left -35
|
|
|
|
:color :#aaa})
|
|
|
|
|
|
|
|
(defn all-tests []
|
2018-04-27 23:17:25 +03:00
|
|
|
(test/run-all-tests #"(reagenttest\.test.*|reagent\..*-test)"))
|
2015-02-10 18:20:48 +01:00
|
|
|
|
2015-02-10 14:18:56 +01:00
|
|
|
(defmethod test/report [::test/default :summary] [m]
|
|
|
|
;; ClojureScript 2814 doesn't return anything from run-tests
|
|
|
|
(reset! test-results m)
|
|
|
|
(println "\nRan" (:test m) "tests containing"
|
|
|
|
(+ (:pass m) (:fail m) (:error m)) "assertions.")
|
|
|
|
(println (:fail m) "failures," (:error m) "errors."))
|
|
|
|
|
2016-04-29 13:17:54 +02:00
|
|
|
(defn run-tests []
|
|
|
|
(reset! test-results nil)
|
|
|
|
(if r/is-client
|
|
|
|
(js/setTimeout all-tests 100)
|
|
|
|
(all-tests)))
|
|
|
|
|
2014-01-06 19:16:53 +01:00
|
|
|
(defn test-output-mini []
|
|
|
|
(let [res @test-results]
|
2016-04-29 13:17:54 +02:00
|
|
|
[:div {:style test-box-style
|
|
|
|
:on-click run-tests}
|
2015-02-10 18:20:48 +01:00
|
|
|
(if res
|
|
|
|
(if (zero? (+ (:fail res) (:error res)))
|
|
|
|
"All tests ok"
|
|
|
|
[:span "Test failure: "
|
|
|
|
(:fail res) " failures, " (:error res) " errors."])
|
|
|
|
"testing")]))
|
|
|
|
|
2015-03-21 13:53:37 +01:00
|
|
|
(defn init! []
|
2017-10-18 14:25:41 +03:00
|
|
|
;; This function is only used when running tests from the demo app.
|
|
|
|
;; Which is why exit-point is set manually.
|
2015-03-21 13:53:37 +01:00
|
|
|
(when (some? (test/deftest empty-test))
|
2017-10-18 14:25:41 +03:00
|
|
|
(doo/set-exit-point! (fn [success?] nil))
|
|
|
|
(run-tests)
|
|
|
|
[#'test-output-mini]))
|
2015-03-21 13:53:37 +01:00
|
|
|
|
2020-04-13 01:32:06 +03:00
|
|
|
;; Macro which sets *main-cli-fn*
|
2018-04-27 23:17:25 +03:00
|
|
|
(doo/doo-all-tests #"(reagenttest\.test.*|reagent\..*-test)")
|
2020-04-13 01:32:06 +03:00
|
|
|
|
|
|
|
(defn ^:export karma-tests [karma]
|
|
|
|
(karma/run-all-tests karma #"(reagenttest\.test.*|reagent\..*-test)"))
|
|
|
|
|
|
|
|
(when (exists? js/window)
|
|
|
|
(when-let [f (some-> js/window .-__karma__ .-loaded_real)]
|
|
|
|
(.loaded_real (.-__karma__ js/window))))
|