testing

Testing tools, testing philosophy & methodology...
Jacob Emcken 2021-06-18T10:22:43.060Z

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?

mauricio.szabo 2021-06-20T19:15:54.061400Z

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

Jacob Emcken 2021-06-21T11:50:41.061600Z

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

Jacob Emcken 2021-06-22T15:12:10.062200Z

@vemv 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 Emcken 2021-06-22T15:19:28.062400Z

@seancorfield 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.

vemv 2021-06-22T15:24:52.062600Z

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

vemv 2021-06-22T15:34:16.062800Z

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 Emcken 2021-06-22T15:45:20.063100Z

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 Emcken 2021-06-22T15:48:22.063400Z

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

vemv 2021-06-22T15:49:52.063600Z

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 Emcken 2021-06-23T06:47:19.063800Z

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.

👍 1
Jacob Emcken 2021-06-23T06:49:38.064Z

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

mauricio.szabo 2021-06-24T01:48:49.064400Z

@jacob429 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 😄

mauricio.szabo 2021-06-24T02:03:53.064600Z

An example on how I did in a project: https://github.com/mauricioszabo/duck-repled/blob/master/test/duck_repled/tests.cljs#L33-L41

vemv 2021-06-18T10:29:43.060100Z

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 Emcken 2021-06-18T10:49:25.060400Z

thanks, gonna take a look

Jacob Emcken 2021-06-18T12:59:23.060600Z

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.

vemv 2021-06-18T13:01:48.060900Z

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

seancorfield 2021-06-18T15:12:21.061200Z

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.