diff --git a/src/leiningen/bat_test.clj b/src/leiningen/bat_test.clj index cd32bde..9a7636a 100644 --- a/src/leiningen/bat_test.clj +++ b/src/leiningen/bat_test.clj @@ -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. @@ -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 diff --git a/src/metosin/bat_test.clj b/src/metosin/bat_test.clj index ee8b226..b5b91f3 100644 --- a/src/metosin/bat_test.clj +++ b/src/metosin/bat_test.clj @@ -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)) diff --git a/src/metosin/bat_test/cli.clj b/src/metosin/bat_test/cli.clj index 5d2d7ac..fb209ed 100644 --- a/src/metosin/bat_test/cli.clj +++ b/src/metosin/bat_test/cli.clj @@ -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. @@ -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) diff --git a/src/metosin/bat_test/impl.clj b/src/metosin/bat_test/impl.clj index aff2510..b5e7534 100644 --- a/src/metosin/bat_test/impl.clj +++ b/src/metosin/bat_test/impl.clj @@ -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]