Fork me on GitHub
#babashka
<
2024-02-13
>
Brandon Olivier14:02:29

Do babashka tests integrate with CIDER? I’m inclined to think so since I didn’t see any caveats on the CIDER docs, but it seems like nothing happens for me when I try to run a test.

borkdude14:02:35

The babashka nrepl server doesn't implement most of the custom CIDER stuff, just the normal nREPL ops To run tests, I usually run (clojure.test/run-test foo/bar) or whatever, or even just execute the test body in the REPL

🙌 1
borkdude14:02:55

or (clojure.test/run-tests *ns*) etc

Brandon Olivier14:02:06

Are those things possible to implement or are there technical not to?

borkdude14:02:32

In general the cider middleware stuff isn't compatible with the built-in babashka nrepl server. I think a better option might be to just develop with the regular CIDER and then run with babashka when you're done

🙌 1
borkdude15:02:26

To get the built-in dependencies on your classpath for the clj REPL, you can run bb print-deps

🙌 1
vemv18:02:36

> Are those things possible to implement or are there technical [reasons] not to? It's possible to implement - it's a matter of putting this piece of middleware https://github.com/clojure-emacs/cider-nrepl/blob/9aea519b87430c3a26cd146417dd84c33bb14676/src/cider/nrepl/middleware/test.clj into babashka-nrepl's stack. (Worth noting, cider-nrepl is a collection of middleware - you can mix and match the pieces that one actually needs) Best-case scenario, it's simply a matter of copying a few namespaces with little to no modifications. Worst-case, some degree of refactoring would be needed. We'd be certainly open to PRs adding :bb reader conditionals or so - it's simply a matter of someone volunteering to do it :)

👍 1
vemv18:02:55

...Something that you could do right now is to have bb and JVM repls concurrently open. With Sesman (cider's connection manager) one can have fine-grained routing, e.g. "use the JVM repl for foo-test ns, bb for foo ns" I don't think people have played with that a lot, but tinkering, you might get something workable. (Again, PRs welcome if we can make people lives easier there)

borkdude18:02:36

cider middleware is fundamentally incompatible with bb's nrepl server

borkdude18:02:59

the middleware in bb.nrepl is transducer-based (and wasn't designed to be compatible with CIDER, more to let users that make a similar thing as bb plug in their own additional ops from the outside) I think if I would do the whole nREPL thing in bb again I'd maybe try to load the nREPL + CIDER stuff from source

borkdude18:02:53

The middleware docs for the bb nREPL implementation is here https://github.com/babashka/babashka.nrepl/blob/master/doc/middleware.md and written by @U7RJTCH6J

vemv18:02:46

ohh TIL! Didn't know there was an alternative to nrepl middleware However a cider middleware defn is just a tiny façade defn. 99.9% of the code is orthogonal to the fact that it will be offered as middleware We could also offer bb-style façades.

borkdude18:02:34

I have tried to enable loading middleware from source and do a transducer -> CIDER middleware conversion, it worked somewhat, but some CIDER middlewares were pretty complex, e.g. they sent and awaited extra requests mid-request, which didn't fit the transducer model

vemv18:02:34

Yeah an automated conversion sounds tricky if not impossible. Some pieces of middleware definitely are 'funny' But writing them by hand each time sounds easy enough

borkdude18:02:16

if compatibility with CIDER was a goal (it didn't seem within reach at the time) I think I would just align the middleware stuff with CIDER so you could then load stuff from source. Or rewrite things in such a way that it can be entirely loaded from source. bencode.core is part of bb

👀 1
borkdude18:02:16

the builtin babashka.nrepl is a library which can be used outside of bb, this would then have a breaking change, but I don't think many projects are using this, it could also be babashka.nrepl2

👍 1
phronmophobic18:02:07

What I remember about CIDER compatibility was that one of the big draw backs was executable size.

borkdude18:02:27

the idea would be to load the CIDER middleware from source

borkdude18:02:51

there is a thread somewhere where I worked on that with @U02CV2P4J6S and you, but eventually we gave up, it was just too hard to reconcile the transducer model with CIDER

yubrshen17:03:56

I'm happy with the solution described here: https://clojurians.slack.com/archives/CLX41ASCS/p1707835535888609?thread_ts=1707835469.969249&cid=CLX41ASCS I also eventually found the equivalent information at https://book.babashka.org/#_running_tests I learned that there is rich helpful information at https://book.babashka.org/#introduction of Babashka book. I feel that it would be great to have a section on unit testing. It would be more helpful than being hidden in the section of Recipes. Furthermore, a section of FAQ might also help. For example, it might be a common knowledge to the experienced that the typical workflow of developing Babashka script may be using standard Clojure first, then verify and deploy the developed with bb. But for the new comer, who may approach Babashka without prior experience with standard Clojure, it might not be obvious.

👍 1
eval202015:02:46

Wrote an article last week that might come in handy for bb-scripts: https://polar.sh/eval/posts/til-clojure-reload-ing-when-require-ing

🆒 1
👍 1
babashka 2
teodorlu16:02:15

I've been struck by the exact same problem before, and Michiel helped me out too!

babashka 1
pez16:02:48

For a second there I thought the TIL was that you can attach a :reload to individual requires. 😃 I think I’ve only seen it last in the require form so have assumed it pertains to all.

eval202015:02:26

😄 let’s say it doesn’t help to have :reload and :reload-all

😂 1