kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
danielcompton 2019-09-10T02:53:46.037200Z

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.

plexus 2019-09-10T05:45:36.037700Z

this is great @danielcompton

1
danielcompton 2019-09-10T05:46:12.038300Z

I think the only missing thing is parsing CLI opts

plexus 2019-09-10T05:46:29.038600Z

would it need CLI opts?

danielcompton 2019-09-10T05:46:45.039Z

The require-ns one could have them

danielcompton 2019-09-10T05:46:57.039500Z

For generality, I don’t need them though

plexus 2019-09-10T05:47:02.039700Z

yeah that's true, exercise for the reader 😉

danielcompton 2019-09-10T05:47:35.040700Z

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

danielcompton 2019-09-10T05:48:00.041600Z

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

danielcompton 2019-09-10T05:48:35.042400Z

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

plexus 2019-09-10T05:50:31.044100Z

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)

plexus 2019-09-10T05:51:41.044800Z

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

plexus 2019-09-10T05:52:23.045200Z

happy to hear my documentation efforts have paid off 🙂

danielcompton 2019-09-10T05:55:03.045700Z

Yeah, easiest Clojure plugin I’ve ever written

plexus 2019-09-10T06:10:18.046200Z

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

danielcompton 2019-09-10T07:13:15.046600Z

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

danielcompton 2019-09-10T07:13:43.047200Z

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.

plexus 2019-09-10T07:14:45.047500Z

uh... can you elaborate?

danielcompton 2019-09-10T09:42:42.050800Z

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

danielcompton 2019-09-10T09:44:19.053100Z

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?