kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
borkdude 2020-06-30T10:01:52.365500Z

I made a PR to malli which makes sci optional: https://github.com/metosin/malli/pull/210 The tests are failing, but this is only because the order in which namespaces are loaded is random. sci.core needs to be loaded first. But since sci.core is now optional, the tests have to be refactored accordingly anyway. Just putting this here in case someone has ideas about it.

plexus 2020-06-30T10:54:47.366900Z

@borkdude seems like a good case for using a hook? that's the right place to do "global" setup

plexus 2020-06-30T10:55:53.367600Z

actually there's a preloads plugin as well which is an even better fit (thanks @danielcompton for that one)

borkdude 2020-06-30T10:56:03.367900Z

I was thinking of that one, but it only works in CLJ?

plexus 2020-06-30T10:56:27.368200Z

oh snap these are cljc tests? that's tricky

plexus 2020-06-30T10:57:05.369300Z

you could still do it with a hook, but it's not as trivial as you'd be dealing with the communication with the client

borkdude 2020-06-30T10:57:22.369700Z

I think the better option for malli is to make specific namespaces where sci is required and not in others. But that will still not test cases that should work absolutely when sci isn't there, since the randomization might cause to be loaded first in some other ns

plexus 2020-06-30T10:57:52.370100Z

you can also turn off the randomization

borkdude 2020-06-30T10:58:02.370300Z

So maybe the only way out is to use different classpaths for different tests

plexus 2020-06-30T10:58:18.370500Z

or have custom sorting logic

borkdude 2020-06-30T10:58:43.371100Z

right now I've put a (:require [sci.core]) in core-tests.cljc, just to get it working

borkdude 2020-06-30T10:59:39.372100Z

but if we have custom sorting, we can run the tests without sci first, but I expect that won't work, since it won't guarantee that some other namespace will still load sci .. or something. it's not transparent to me how kaocha handles this

plexus 2020-06-30T11:00:19.372500Z

kaocha-cljs just sends (require ...) forms to a prepl

plexus 2020-06-30T11:00:32.372800Z

each namespace gets required as it gets run

borkdude 2020-06-30T11:01:19.373200Z

ok, then the custom sorting will actually work

borkdude 2020-06-30T11:01:39.374Z

just out of curiosity: how does kaocha test optimized builds? does that also work with prepl?

plexus 2020-06-30T11:01:47.374200Z

can you somehow make this explicit? have a way to tell the dynaload/lazyvar stuff to pretend sci isn't there?

plexus 2020-06-30T11:02:16.374800Z

kaocha-cljs does not currently test optimized builds, that's one of the reasons we're taking a different approach with chui/kaocha-cljs2

borkdude 2020-06-30T11:04:50.375Z

ok

borkdude 2020-06-30T11:08:28.375400Z

I'm trying to find the custom sorting in the docs

plexus 2020-06-30T11:08:57.376Z

that's not documented as such, you'll have to look at the randomization plugin and take it from there

plexus 2020-06-30T11:10:39.377600Z

either do it this way with a plugin with a post-load hook, or use the hooks plugin and implement a test-plan -> test-plan function that you reference

plexus 2020-06-30T11:11:26.377800Z

{:plugins [:kaocha.plugin/hooks]
 :kaocha.hooks/post-load [my.kaocha.hooks/custom-sort]}

plexus 2020-06-30T11:14:09.379100Z

you can use --print-test-plan to better understand what's being passed there, basically it's a map which has :kaocha.test-plan/tests, which is a sequence of "testables" corresponding with the test suites configured in tests.edn. Each of these in turn has :kaocha.test-plan/tests which correspond to namespaces

borkdude 2020-06-30T11:16:07.379700Z

I'll wait for what @ikitommi thinks of this, before putting too much time in it. Maybe it's better to split out all the sci-related tests into one namespace, or something

borkdude 2020-06-30T11:17:41.380500Z

I was mostly doing this PR as an example how to do it, but this is turning out into a bit of a rabbit hole 🙂

plexus 2020-06-30T11:18:28.381200Z

I have to say it's an impressive hack 🙂 if someone had asked me how to do optional dependencies like this in cljs I probably would have said "can't be done"

borkdude 2020-06-30T11:18:47.381400Z

it's just a hack I stole from spec

plexus 2020-06-30T11:19:01.381800Z

someone should do a blog post about it 😉

borkdude 2020-06-30T11:19:18.382100Z

I might pull this apart into a separate lib, so more projects can benefit

borkdude 2020-06-30T11:19:23.382300Z

and then document how it works in the README

plexus 2020-06-30T11:19:31.382500Z

👍

cap10morgan 2020-06-30T19:56:32.383Z

Does kaocha-cljs work with target-bundle projects?

borkdude 2020-06-30T19:57:19.383100Z

https://github.com/borkdude/dynaload

cap10morgan 2020-06-30T20:04:01.383500Z

Or maybe I should try kaocha-cljs2?