Fork me on GitHub
#kaocha
<
2020-11-27
>
reefersleep00:11:16

Is such a thing as cljc tests possible? That is, tests that run in both cljs and clj. (I want to test some macros that are defined in cljc 🙂 )

reefersleep00:11:29

Turns out it is; HoneySQL is a library with such tests! https://clojurians.slack.com/archives/C03S1KBA2/p1606436180241300

plexus07:11:22

Sure, we do this for instance in lambdaisland.uri , using kaocha and kaocha-cljs https://github.com/lambdaisland/uri

reefersleep22:11:40

Cool, a different way to do it. How do you run them?

reefersleep23:11:28

It’s probably obvious to people more well versed with clj and deps.edn - I’m still getting into it.

plexus07:11:43

standard kaocha stuff, see tests.edn and bin/kaocha

reefersleep08:11:12

Right you are 🙂 Thanks.

andrea.crotti09:11:58

I've done a first crude attempt to retry tests automatically https://github.com/lambdaisland/kaocha/pull/176 It's not really working as hoped for and I would it's a bad idea to do it that way, but so for I could not think of another way.

plexus10:11:46

That's cool @andrea.crotti. Why don't you go ahead and release this yourself? the whole point of the plugin infrastructure is that anyone can release a plugin. That way it's easy and cheap for people to experiment with ideas. Once it's in core we are committed to supporting it forever, and to not break or change its existing behavior.

andrea.crotti10:11:23

yeah well I didn't open the PR to merge it sorry (that's why it's just a draft)

andrea.crotti10:11:37

just to have something to show to understand what I'm doing wrong

andrea.crotti10:11:50

but yeah eventually when it works I can deploy it myself surely

andrea.crotti10:11:08

but it's quite far from actually working atm

andrea.crotti10:11:22

I'd just like to understand if you have any suggestions about how you would do that

plexus10:11:03

sure, I would start by using a more fine grained hook. Do you absolutely want to run all tests first before retrying, or is it also fine to retry a failing test immediately?

plexus10:11:00

you're using post-run which returns a full nested test plan, you'll need a lot more logically to correctly deal with that. If you can use post-test then you can deal with one test at a time

plexus10:11:30

you might also be interested in kaocha.result/failed? or kaocha.result/failed-one?

andrea.crotti10:11:19

ah yes I haven't tried post-test but that looks more suitable

andrea.crotti10:11:31

and yeah I saw failed? but I needed to get the l ist of failed tests

andrea.crotti10:11:37

which I could not get from failed?

plexus10:11:00

(filter failed-one? (test-seq ...)) doesn't work?

andrea.crotti10:11:14

ah good point I didn't try that

andrea.crotti10:11:45

and the other question is how to make the reporting work (discarding the runs where the test failed)

andrea.crotti10:11:24

but maybe if I use the other more granular hook it will work directly

plexus10:11:27

that's harder... you'll have to intercept the reporting events first, and then replay them if necessary

andrea.crotti10:11:51

ah ok yeah I see

andrea.crotti10:11:09

and last question is if makes sense to use kaocha.repl/run in a plugin

plexus10:11:22

you can use pre-report to intercept reporting events, change failing events to succeeding for instance, then replay the failure if all retries fail

plexus10:11:46

alternatively you can use wrap-run to temporarily rebind the reporter...

andrea.crotti10:11:01

ah cool yeah lots of possibilities

andrea.crotti10:11:15

ok thanks I'll try a few more things

plexus10:11:16

hmmm no I wouldn't use repl/run in a plugin. The repl namespace is really only meant for direct repl use, not as an API

andrea.crotti10:11:41

ah yeah I thought it wasn't a great idea

plexus10:11:15

if you want to re-run single test/testable testable/run-testable is your friend