For the record, here are two plugins (with new namespaces) I made to handle this:
(ns myplugin.kaocha.orchestra
(:require [kaocha.plugin :refer [defplugin]]
[orchestra.spec.test :as orchestra]))
(defplugin myplugin.kaocha/orchestra
(post-load [test-plan]
;; Instrument specs after all of the test namespaces have been loaded
(orchestra/instrument)
test-plan)
(post-run [result]
;; Unstrument specs after tests have run. This isn't so important
;; for CLI testing as the process will exit shortly after the post-run
;; step, but is helpful for running Kaocha tests from the REPL.
(orchestra/unstrument)
result))
(ns myplugin.kaocha.require-ns
(:require [kaocha.plugin :refer [defplugin]]
[clojure.spec.alpha :as s]))
(s/def ::ns-names (s/coll-of symbol?))
(defplugin myplugin.kaocha/require-ns
(pre-load [config]
(when-let [ns-names (::ns-names config)]
(apply require ns-names))
config))
#kaocha/v1 {:plugins [:myplugin.kaocha/orchestra
:myplugin.kaocha/require-ns]
:myplugin.kaocha.require-ns/ns-names [thanks.spec]}
I'll probably get around to open sourcing them at some point, but for now here they are in case they're helpful for anyone. These were my first Kaocha plugins, so I might have made some mistakes. The docs were excellent though.this is great @danielcompton
I think the only missing thing is parsing CLI opts
would it need CLI opts?
The require-ns one could have them
For generality, I don’t need them though
yeah that's true, exercise for the reader 😉
Also, do you think it’s better to instrument post-load or pre-run?
I don’t think it makes much difference in practice, post-load felt semantically better, but not by much
Less symmetrical doing it post-load than pre-run though
I don't think it matters much. The only real differences I see are that in pre-run any :kaocha/bindings
for vars that were loaded during the load step will also be set, in post-load that's not the case yet. Also in pre-run the reporter has been set (bound)
I feel like we should have a way to gather these plugins and hooks that people post here, maybe just an examples/
directory in the kaocha repo
happy to hear my documentation efforts have paid off 🙂
Yeah, easiest Clojure plugin I’ve ever written
Maybe a :kaocha/preloads
would make sense (analogous to cljs :preloads
)
Yeah, I think it kinda makes sense as a built-in
Also, should it be necessary for me to re-instrument the system after loading the tests? Kaocha runs orchestra/instrument, but much earlier in the process, when requiring the test-helper namespace.
uh... can you elaborate?
https://clojurians.slack.com/archives/CCY2V0U6A/p1568004513034600
Kaocha already runs orchestra/instrument to instrument fspecs, but it does it before my application specs are loaded. I wondered whether Kaocha wants to be instrumenting the application specs too, or whether it’s call to orchestra is only intended for checking Kaocha functions
Basically, should the myplugin.kaocha.orchestra
exist, or should I do a PR to Kaocha to run instrument at some point in the test cycle automatically?