Fork me on GitHub
#kaocha
<
2019-06-06
>
countgizmo11:06:41

hi all! has anyone successfully used kaocha-cljs for a cljs project? I’m in great need of inspiration and help 🙂

zane17:06:11

I have! What's on your mind?

countgizmo03:06:05

I can’t quite understand (my limitation, not Kaocha’s!) how to run cljs tests in my cljs project. Context: I have a cljs app (re-frame, etc.), I would like to run cljs tests of this app in the browser (using Kaocha and I’m guessing browser.repl). And whatever I do, I cannot get it to work. I think an example or a high level architecture would be enough for me to understand it 🙂 Like, how do I start my app, where do I put the repl/connect bit (if I need it at all), etc.

zane04:06:37

Right! Okay. So this is actually a bit relevant to my question here: https://clojurians.slack.com/archives/CCY2V0U6A/p1559847736004000

zane04:06:12

The idea is that you're going to tell Kaocha everything it needs to know to run your cljs tests in a tests.edn file, and then Kaocha is going to handle starting the ClojureScript process in which your tests will run itself.

zane04:06:36

The important bit is the second map inside the vector under :tests.

zane05:06:14

That map I believe needs to have an :id and a :type of :kaocha.type/cljs. Once you've done that you should be able to run your tests with either bin/kaocha from the shell or with (require '[kaocha.repl :as kaocha]) (kaocha/run) (assuming you followed the installation instructions in Kaocha's README). Note that kaocha/run must be run from a Clojure REPL, not a ClojureScript REPL.

zane05:06:29

Making sense?

countgizmo05:06:17

That part - yes 🙂 And thanks for the example. However, you’re using node as your test runtime (I’m guessing from your tests.edn example).

countgizmo05:06:38

I’m facing issues with running the tests inside a browser though 😞

countgizmo05:06:59

I know that you can pass browser.repl env to :cljs/repl-env key and I can see kaocha opening a browser but then I always get an error regarding Client not able to connect back (or something like that).

plexus06:06:13

@countgizmo that error could occur due to any number of reasons. It could be a bug in kaocha-cljs, or it could be something in your app/setup preventing kaocha-cljs from functioning correctly. If you can create a repo that you can share that reproduces the problem then I'm happy to take a look at it. Otherwise gather up as much information as possible and create an issue. You can get more detailed debug output by adding this to your tests.edn

:bindings {kaocha.type.cljs/*debug* true}

countgizmo07:06:00

@U07FP7QJ0 Thank you! I will continue to dig into it then!

zane19:06:16

Am I understanding correctly that since Kaocha is only runs on Clojure there's no way to use Kaocha to run ClojureScript tests in the ClojureScript REPL?

plexus06:06:13

@countgizmo that error could occur due to any number of reasons. It could be a bug in kaocha-cljs, or it could be something in your app/setup preventing kaocha-cljs from functioning correctly. If you can create a repo that you can share that reproduces the problem then I'm happy to take a look at it. Otherwise gather up as much information as possible and create an issue. You can get more detailed debug output by adding this to your tests.edn

:bindings {kaocha.type.cljs/*debug* true}