cljs tests are in
This commit is contained in:
parent
4b6a4b1658
commit
3fc53f747e
7 changed files with 170 additions and 8 deletions
|
|
@ -8,6 +8,11 @@
|
|||
mount.test.fun-with-values
|
||||
mount.test.private-fun
|
||||
mount.test.parts
|
||||
mount.test.cleanup-dirty-states
|
||||
mount.test.stop-except
|
||||
mount.test.start-without
|
||||
mount.test.start-with
|
||||
mount.test.suspend-resume
|
||||
))
|
||||
|
||||
(mount.core/in-cljc-mode)
|
||||
|
|
@ -19,6 +24,11 @@
|
|||
'mount.test.fun-with-values
|
||||
'mount.test.private-fun
|
||||
'mount.test.parts
|
||||
'mount.test.cleanup-dirty-states
|
||||
'mount.test.stop-except
|
||||
'mount.test.start-without
|
||||
'mount.test.start-with
|
||||
'mount.test.suspend-resume
|
||||
))
|
||||
|
||||
(defn run-tests []
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
(ns mount.test.cleanup_dirty_states
|
||||
(ns mount.test.cleanup-dirty-states
|
||||
(:require
|
||||
#?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer-macros [defstate]]
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
:clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer [defstate]]
|
||||
[app.example]])
|
||||
[mount.test.helper :refer [dval]]))
|
||||
[mount.test.helper :refer [dval helper forty-two]]))
|
||||
|
||||
#?(:clj
|
||||
(deftest cleanup-dirty-states
|
||||
|
|
@ -19,3 +19,16 @@
|
|||
(is (not (.isClosed (:server-socket (dval app.example/nrepl)))))
|
||||
(mount/stop)
|
||||
(is (instance? mount.core.NotStartedState (dval app.example/nrepl))))))
|
||||
|
||||
#?(:cljs
|
||||
(deftest cleanup-dirty-states
|
||||
(let [_ (mount/start #'mount.test.helper/helper)]
|
||||
(is (= :started (dval helper)))
|
||||
(is (= 42 @forty-two))
|
||||
(.require js/goog "mount.test.helper") ;; should have run :stop of `helper`
|
||||
;; (is (= :cleaned @forty-two)) ;; TODO: figure out how to reload a namespace properly
|
||||
;; (is (instance? mount.core.NotStartedState (dval helper)))
|
||||
(mount/start #'mount.test.helper/helper)
|
||||
(is (= :started (dval helper)))
|
||||
(mount/stop)
|
||||
(is (instance? mount.core.NotStartedState (dval helper))))))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
(ns mount.test.helper
|
||||
(:require mount.core))
|
||||
(:require
|
||||
#?@(:cljs [[mount.core :as mount :refer-macros [defstate]]]
|
||||
:clj [[mount.core :as mount :refer [defstate]]])))
|
||||
|
||||
(defn dval
|
||||
"returns a value of DerefableState without deref'ing it"
|
||||
|
|
@ -9,3 +11,8 @@
|
|||
:cljs (.-name d)))
|
||||
:inst
|
||||
deref))
|
||||
|
||||
(def forty-two (atom 42))
|
||||
|
||||
(defstate helper :start :started
|
||||
:stop (reset! forty-two :cleaned))
|
||||
|
|
|
|||
|
|
@ -10,13 +10,52 @@
|
|||
[app.conf :refer [config]]
|
||||
[app.nyse :refer [conn]]
|
||||
[app.example :refer [nrepl]]])
|
||||
[mount.test.helper :refer [dval]]))
|
||||
[mount.test.helper :refer [dval helper]]))
|
||||
|
||||
(defstate test-conn :start 42
|
||||
:stop (constantly 0))
|
||||
|
||||
(defstate test-nrepl :start [])
|
||||
|
||||
#?(:cljs
|
||||
(deftest start-with
|
||||
|
||||
(testing "should start with substitutes"
|
||||
(let [_ (mount/start-with {#'app.websockets/system-a #'mount.test.start-with/test-conn
|
||||
#'mount.test.helper/helper #'mount.test.start-with/test-nrepl})]
|
||||
(is (map? (dval config)))
|
||||
(is (vector? (dval helper)))
|
||||
(is (= (dval system-a) 42))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should not start the substitute itself"
|
||||
(let [_ (mount/start-with {#'app.websockets/system-a #'mount.test.start-with/test-conn})]
|
||||
(is (instance? mount.core.NotStartedState (dval test-conn)))
|
||||
(is (= 42 (dval system-a)))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start normally after start-with"
|
||||
(let [_ (mount/start)]
|
||||
(is (map? (dval config)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(is (instance? js/WebSocket (dval system-a)))
|
||||
(is (= 42 (dval test-conn)))
|
||||
(is (vector? (dval test-nrepl)))
|
||||
(is (= :started (dval helper)))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start-without normally after start-with"
|
||||
(let [_ (mount/start-without #'mount.test.start-with/test-conn
|
||||
#'mount.test.start-with/test-nrepl)]
|
||||
(is (map? (dval config)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(is (instance? js/WebSocket (dval system-a)))
|
||||
(is (= :started (dval helper)))
|
||||
(is (instance? mount.core.NotStartedState (dval test-conn)))
|
||||
(is (instance? mount.core.NotStartedState (dval test-nrepl)))
|
||||
(mount/stop)))))
|
||||
|
||||
#?(:clj
|
||||
(deftest start-with
|
||||
|
||||
|
|
@ -39,7 +78,7 @@
|
|||
(is (map? (dval config)))
|
||||
(is (instance? clojure.tools.nrepl.server.Server (dval nrepl)))
|
||||
(is (instance? datomic.peer.LocalConnection (dval conn)))
|
||||
(is (= (dval test-conn )42))
|
||||
(is (= (dval test-conn) 42))
|
||||
(is (vector? (dval test-nrepl)))
|
||||
(mount/stop)))
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
[app.conf :refer [config]]
|
||||
[app.nyse :refer [conn]]
|
||||
[app.example :refer [nrepl]]])
|
||||
[mount.test.helper :refer [dval]]))
|
||||
[mount.test.helper :refer [dval helper]]))
|
||||
|
||||
#?(:clj
|
||||
(defn without [f]
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
(mount/stop)))
|
||||
|
||||
(use-fixtures :once
|
||||
#?(:cljs {:before #(mount/start-without #'app.websockets/system-a #'app.audit-log/log)
|
||||
#?(:cljs {:before #(mount/start-without #'mount.test.helper/helper #'app.websockets/system-a)
|
||||
:after mount/stop}
|
||||
:clj without))
|
||||
|
||||
|
|
@ -28,3 +28,10 @@
|
|||
(is (map? (dval config)))
|
||||
(is (instance? mount.core.NotStartedState (dval nrepl)))
|
||||
(is (instance? mount.core.NotStartedState (dval conn)))))
|
||||
|
||||
#?(:cljs
|
||||
(deftest start-without-states
|
||||
(is (map? (dval config)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(is (instance? mount.core.NotStartedState (dval helper)))
|
||||
(is (instance? mount.core.NotStartedState (dval system-a)))))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,34 @@
|
|||
[app.conf :refer [config]]
|
||||
[app.nyse :refer [conn]]
|
||||
[app.example :refer [nrepl]]])
|
||||
[mount.test.helper :refer [dval]]))
|
||||
[mount.test.helper :refer [dval helper]]))
|
||||
|
||||
#?(:cljs
|
||||
(deftest stop-except
|
||||
|
||||
(testing "should stop all except nrepl"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/stop-except #'app.audit-log/log #'mount.test.helper/helper)]
|
||||
(is (= :started (dval helper)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(is (instance? mount.core.NotStartedState (dval config)))
|
||||
(is (instance? mount.core.NotStartedState (dval system-a)))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start normally after stop-except"
|
||||
(let [_ (mount/start)]
|
||||
(is (map? (dval config)))
|
||||
(is (instance? js/WebSocket (dval system-a)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should stop all normally after stop-except"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/stop-except #'app.audit-log/log #'mount.test.helper/helper)
|
||||
_ (mount/stop)]
|
||||
(is (instance? mount.core.NotStartedState (dval config)))
|
||||
(is (instance? mount.core.NotStartedState (dval log)))
|
||||
(is (instance? mount.core.NotStartedState (dval system-a)))))))
|
||||
|
||||
#?(:clj
|
||||
(deftest stop-except
|
||||
|
|
|
|||
|
|
@ -34,6 +34,65 @@
|
|||
|
||||
(defstate randomizer :start (rand-int 42))
|
||||
|
||||
#?(:cljs
|
||||
(deftest suspendable-lifecycle
|
||||
|
||||
(testing "should suspend _only suspendable_ states that are currently started"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)]
|
||||
(is (map? (dval config)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(is (instance? js/WebSocket (dval system-a)))
|
||||
(is (= (dval web-server) :w-suspended))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should resume _only suspendable_ states that are currently suspended"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/stop #'app.websockets/system-a)
|
||||
_ (mount/suspend)
|
||||
_ (mount/resume)]
|
||||
(is (map? (dval config)))
|
||||
(is (instance? mount.core.NotStartedState (dval system-a)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(is (= (dval web-server) :w-resumed))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start all the states, except the ones that are currently suspended, should resume them instead"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)
|
||||
_ (mount/start)]
|
||||
(is (map? (dval config)))
|
||||
(is (instance? js/WebSocket (dval system-a)))
|
||||
(is (instance? datascript.db/DB @(dval log)))
|
||||
(is (= (dval web-server) :w-resumed))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should stop all: started and suspended"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)
|
||||
_ (mount/stop)]
|
||||
(is (instance? mount.core.NotStartedState (dval config)))
|
||||
(is (instance? mount.core.NotStartedState (dval system-a)))
|
||||
(is (instance? mount.core.NotStartedState (dval log)))
|
||||
(is (instance? mount.core.NotStartedState (dval web-server)))))))
|
||||
|
||||
#?(:cljs
|
||||
(deftest suspendable-start-with
|
||||
|
||||
(testing "when replacing a non suspendable state with a suspendable one,
|
||||
the later should be able to suspend/resume,
|
||||
the original should not be suspendable after resume and preserve its lifecycle fns after rollback/stop"
|
||||
(let [_ (mount/start-with {#'app.websockets/system-a #'mount.test.suspend-resume/web-server})
|
||||
_ (mount/suspend)]
|
||||
(is (= (dval system-a) :w-suspended))
|
||||
(is (instance? mount.core.NotStartedState (dval web-server)))
|
||||
(mount/stop)
|
||||
(mount/start)
|
||||
(mount/suspend)
|
||||
(is (instance? js/WebSocket (dval system-a)))
|
||||
(is (= (dval web-server) :w-suspended))
|
||||
(mount/stop)))))
|
||||
|
||||
#?(:clj
|
||||
(deftest suspendable-lifecycle
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue