Skip to content

Commit

Permalink
Use figwheel main so tests run in a proper test runner
Browse files Browse the repository at this point in the history
figwheel's test runner did not allow for fixtures which is a problem
for hijacking the event defmethod so we can monitor the results
  • Loading branch information
dan sutton committed Oct 23, 2018
1 parent 82c1adb commit 823fdf6
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 36 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ A Clojure library designed to ... well, that part is up to you.
## Usage

``` shell
lein figwheel devcards
lein build-dev
```

This will open up a browser for you. The default page will open up a repl. You can also view http://localhost:9500/test.html to load the tests in a test runner.

Then go to http://localhost:3449/cards.html


Expand Down
12 changes: 12 additions & 0 deletions dev-resources/public/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<!--<link href="/css/example.css" rel="stylesheet" type="text/css">-->
</head>
<body>
<div id="app"></div>
<script src="cljs-out/dev-main-test.js" type="text/javascript"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions dev.cljs.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^{:extra-main-files {:devcards {:main react-hitch.devcards-runner}
:test {:main react-hitch.test-runner}}
:watch-dirs ["src" "test"]}
{:main react-hitch.qui-tracker}
33 changes: 7 additions & 26 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:description "A Clojurescript library designed to manage and cache derived data."
:url "https://github.com/Breezeemr/react-hitch"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:url "http://www.eclipse.org/legal/epl-v10.html"}
:scm "https://github.com/Breezeemr/react-hitch"
:repositories [["snapshots" {:url "s3p://breezepackages/snapshots" :creds :gpg}]
["releases" {:url "s3p://breezepackages/releases" :creds :gpg}]]
Expand All @@ -12,28 +12,9 @@
[com.breezeehr/hitch2 "0.1.0-SNAPSHOT"]]
:profiles {:dev {
:dependencies [[cider/piggieback "0.3.9"] ; needed by figwheel nrepl
[devcards "0.2.5"]]
:plugins [[lein-figwheel "0.5.16"]]
:resource-paths ["dev-resources" "target/devcards"]
:figwheel {:css-dirs ["dev-resources/public/css"]
:nrepl-port 7888
:server-logfile "target/figwheel-logfile.log"}}}
:source-paths ["src"]

:clean-targets ^{:protect false} ["resources/public/js" "target"]

:cljsbuild {
:builds [{:id "devcards"
:source-paths ["src" "test"]

:figwheel {:devcards true}

:compiler {:main react-hitch.devcards-runner
:asset-path "js/devcardsout"
:output-to "target/devcards/public/js/react_hitch_devcards.js"
:output-dir "target/devcards/public/js/devcardsout"
:optimizations :none
:source-map true
:source-map-timestamp false
:cache-analysis true
}}]})
[devcards "0.2.5"]
[com.bhauman/cljs-test-display "0.1.1"]
[com.bhauman/figwheel-main "0.1.9"]]
:aliases {"fig" ["trampoline" "run" "-m" "figwheel.main"]
"build-dev" ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"]}}}
:source-paths ["src"])
1 change: 1 addition & 0 deletions test/react_hitch/common_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

(defn return-constant [gv-tracker v]
v)

(sel-proto/def-selector-spec constant-spec
:not-machine
:hitch.selector.spec/canonical-form :hitch.selector.spec.canonical-form/positional
Expand Down
12 changes: 9 additions & 3 deletions test/react_hitch/curator/react_hook_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@

(def results (atom []))

(defmethod graph-proto/run-effect :rerender-components
[gm effect]
(swap! results conj effect))
(defn fixture [f]
(defmethod graph-proto/run-effect :rerender-components
[gm effect]
(prn "effect! hook test")
(swap! results conj effect))
(f)
(remove-method graph-proto/run-effect :rerender-components))

(use-fixtures :once fixture)

(def gctors
[["Atom graph: " (fn [] (atom-gm/make-gm registry-resolver))]])
Expand Down
16 changes: 10 additions & 6 deletions test/react_hitch/qui_tracker_test.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns react-hitch.qui-tracker-test
(:require [clojure.test :refer [is testing]]
(:require [clojure.test :refer [is testing use-fixtures]]
[react-hitch.qui-tracker :as qui]
[hitch2.protocols.graph-manager :as graph-proto]
[hitch2.graph :as h]
Expand All @@ -10,9 +10,15 @@

(def results (atom []))

(defmethod graph-proto/run-effect :rerender-components
[gm effect]
(swap! results conj effect))
(defn fixture [f]
(defmethod graph-proto/run-effect :rerender-components
[gm effect]
(prn "effect! in qui tracker")
(swap! results conj effect))
(f)
(remove-method graph-proto/run-effect :rerender-components))

(use-fixtures :once fixture)

(def gctors
[["Atom graph: " (fn [] (atom-gm/make-gm registry-resolver))]])
Expand All @@ -29,7 +35,6 @@
(is (= value (qui/qui-hitch graph :nf :component render-function value services)))
(is (= [] @results)))))


(defn render-with-deps [value rtx services]
@(h/select-sel! rtx value))

Expand All @@ -51,4 +56,3 @@
(h/apply-commands g [[mv-sel [:set-value 7]]])
(is (= [{:type :rerender-components, :components #{:component}}]
@results)))))

14 changes: 14 additions & 0 deletions test/react_hitch/test_runner.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns react-hitch.test-runner
(:require [cljs.test]
[cljs-test-display.core]
[react-hitch.curator.react-hook-test]
[react-hitch.qui-tracker-test])
(:require-macros [cljs.test]))

(defn test-run []
(cljs.test/run-tests
(cljs-test-display.core/init! "app")
'react-hitch.curator.react-hook-test
'react-hitch.qui-tracker-test))

(test-run)

0 comments on commit 823fdf6

Please sign in to comment.