athomasoriginal / demo-clojurescript-jest

ClojureScript and Jest
7 stars 2 forks source link

Is it demo dead? #2

Open Valdermeyder opened 3 years ago

Valdermeyder commented 3 years ago

Hello @athomasoriginal! Thank you for the great example. Have you decided to stop this initiative? If yes, any worrying reason for that? I am thinking about using Jest to run component reagent tests with help of @testing-library in my project however I am new to the ClojureScript ecosystem and I am not sure is it a great idea to do that.

athomasoriginal commented 3 years ago

Hi @Valdermeyder!!

All very good questions. Let me run through them one-by-one.

Have you decided to stop this initiative?

Not exactly. I'm always thinking of how I can use the JS ecosystem in my CLJS, but right now I haven't had enough time to revisit this demo. It was very much a learning project.

I am thinking about using Jest to run component reagent

I might rephrase this as, "what is a good way to test Reagent?" because that is the question i'm always asking myself. I also phrase it this way because if you just want to test CLJS, that is more straightforward.

I've been working with CLJS for many years now, so I feel my opinion on this has begun to become clearer to myself. Jest initially seemed like a great win because I could lean on the JS ecosystem for testing: it's battle tested and full featured. After playing with it, there is a bit of friction. Some of these are identified in this project's README.

Then I started experimenting more with the tooling provided by the Clojure ecosystem and I can say that my preference now is a combination of:

The reason is because the CLJ/S ecosystem is simple, has less friction, performance isn't an issue and you have less moving pieces which means a greater understanding of what everything is doing.

So what does this look like? I have a blog post i've been meaning to finish writing for a while. Haven't got to it yet. Having said this, what this looks like is:

The setup is light weight, transparent, almost 0 extra deps and it's been successful. A lot of the general setup here is outlined in Testing ClojureScript Apps. The part that's missing from that blog is the bit about testing helpers, and examples of testing reagent.

Hope this helps!!

Valdermeyder commented 3 years ago

@athomasoriginal thanks for so detailed response. I am also thinking to apply jest only to test components (reagent + reframe) and keep standard ClojureScript tools to test the rest part of the code. The main reason to use jest for me is @testing-library and particularly @testing-library/jest-dom part with its set of jest matchers. I found it very handy and less error-prone than writing all of the assertions manually by using jest.expect or clojure.is. I agree that jest could be a little bit overhead for testing reagent components and it would be great to find the tools closer to ClojureScript code/ecosystem. I have tried to use Karma + shadow-cljs as a test runner and it seems to work quite okay. However, I am wondered if any of the above will show good code coverage (at least generated js) or will it simplify test debugging which is a black hole for me right now? I didn't know about kaocha so maybe it answers some of my concerns, so thank you for mentioning it out Looking forward to your blog post which may help the community a lot.