Fork me on GitHub
#kaocha
<
2020-04-18
>
Sean Poulter04:04:02

Hey folks, can I ask a silly question? I’ve been exploring if I can get kaocha-cljs set up to run our tests in a shadow-cljs project. It is expected that that’ll our npm imports like (require ["axios" as :axios-js]) will fail? I found the cljs compiler options in https://github.com/lambdaisland/kaocha-cljs/issues/25 which got things pretty set up, but it seems like clever Thomas Heller has outdone the :npm-deps

Caused by: clojure.lang.ExceptionInfo: Only :as, :refer and :rename options supported in :require / :require-macros; offending spec: ["graphql-tag" :default gql] at line 1 src/app-ns/network/apollo_client.cljs
So .. the silly question is, could I work around this writing a kaocha-plugin using the config and pre-load scripts to add the npm-deps and rewrite the invalid imports like above? Would that be enough to make it work?

Sean Poulter04:04:40

Anyone solved that problem before, or should I abandon and just use a shadow-cljs browser tab?

plexus06:04:45

Hi @sean.poulter, honestly I don't know if this would be enough or not. The fact is that when you're using shadow you're using non-standard ClojureScript, your code is no longer compatible with other clojurescript tools. This is something that Thomas downplays but it's a thing. (I say this as someone who has developed a tremendous amount of appreciation for shadow, I use it by default on my cljs projects now, but it's really something to be aware of).

plexus06:04:09

There are possibilities for making kaocha-cljs work with shadow, and some options have been explored. The easiest short term solution would probably be to use shadow's prepl instead of the clojurescript prepl. Not sure what issues you'd encounter along the way but if I wanted to have something working soon this is what I'd be exploring.

plexus06:04:56

That said for a client we are working on a shadow-compatible test runner for the browser that should already give you a better experience than the stuff that is currently available, which will be fully open sourced. It's fully cljs, so it does not work with Kaocha, does not provide a CLI interface, etc, but it brings a lot of the principles of Kaocha to the frontend. When that is all shipped and done we're going to look at using that as a foundation for a new kaocha-cljs. The idea would be that this becomes a remote controller that kaocha talks to. As long as you are able to add it to your build and load it in a JS runtime we are good, so compilation and runtime loading would be decoupled (currently the cljs repl-env's complect these two things), and they would be fully pluggable, so we don't have to care what you use for your compilation.

🎉 8
sheepy 4
👍 4
Sean Poulter17:04:44

Thanks so much (again) Arne! Let me know how I can help on the shadow-compatible test runner and further. As long as I'm working with ClojureScript, I'm motivated to chip away at making the testing story better.

Sean Poulter17:04:19

Is that new runner going to be structured to use web workers? ☺️