This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-09
Channels
- # aleph (1)
- # asami (5)
- # babashka (4)
- # beginners (8)
- # biff (19)
- # calva (2)
- # cider (9)
- # clojure (17)
- # clojure-dev (3)
- # clojure-europe (3)
- # clojurescript (2)
- # community-development (9)
- # conjure (1)
- # core-typed (2)
- # datomic (6)
- # emacs (20)
- # gratitude (1)
- # helix (5)
- # kaocha (4)
- # nbb (1)
- # releases (3)
- # testing (17)
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?
What exactly do you have in your :test
alias?
Eftest returns similar output by default , I suspect kaocha also has options for this. But these are full runners, not just a reporter
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.
: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}
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.
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.
(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
)
I had hoped I could leave all the projects as is, and just add something in ~/.clojure/deps.edn
kinda 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!)]}}
> (BTW, you don't need both ...
both were added with clj -M:neil add test
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.
(let me just set that up and report back)
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"]}
(assuming you're on Clojure 1.10 or later)
Since -X
invokes just a single function, you'd need a wrapper function, but with -M
you can have multiple main options chained together.
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.