kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
2020-07-24T08:00:25.454Z

I was trying to extract all the tests from the test-plan, which is a quite nested data structure

2020-07-24T08:00:31.454200Z

and this seems to work

(def plan (kr/test-plan))

(def all-test-names
  (->> plan
       :kaocha.test-plan/tests
       (mapcat :kaocha.test-plan/tests)
       (mapcat :kaocha.test-plan/tests)
       (map :kaocha.var/name)
       sort))

2020-07-24T08:00:36.454400Z

I wonder if there is an easier way though

plexus 2020-07-24T08:03:52.455500Z

There's kaocha.testable/test-seq, or you can use clojure.walk

2020-07-24T08:04:29.455800Z

ah yes better thanks.

2020-07-24T08:05:46.456700Z

seems like I was getting the same result at least

plexus 2020-07-24T08:05:49.457100Z

I posted an example of using clojure.walk recently https://github.com/lambdaisland/kaocha/blob/master/repl_sessions/strict_focus_meta_hook.clj

2020-07-24T08:05:51.457300Z

apart from the skip maybe

plexus 2020-07-24T08:06:45.458500Z

you are encourage to use hierarchy/leaf? to check if a testable is a an actual test as opposed to a grouping like a namespace or a test suite

plexus 2020-07-24T08:06:57.458800Z

different test types may have more or fewer than two levels of nesting

plexus 2020-07-24T08:07:34.459700Z

also :kaocha.var/name is specific to clojure.test, whereas all testables have a :kaocha.testable/id

2020-07-24T08:07:34.459800Z

ah nice thanks

2020-07-24T08:08:12.460500Z

well what I have to do is to actually split tests with the circleci tool

(def all-test-names-2
  (->> (kaocha.testable/test-seq plan)
       (map :kaocha.var/name)
       (remove nil?)))

(def split
  (-> (sh/sh "circleci tests split --split-by=timings"
             :in (clojure.string/join "\n" all-test-names-2))
      :out))

2020-07-24T08:08:21.461100Z

and then run them with kaocha

2020-07-24T08:08:33.461700Z

something like (kr/run "--focus" (first all-test-names-2)) for example

2020-07-24T08:08:39.462200Z

but yeah running all the ones returned by the split

2020-07-24T08:09:02.463100Z

but yeah I guess I can use the id as well

plexus 2020-07-24T08:09:15.463700Z

yeah so in this case you definitely want to use kaocha.testable/id, that's what you pass to focus. it just happens to correspond to the var name for clojure.test

2020-07-24T08:09:52.464Z

ah yeah but don't think circleci would handle that

plexus 2020-07-24T08:10:26.465200Z

I'm not familiar with this circleci tool. What does it do?

2020-07-24T08:10:56.465900Z

so it kind automatically split tests by timing, parallelising automatically

2020-07-24T08:11:08.466600Z

but still keeping only one job

2020-07-24T08:11:26.467300Z

we had that working for clojure.test, I just wanted to convert to kaocha

plexus 2020-07-24T08:11:35.467700Z

interesting, I'm guessing it gets the test information via junit.xml?

2020-07-24T08:11:42.467900Z

yeah probably

2020-07-24T08:11:49.468500Z

from the circleci agent from previous runs I guess

plexus 2020-07-24T08:11:56.469100Z

in which case it will have the testable ids

2020-07-24T08:12:07.469300Z

ah ok I'll try

plexus 2020-07-24T08:12:25.470Z

I mean if you're only using clojure.test it comes down to the same thing

plexus 2020-07-24T08:13:38.470500Z

and then (kaocha.repl/run {:focus [id1 id2 id3]}) I think

2020-07-24T08:27:32.471100Z

I'm always confused about the arguments to pass to kr/run

finops.ci-tests> (kr/run {:focus smaller-subset})

0 tests, 0 assertions, 0 failures.
#:kaocha.result{:count 0, :pass 0, :error 0, :fail 0, :pending 0}
finops.ci-tests> (kr/run "--focus" (first smaller-subset))
[(...........................................................................................................................................................................................................................................................................................................................................................................................................................................

2020-07-24T08:27:45.471700Z

so it works fine if I pass things same args I would pass to the cli

2020-07-24T08:27:52.472Z

but not with configs

plexus 2020-07-24T08:28:07.472400Z

hmmm that's surprising

plexus 2020-07-24T08:30:54.473Z

but that "--focus" version only works by accident, kaocha.repl does not take command line options like that

plexus 2020-07-24T08:31:48.473700Z

kaocha.run takes testable-ids, and optionally a config map as last arg, so you can just do (apply kaocha.repl/run subset)

2020-07-24T08:37:11.474100Z

ahok thanks let's see if

(apply kr/run
         (conj (tests-to-run)
               {:plugin :kaocha.plugin/junit-xml
                :junit-xml-file "test-results/kaocha/results.xml"}))
works

2020-07-24T08:37:19.474500Z

maybe I can add an example in hte kr/run docs

2020-07-24T08:37:32.475Z

it's not the first time I get confused even after looking at docs and code

plexus 2020-07-24T08:49:35.475500Z

that'd be great! doc improvements are always most welcome

plexus 2020-07-24T08:49:57.475900Z

in general a writeup of this parallel testing with circle would be very cool!

2020-07-24T09:43:16.476100Z

ah yeah as soon as I get it working

2020-07-24T09:43:18.476500Z

I can do that

2020-07-24T09:43:54.477600Z

Yeah I didn't even know there was this feature, but it's quite a good way to get some free parallelism without having to split yourself creating multiple jobs

2020-07-24T09:59:10.478400Z

still doesn't work but it's because of something I'm passing wrong to the circleci command, but well almost there

2020-07-24T10:58:44.479100Z

mm so splitting didn't work yet, but the other weird thing is

..............................................................................................................................................................................................................................................................................................................................................................................)]
1 tests, 2800 assertions, 0 failures.

2020-07-24T10:58:58.479700Z

so doing it like this seems to group all the tests into one

2020-07-24T10:59:09.480300Z

which is maybe expected I guess and maybe not a big deal

2020-07-24T10:59:12.480600Z

just seems a bit strange

2020-07-24T11:02:35.481500Z

also any idea how to pass the --reporter documentation config in that config map?

2020-07-24T11:02:51.482Z

:reporter :documentation or :reporter "documentation" don't work

2020-07-24T11:20:37.483200Z

also I was trying to use leaf? but I find nothing if I do this for example

(defn fetch-tests
  [test-plan]
  (w/postwalk
   (fn [t]
     (when (kh/leaf? t) t))
   test-plan))

plexus 2020-07-24T12:11:25.484Z

I think that's because of how postwalk works, you're removing the parents so the chidren are never reached

plexus 2020-07-24T12:12:51.484500Z

kaocha.repl/config is your friend to see what the results are of your config options

plexus 2020-07-24T12:14:27.484700Z

(:kaocha/reporter (kaocha.repl/config))
(:kaocha/reporter (kaocha.repl/config {:reporter kaocha.report/documentation}))