Skip to content

Commit

Permalink
port :enter-key-listener to lein/boot
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Feb 4, 2022
1 parent a1f575b commit f802b9f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
10 changes: 6 additions & 4 deletions src/leiningen/bat_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Available options:
:notify-command String or vector describing a command to run after tests
:test-matcher-directories Vector of paths restricting the tests that will be matched. Relative to project root.
Default: nil (no restrictions).
:enter-key-listener If true, refresh tracker on enter key. Default: true. Only meaningful via `auto` subtask.
Also supports Lein test selectors, check `lein test help` for more information.
Expand All @@ -123,10 +124,11 @@ Arguments:
;; read-args tries to find namespaces in test-paths if args doesn't contain namespaces
[namespaces selectors] (test/read-args args (assoc project :test-paths nil))
project (project/merge-profiles project [:leiningen/test :test profile])
config (assoc (:bat-test project)
:selectors (vec selectors)
:namespaces (mapv (fn [n] `'~n) namespaces)
:cloverage (= "cloverage" subtask))]
config (-> {:enter-key-listener true}
(into (:bat-test project))
(assoc :selectors (vec selectors)
:namespaces (mapv (fn [n] `'~n) namespaces)
:cloverage (= "cloverage" subtask)))]
(case subtask
("once" "cloverage")
(try
Expand Down
11 changes: 7 additions & 4 deletions src/metosin/bat_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@
s on-start VAL sym "Function to be called before running tests (after reloading namespaces)"
e on-end VAL sym "Function to be called after running tests"
c cloverage bool "Enable Cloverage coverage report (default off)"
l enter-key-listener bool "If true, refresh tracker on enter key (default true). Only meaningful when `parallel` is true."
_ cloverage-opts VAL edn "Cloverage options"]
(let [p (-> (core/get-env)
(update-in [:dependencies] into deps)
pod/make-pod
future)
opts (cond-> (assoc *opts*
:verbosity (deref util/*verbosity*)
:watch-directories (:directories pod/env))
(some? test-matcher-directories) (assoc :test-matcher-directories test-matcher-directories))]
opts (-> {:enter-key-listener true}
(into *opts*)
(assoc :verbosity (deref util/*verbosity*)
:watch-directories (:directories pod/env))
(cond->
(some? test-matcher-directories) (assoc :test-matcher-directories test-matcher-directories)))]
(fn [handler]
(System/setProperty "java.awt.headless" "true")
(pod/with-call-in @p (metosin.bat-test.impl/enter-key-listener ~opts))
Expand Down
17 changes: 4 additions & 13 deletions src/metosin/bat_test/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,6 @@
(assoc :selectors selectors)
(assoc :namespaces namespaces)))))

;; https://github.com/metosin/bat-test/blob/636a9964b02d4b4e5665fa83fea799fcc12e6f5f/src/metosin/bat_test/impl.clj#L24-L32
(defn ^:private -enter-key-listener
[opts]
(impl/on-keypress
java.awt.event.KeyEvent/VK_ENTER
(fn [_]
(when-not @impl/running
(util/info "Running all tests\n")
(reset! impl/tracker nil)
(run-tests1 opts)))))

(defn run-tests
"Run tests.
Expand Down Expand Up @@ -194,8 +183,10 @@
(when (:headless opts)
(System/setProperty "java.awt.headless" "true"))
(run-tests1 opts)
(when (:enter-key-listener opts)
(-enter-key-listener opts))
(impl/enter-key-listener opts
(fn [opts]
(reset! impl/tracker nil)
(run-tests1 opts)))
(hawk/watch! [{:paths watch-directories
:filter hawk/file?
:context (constantly 0)
Expand Down
18 changes: 10 additions & 8 deletions src/metosin/bat_test/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
(recur (read-in))))))

(defn enter-key-listener
[opts]
(util/dbug "Listening to the enter key\n")
(on-keypress
java.awt.event.KeyEvent/VK_ENTER
(fn [_]
(when-not @running
(util/info "Running all tests\n")
(run-all opts)))))
([opts] (enter-key-listener opts #'run-all))
([opts run-all]
(when (:enter-key-listener opts)
(util/dbug "Listening to the enter key\n")
(on-keypress
java.awt.event.KeyEvent/VK_ENTER
(fn [_]
(when-not @running
(util/info "Running all tests\n")
(run-all opts)))))))

(defn load-only-loaded-and-test-ns
[{:keys [::track/load] :as tracker} test-matcher]
Expand Down

0 comments on commit f802b9f

Please sign in to comment.