Rework tests slightly

This commit is contained in:
Nicholas Kariniemi 2014-08-02 23:54:02 +03:00
parent 16a0a5cb97
commit a7ac7665df
3 changed files with 28 additions and 16 deletions

View file

@ -60,14 +60,13 @@
(handler/site routes))))
(def default-port 3000)
(def integration-test-port 3456)
(defn start-server [port]
(httpkit/run-server app {:port port}))
(defn run-integration-test []
(let [stop-server (start-server integration-test-port)]
(integration-test/run integration-test-port)
(let [stop-server (start-server integration-test/server-port)]
(integration-test/run)
(stop-server)))
(defn start-production-server [{:keys [port mongo-url]}]

View file

@ -12,6 +12,13 @@
(defn clear-grubs []
(mc/drop @db grub-collection))
(defn clear-recipes []
(mc/drop @db recipe-collection))
(defn clear-all []
(clear-grubs)
(clear-recipes))
(defmulti handle-event :event :default :unknown-event)
(defn insert-grub [event]

View file

@ -5,6 +5,9 @@
[clj-webdriver.core :as webdriver]
[clojure.test :as test]))
(def server-port 3456)
(def site-url (str "http://localhost:" server-port))
;; Hard-coded path to chromedriver
(defn set-chromedriver-path! []
(System/setProperty "webdriver.chrome.driver" "bin/chromedriver"))
@ -57,9 +60,9 @@
(taxi/to driver2 url)
(let [recipes (repeatedly 4 get-rand-recipe )]
(doseq [recipe recipes]
(add-recipe driver2 recipe))
(add-recipe driver1 recipe))
(doseq [{:keys [name]} recipes]
(test/is (taxi/find-element driver2 {:text name})
(test/is (taxi/find-element driver2 {:value name})
"Added recipes should appear in other browser"))))
(defn run-tests [site-url driver1 driver2]
@ -67,15 +70,18 @@
(test-added-grubs-sync site-url driver1 driver2)
(test-added-recipes-sync site-url driver1 driver2))
(defn run [port]
(defn start-db-and-websocket-server! []
(let [db-chan (db/connect-and-handle-events "grub-integration-test")]
(db/clear-all)
(ws/pass-received-events-to-clients-and-db db-chan)))
(defn run []
(println "Starting integration test")
(set-chromedriver-path!)
(let [db-chan (db/connect-and-handle-events "grub-integration-test")
site-url (str "http://localhost:" port)]
(println "Starting integration test")
(ws/pass-received-events-to-clients-and-db db-chan)
(let [driver1 (get-driver site-url)
driver2 (get-driver site-url)]
(run-tests site-url driver1 driver2)
(taxi/quit driver1)
(taxi/quit driver2)))
(db/clear-grubs))
(start-db-and-websocket-server!)
(let [driver1 (get-driver site-url)
driver2 (get-driver site-url)]
(run-tests site-url driver1 driver2)
(taxi/quit driver1)
(taxi/quit driver2))
(db/clear-all))