testing 2024-08-27

what's the current best choice for running clojurescript tests in CI (leiningen + shadow-cljs)? Karma is deprecated, so I'd rather not use it. At first I thought using shadow-cljs to create tests for node.js would be great, but a lot of our code refers to various js/foo variables which are only available in a browser environment (as far as I understand). There's a bunch of js test frameworks (jest, vitest etc) but it seems I can't just write clojure.test tests but instead have to use their own API's for tests.

πŸ‘€ 1

I have this exact issue, where I have a library written in cljc and I’d like to target both JVM and node for the tests to be 100% sure of the results when targeting cljs

I found this example from tick. They write their tests in cljc and run them with Kaocha.cljs for clojurescript. They even run them for babashka https://github.com/juxt/tick/blob/master/test/tick/api_test.cljc https://github.com/juxt/tick/blob/master/.github/workflows/tests.yaml

πŸ‘€ 1
κΉ€νƒœν¬(taehee kim) 2024-08-27T14:58:42.068179Z

I'm just using vitest browser mode. It is good Karma Alternative. But as you mentioned, It's not compatible with clojure.test So we have to use decribe, test, promise etc... I think we can make vitest compatible plugin someday.

Ideally I'd like to be able to write at least some of the tests with clojure.test in .cljc and run them both on the JVM and on a js environment

2

e.g. to check that calculations or domain functions work in both environments, not really looking for something for testing DOM stuff

κΉ€νƒœν¬(taehee kim) 2024-08-27T15:02:48.087169Z

Oh. It makes sense.

κΉ€νƒœν¬(taehee kim) 2024-08-27T15:05:22.998949Z

I think there is "puppeteer with cljs test setup" something, somewhere...

I guess in the short term I can move forward with testing with node.js, as long as I make sure that any references to js/.. fields are either moved elsewhere or wrapped in exists? checks (which seems to fix any ReferenceError issues). As I said, most of the code I'd like to check is just business logic so it shouldn't depend on some browser feature anyways. But still, I'd love to hear what other folks are doing in similar situations

wrote up an Ask about a feature that I think would be helpful for test library writers in the future. i'm interested to hear any feedback on the idea: https://ask.clojure.org/index.php/14089/separate-bindable-reporting-function-from-clojure-report

βž• 2

@cfleming would this be helpful for Cursive? i know you've said you have to monkeypatch/work around clojure.test's reporting system before

@lee that's a great change to testing, i wish that's how testing worked already

❀️ 1

Thanks @nbtheduke, I'll read through that in detail and try to get my head around it - looks like some interesting links there to investigate too.

πŸ‘ 1