Fork me on GitHub
#kaocha
<
2019-09-10
>
danielcompton02:09:46

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.

danielcompton05:09:12

I think the only missing thing is parsing CLI opts

plexus05:09:29

would it need CLI opts?

danielcompton05:09:45

The require-ns one could have them

danielcompton05:09:57

For generality, I don’t need them though

plexus05:09:02

yeah that's true, exercise for the reader 😉

danielcompton05:09:35

Also, do you think it’s better to instrument post-load or pre-run?

danielcompton05:09:00

I don’t think it makes much difference in practice, post-load felt semantically better, but not by much

danielcompton05:09:35

Less symmetrical doing it post-load than pre-run though

plexus05:09:31

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)

plexus05:09:41

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

plexus05:09:23

happy to hear my documentation efforts have paid off 🙂

danielcompton05:09:03

Yeah, easiest Clojure plugin I’ve ever written

plexus06:09:18

Maybe a :kaocha/preloads would make sense (analogous to cljs :preloads)

danielcompton07:09:15

Yeah, I think it kinda makes sense as a built-in

danielcompton07:09:43

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.

plexus07:09:45

uh... can you elaborate?

danielcompton09:09:42

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

danielcompton09:09:19

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?