reagent/test/runtests.cljs

57 lines
1.5 KiB
Plaintext
Raw Normal View History

2013-12-16 22:19:36 +00:00
(ns runtests
2014-11-29 22:47:57 +00:00
(:require [testreagent]
[testcursor]
[testinterop]
[testratom]
2014-12-03 13:50:03 +00:00
[testwrap]
[cemerick.cljs.test :as t]
[reagent.core :as reagent :refer [atom]]
[reagent.interop :refer-macros [.' .!]]
2014-11-29 22:47:57 +00:00
[reagent.debug :refer-macros [dbg println]]))
2013-12-16 22:19:36 +00:00
2014-11-29 22:47:57 +00:00
(enable-console-print!)
2013-12-16 22:19:36 +00:00
(def test-results (atom nil))
(def test-box {:position 'absolute
:margin-left -35
:color :#aaa})
2013-12-16 22:19:36 +00:00
(defn test-output []
(let [res @test-results]
[:div {:style test-box}
2013-12-16 22:19:36 +00:00
(if-not res
[:div "waiting for tests to run"]
[:div
[:p (str "Ran " (:test res) " tests containing "
(+ (:pass res) (:fail res) (:error res))
" assertions.")]
[:p (:fail res) " failures, " (:error res) " errors."]])]))
2013-12-16 22:19:36 +00:00
(defn test-output-mini []
(let [res @test-results]
(if res
(if (zero? (+ (:fail res) (:error res)))
[:div {:style test-box}
"All tests ok"]
[test-output])
[:div {:style test-box} "testing"])))
(defn ^:export run-all-tests []
(println "-----------------------------------------")
(try
(reset! test-results (t/run-all-tests))
(catch js/Object e
(do
(println "Testrun failed\n" e "\n" (.-stack e))
(reset! test-results {:error e}))))
(println "-----------------------------------------"))
(defn ^:export run-tests []
(if reagent/is-client
(do
(reset! test-results nil)
(js/setTimeout run-all-tests 100))
(run-all-tests)))