Fork me on GitHub
#testing
<
2021-08-15
>
mauricio.szabo00:08:36

Recently, I've been talking with some people about testing in ClojureScript. It's harder that it needs, specially for async tests and other issues. As I'm working with lots of projects in ClojureScript, and I really do want to make testing better, I made a library called check - https://gitlab.com/mauricioszabo/check I talked with some people on ClojureScript channels, on threads, etc about this library. It's a kinda complicated macro with lots of specific handlings, but it's been working really well for me at the past 8~12 months on my projects (and I have some that deal exclusively with async stuff) so I want to share here, see what people think about it, and new ideas to make it better.

vemv01:08:36

Genuine question, would it be possible to decouple the async features from the novel syntax? Probably a good chunk of us are syntax- / churn-averse. You could e.g. offer the core as an isolated library and state in the readme that if it looks too awkward... there's a companion lib for that :)

vemv01:08:01

Also quite frankly if a lib is not under github, more likely than not I'm not going to give it much consideration I guess it's very personal/subjective but as a practical matter, cross-linking issues, commits, etc across projects is very much practical for having a full perspective of things

mauricio.szabo15:08:23

Well, for the first point, there's no "new syntax" required. Mocks can't be "decoupled" and I'm still trying to find a better way to easily represent them, but it's possible to work with is instead of check - I'll document it, but it's mostly a point of using promesa.core/let or promesa.core/then (or even JS .then) - for example: The "`check` way":

(deftest something
  (check.async/async-test "tests connection to DB"
    (check.async/testing "see if it connects"
      (check.async/check (=> true (db/connect! ...)))))
The "`is` way":
(deftest something
  (check.async/async-test "tests connection to DB"
    (check.async/testing "see if it connects"
      (.then (db/connect! ...) #(is (= true %))))))

👍 3
🙂 3
mauricio.szabo15:08:16

Unfortunately, testing also have to be aware that it's async, so it needs to stay on check.async namespace.

mauricio.szabo15:08:30

As for the second point - sorry to hear that. But it's the way it is - I have multiple concerns about the way Microsoft is handling things, and I just got the last drop and I'm slowly quitting everything MS related after they decided to use all public code without permission for a proprietary, future paid product that will probably decrease the quality of code over time and opens up a precedent for abusive behavior in the future 😞

👀 3
mauricio.szabo00:08:57

What it adds is mocking for async code (a thing that's strangely absent from libs I tried), "await" for promises like Mocha/Jest JS test libraries, teardown for async tests (also a difficult thing) timeouts (a test must run in 2s, otherwise it'll timeout. This value is, obviously, configurable), stacktraces for ClojureScript when things fail (also something strangely absent), fail-safe code (if a promise fails, it'll fail the whole test) and custom matchers with pretty messages when something fail (no more expected (= [1 2 3]) actual (not (= [1 2 3])) for example)

mauricio.szabo00:08:35

I also talked a little bit on #announcements but here I want to see if someone wants to try, and what's the bad parts that still need fixing 🙂

mauricio.szabo15:08:23

Well, for the first point, there's no "new syntax" required. Mocks can't be "decoupled" and I'm still trying to find a better way to easily represent them, but it's possible to work with is instead of check - I'll document it, but it's mostly a point of using promesa.core/let or promesa.core/then (or even JS .then) - for example: The "`check` way":

(deftest something
  (check.async/async-test "tests connection to DB"
    (check.async/testing "see if it connects"
      (check.async/check (=> true (db/connect! ...)))))
The "`is` way":
(deftest something
  (check.async/async-test "tests connection to DB"
    (check.async/testing "see if it connects"
      (.then (db/connect! ...) #(is (= true %))))))

👍 3
🙂 3