Fork me on GitHub

Is there a way to send something like a watch command to the cognitect-labs test-runner using the cli so that whenever I save code it runs the tests automatically in the background?


It would be fairly easy to create a watcher in the REPL that could kick off tests...

$ clojure -Sdeps '{:deps {juxt/dirwatch {:mvn/version "RELEASE"}}}' -M:rebel
[Rebel readline] Type :repl/help for online help info
user=> (require '[juxt.dirwatch :refer [watch-dir]] '[ :as io])
user=> (watch-dir println (io/file "."))
#object[clojure.lang.Agent 0x32f5ecc4 {:status :ready, :val #object[sun.nio.fs.LinuxWatchService 0x7ef8eda7 "[email protected]"]}]
user=> (spit "ex.txt" "Hello, Watcher!")
{:file #object[ 0x713dbaa1 ./.rebel_readline_history], :count 1, :action :modify}
{:file #object[ 0x662be223 ./ex.txt], :count 1, :action :create}
{:file #object[ 0x76cdf12f ./ex.txt], :count 1, :action :modify}
user=> (spit "ex.txt" "Hello, Watcher!")
{:file #object[
0x455a35c1 ./ex.txt], :count 2, :action :modify}


The Cognitect test-runner has a programmatic -X entry point that you could invoke from a watcher.


Ok, cool, I'll look into that option. Looks like koacha has a watch command too if I want to explore that one. These exercism exercises come with the cognitect one though so I figured I would explore that


You'd probably want to run it in a thread and keep track of when it is running (so you don't run tests in parallel) but also keep track of changes so you know to run it again if changes came in while the previous run was in progress...


Really though you probably want incremental testing to make watching worthwhile...


Frankly, I don't like that workflow. I prefer to run tests via hotkeys in my editor all the time I'm editing (and evaluating) code. I have a hot key bound to, essentially, "find the current ns's tests and run them" and another hot key bound to "run the tests in the current ns" (to allow for whether I'm in a code file or a test file.


But my workflow is all in the REPL. I don't switch to a terminal for any of that. Edit, eval, edit, eval, test. A lot of it without saving files 🙂


That's what I've been currently doing as well and it works great. But I like to tinker with my tooling and workflow every now and then


By that I mean I was somehow getting too lazy to even type ,tn lol


@U9J50BY4C I've added a :test/watch alias that runs koacha in watch mode (with fail-fast) to, so I can run quickly run koacha with any Clojure project.

clojure -M:test/watch
I like to run koacha before pushing commits to a project as a sanity check

Alex Miller (Clojure team)02:12:13

Nothing in test-runner but you can use os watch stuff for that