kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
2020-12-09T12:14:01.263700Z

is there a good example of a project configured with kaocha-cljs and/or kaocha-cljs2? I'm trying on a few projects but I never manage to get it to work, always fails to connect back to the browser

2020-12-09T12:14:20.264100Z

probably just something dumb, if I see a working example I can probably figure it out

plexus 2020-12-09T12:39:03.264700Z

lambdaisland/uri uses kaocha-cljs, literally just 100% defaults

plexus 2020-12-09T12:39:22.264900Z

#kaocha/v1
{:tests [{:id :clj}
         {:id :cljs
          :type :kaocha.type/cljs}]}

plexus 2020-12-09T12:40:09.265800Z

generally with kaocha-cljs it works better the less you hard you try 🙂 if you start giving it compiler options or such you'll likely break the repl setup.

plexus 2020-12-09T12:41:23.266200Z

https://github.com/lambdaisland/kaocha-cljs2-demo is meant as a demo setup for kaocha-cljs2, but not sure what state it is in...

2020-12-09T13:50:36.266800Z

ok thanks I'll check

2020-12-09T13:51:07.267600Z

btw @plexus I think I noticed a pretty serious issue with my retry plugin, tests now are always passing no matter what and I found out why

2020-12-09T13:51:26.267900Z

if the test function itself is called in

(defn- with-capture-report [t]
  (with-redefs [te/report (fn [& args] (reset! to-report args))]
     (t)))
it returns always true

2020-12-09T13:51:41.268700Z

but if I run (t) directly it returns false when the test fails

2020-12-09T13:55:50.269700Z

if I check what's passed to as args it also contains something like

:type :pass, :expected (= 1 1), :actual (#function[clojure.core/=] 1 1), :message nil}
which is weird since it failed

2020-12-09T13:56:56.270700Z

so somehow the return for (t) itself depends on the reporter but also what's passed the reporter doesn't seem right, am I missing something silly?

plexus 2020-12-09T14:01:11.271300Z

@andrea.crotti it seems like you're assuming you'll only get one event per test. That's not correct.

plexus 2020-12-09T14:01:24.271700Z

you may get multiple pass/fail/error events for a single test

plexus 2020-12-09T14:01:36.272Z

as well as other events, custom assertions, etc

2020-12-09T14:01:51.272400Z

ah right of course, there are multiple assertions

2020-12-09T14:02:15.273Z

so what would (t) return then in general?

plexus 2020-12-09T14:02:38.273600Z

I don't think (t) really returns anything, or nothing meaninful

plexus 2020-12-09T14:03:07.274200Z

I would have to check but I think you'll just get back whatever the last form in the deftest returned, which doesn't tell you anything

plexus 2020-12-09T14:03:22.274700Z

all fail/pass information is communicated via the events

2020-12-09T14:03:24.274800Z

ah ok I see, yeah I was fooled by the fact that I saw it returning true/false

2020-12-09T14:03:35.275400Z

so I assumed that it was returning if the test failed or not

2020-12-09T14:03:42.275900Z

cool ok makes sense

plexus 2020-12-09T14:04:02.276500Z

yeah I think (is ...) will return true / false, makes it convenient from a repl, but that's mostly ignored in actual tests

2020-12-09T14:19:21.277600Z

yeah I think I got it now, it makes it more complicated though, since I have to capture all the reports, and remove the duplicate failed ones when I report something that failed more than the max number of times

2020-12-09T14:20:57.278200Z

but well should be easy to find the duplicates

plexus 2020-12-09T14:38:41.280200Z

not sure how you're approaching it, but how I imagined it would work - run test, capture all events - did it fail? (there's a fail event) -> re-run the tests, always keep the recording of events from the last test - did it pass or too many retries? -> break the loop, you're done - now replay all events from the last time you ran the test

2020-12-09T15:04:51.281Z

yes that was what I was trying to do, but since that report has to contain multiple things I can end up with multiple reports for the same assertion failed

2020-12-09T15:05:05.281400Z

anyway now it seems to actually work as expected https://github.com/AndreaCrotti/kaocha-retry/blob/main/src/kaocha_retry/plugin.clj#L28

2020-12-09T15:05:18.282Z

even if not sure that's the best solution yet

plexus 2020-12-09T15:06:35.282600Z

you're capturing all reports, do the reset inside the retry loop

plexus 2020-12-09T15:06:48.282900Z

throw away all reports, except for the reports from the last retry

2020-12-09T15:07:04.283100Z

ah right makes sense

plexus 2020-12-09T15:07:42.284200Z

#(= :fail (:type %)) this is not correct, there are multiple assertions types that can mean failure, use the helpers that exist for this, see kaocha.hierarchy

plexus 2020-12-09T15:08:30.284500Z

also those global atoms 🙈

plexus 2020-12-09T15:08:42.284800Z

but good job! glad to see this come together

2020-12-09T15:11:43.285100Z

hehe well I'll be happy to remove the atoms if I find out how

2020-12-09T15:11:59.285900Z

and yeah cool I'll fix the fail check

2020-12-09T15:12:10.286500Z

have to also add a few tests for the plugin as well

plexus 2020-12-09T15:12:51.287300Z

you have access to the test-plan/config in every hook, and if not you can get it through a dynamic variable, so you can use any hook that runs relatively early to assoc them on there

plexus 2020-12-09T15:14:57.288300Z

but really they're only used in a fairly limited scope, you could also add a new atom onto each leaf testable in pre-test, together with setting the testable/wrap

2020-12-09T15:16:39.288600Z

ah right cool I can try

2020-12-09T15:17:08.289400Z

thanks for the help, not sure I would have got to something almost working otherwise 😄

plexus 2020-12-09T15:19:04.289800Z

of course! always happy to help, especially people making kaocha plugins 🙂

plexus 2020-12-09T15:19:54.290600Z

I still think the design of kaocha is quite elegant, it's definitely powerful, but it's not trivial. Maybe some day I'll get to make some explainer videos 🙂

2020-12-09T15:42:05.290900Z

yeah it's very nicely done for sure

2020-12-09T15:42:22.291500Z

the problem is maybe that's just quite hard to deal with these massive nested maps

2020-12-09T15:42:40.292Z

even on a tiny project (which is what I use to test my plugin) it can be tricky sometimes

plexus 2020-12-09T15:43:37.293300Z

yeah that's true, there's so much in there that it's hard to just inspect them. I have a good "mental map" of what they look like, that's perhaps the hardest thing to communicate. Even with the specs and everything. Maybe something like Portal can help here

2020-12-09T15:44:12.293600Z

ah nice didn't know about portal

2020-12-09T15:44:20.293900Z

I used cider-inspect sometimes

2020-12-09T15:44:29.294400Z

and it helps for sure

2020-12-09T15:44:57.295100Z

also I think that sometimes in the docs or in the plugins the arguments to the various methods are called differently

2020-12-09T15:44:59.295300Z

even if they are the same thing

2020-12-09T15:45:19.296Z

which can be a bit confusing when trying to understand what something takes as argument

plexus 2020-12-09T15:48:17.297100Z

yeah some of this is a bit confusing because for instance the test-plan and the config are really kind of the same map, at the top level you find the same stuff, the test-plan is really config+information about tests

plexus 2020-12-09T15:48:24.297300Z

or test vs testable

plexus 2020-12-09T15:48:47.297600Z

do make issues if you find certain docs confusing

2020-12-09T16:08:33.298100Z

yeah config/test-plan is a good one, I would not have expected them to be the same thing pretty much

2020-12-09T16:08:52.298800Z

btw any thoughts about: https://github.com/lambdaisland/kaocha/pull/180 ?

2020-12-09T16:09:18.299700Z

I wonder if it makes sense to make it smarter instead of just blowing up like that. I guess if only test can possibly match what you want to run it could just run that

2020-12-09T16:10:13.300700Z

I don't think you would really have tests that can run in different scenarios anyway? Well maybe cljc tests can run in both cljs and clj run but can't think of much else

2020-12-09T16:17:14.301400Z

and actually for the example kaocha-cljs project, uri uses the node repl which is not something I can do anyway

plexus 2020-12-09T16:18:20.301800Z

Did you see my comment on your original issue? https://github.com/lambdaisland/kaocha/issues/179#issuecomment-736624136

2020-12-09T16:34:38.302Z

ah right no I didn't actually

2020-12-09T16:35:33.302200Z

uhm that's fine, and well my PR maybe wasn't exactly what I was suggesting in the issue

2020-12-09T16:36:04.302400Z

I mean it's fine not to specify the test-suite, but running multiple times the same test when you pass --focus is also confusing maybe

2020-12-09T16:36:25.302600Z

but well I guess it's not really a big issue, since in most cases it won't happen anyway

2020-12-09T16:36:38.302800Z

if test suites don't have overlapping paths/regexes

plexus 2020-12-09T16:40:12.303Z

you should not have duplicate test ids in a test-plan, so you should not have multiple test suites with the same type and overlapping paths. If you do you are going to get confusing results. I'd rather see us turn that into a warning or error.

plexus 2020-12-09T16:41:53.303200Z

Note that this is not the case for cljc, cljs tests have a prefix (in kaocha-cljs it's just cljs:, in kaocha-cljs2 it's the name of the connection (random but human readable), so even though the same test file is twice in the test plan (clj and cljs) their test ids are different. We do give those tests aliases so you can still --focus them without the prefix, so yes if you have cljc tests and do --focus my.ns/my-test-var it will run two tests. If you do --focus cljs:my.ns/my-test-var it will run one

2020-12-09T16:58:01.303400Z

ah I see

2020-12-09T16:58:12.303600Z

yeah ok then thanks

2020-12-09T16:58:17.303800Z

I close issue/pr

plexus 2020-12-09T17:21:21.304Z

👍