Fork me on GitHub
#testing
<
2021-06-18
>
Jacob Emcken10:06:43

I have a .cljc file with reader conditionals in for both Clojure (Java) and ClojureScript (Node). I would like to get inspired from others who are testing both... have you any links to existing public repos doing this in a way you think is good?

vemv10:06:43

https://github.com/nedap/speced.def does plenty of reader conditionals in test/. I find it a sound approach overall, don't recall problems from it.

Jacob Emcken10:06:25

thanks, gonna take a look

Jacob Emcken12:06:23

What is this file for: https://github.com/nedap/speced.def/blob/master/src/nedap/speced/def/test.cljc I found it confusing to find something outside the test folder which seems to be related to tests.

vemv13:06:48

That's a minor ns, it provides better IDE integration for Cursive users when using (is spec-assertion-thrown?) clojure.test's API is a bit odd about how to extend it (namely with multimethods, which won't play always nicely with IDEs, linters, etc) See also https://github.com/nedap/speced.def#testing

seancorfield15:06:21

Take a look at how HoneySQL does this: it's all cljc files and the run-tests.sh file runs both clj and cljs tests.

mauricio.szabo19:06:54

@USW6URK47 do you also will need to test async functions?

Jacob Emcken11:06:41

@U3Y18N0UC not at the moment anyway. I'll cross that bridge when (if) I get there

Jacob Emcken15:06:10

@U45T93RA6 I can get the tests running, and I see the feedback on STDOUT, but "return value" of node target/out/tests.js is the same regardless of success or failure. It doesn't play nice with my CI/CD pipeline.

Jacob Emcken15:06:28

@U04V70XH6 thanks for the pointer to HoneySQL. Sadly for reasons outside things I can change I have to use lein in the foreseeable future for the project I'm working on.

vemv15:06:52

I don't think that's the case. We've paid close attention to the return value of the Node process If I intentionally break a :cljs reader branch, CircleCI will fail as expected: https://github.com/reducecombine/speced.def/commit/b1f20a3603268bd2e5c2f85e6f9d1ee2bb44647e

vemv15:06:16

The magic sauce being https://github.com/nedap/utils.test/blob/1d4f5a66e89b4703bb8ab227021441946d295373/src/nedap/utils/test/api.cljc#L32-L42 IIRC many codebases implement their own flavor of this - you're right that the unix return code is a gotcha, but not an insurmountable one

Jacob Emcken15:06:20

I was looking at this: https://github.com/nedap/speced.def/blob/master/test/nedap/utils/spec/test_runner.cljs I must admit I expected less DIY and more "plug this and it works". I guess lein test set my expectations a bit to high when it came to ClojureScript 😄

Jacob Emcken15:06:22

I will take a look at the "magic sauce" 😄

vemv15:06:52

lein test generally hasn't worked well for me for running two targets at once (jvm + node). it's seems 'complected' to me, which is why it's explicitly disabled in project.clj

Jacob Emcken06:06:19

lein test works in my opinion VERY well for Clojure (JVM) only. No hairy setup or knowledge about "test runners" is necessary - it just works as expected. A combined Clojure and ClojureScrip (JVM + node) is an entirely different story - sadly.

👍 2
Jacob Emcken06:06:38

The JVM-only experience had set my expectations very high for a combined project. Expectations that obviously was not met 😅

mauricio.szabo01:06:49

@USW6URK47 Are you using CLJS with Shadow-CLJS? If so, there's a target called :node-tests that do what you want. If you don't, or can't, use it theres another option like re-defining the summary to exist on the right exit code 😄