Fork me on GitHub
#testing
<
2023-04-09
>
Jacob Emcken20:04:04

I've been very happy with pjstadig/humane-test-output for projects using lein, by adding it to my :user profile (`.lein/profiles.clj`). I would like a similar setup for projects using deps.edn (`clj -X:test`), but I cannot see a good way forward. Any pointers on if and how this could be possible?

seancorfield20:04:46

What exactly do you have in your :test alias?

mpenet21:04:57

Eftest returns similar output by default , I suspect kaocha also has options for this. But these are full runners, not just a reporter

mpenet21:04:19

That said both are great options

seancorfield21:04:06

I use HTO with deps.edn in my Expectations library, but I have a piece of code that attempts to resolve and call pjstadig.humane-test-output/activate! explicitly in Expectations -- so if it's on the classpath (via an alias), it gets activated automatically.

Jacob Emcken21:04:06

:test {:extra-paths ["test/unit"]
          :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
          :main-opts ["-m" "cognitect.test-runner"]
          :exec-fn cognitect.test-runner.api/test}

seancorfield21:04:24

If you want to stick with the Cognitect test runner for simplicity, you could have a small wrapper for cognitect.test-runner.api/test that activates HTO and then calls that test function.

seancorfield21:04:29

Or you could look at other test runners. Or look at Expectations which is fully compatible with the regular clojure.test stuff, including the Cognitect test runner, but it auto-activates HTO if it's on the classpath.

seancorfield21:04:17

(BTW, you don't need both :main-opts and :exec-fn -- unless you want to be able to use both -M:test and -X:test)

Jacob Emcken21:04:07

I had hoped I could leave all the projects as is, and just add something in ~/.clojure/deps.ednkinda like what I did with lein:

{:user {:dependencies [[pjstadig/humane-test-output "0.11.0"]]
        :injections [(require 'pjstadig.humane-test-output)
                     (pjstadig.humane-test-output/activate!)]}}

Jacob Emcken21:04:39

> (BTW, you don't need both ... both were added with clj -M:neil add test

seancorfield21:04:35

Yeah, it's just giving you options without needing configuration. What you can do with :main-opts is to require/resolve/call that activate! function and then invoke the Cognitect test-runner main.

seancorfield21:04:46

(let me just set that up and report back)

seancorfield21:04:26

Yup, here we go:

{:test
  {:extra-paths ["test"]
   :extra-deps {pjstadig/humane-test-output
                {:mvn/version "0.11.0"}
                io.github.cognitect-labs/test-runner
                {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
   :main-opts ["-e" "((requiring-resolve 'pjstadig.humane-test-output/activate!))"
               "-m" "cognitect.test-runner"]}

seancorfield21:04:44

(assuming you're on Clojure 1.10 or later)

seancorfield21:04:44

Since -X invokes just a single function, you'd need a wrapper function, but with -M you can have multiple main options chained together.

Jacob Emcken18:04:40

Thanks for the explanation and example @U04V70XH6 I have never seen requiring-resolve before, so I would probably have stumbled for a long while before, figuring that one out.