shadow-cljs

valerauko 2025-06-12T06:05:46.343919Z

What's the testing story for shadow-cljs like nowadays? I noticed that karma is deprecated and I'm not sure what to do/use to run tests both during dev (like the :browser-test target) and on CI

thheller 2025-06-12T06:19:57.708979Z

I don't really consider it a concern for shadow-cljs. shadow-cljs just builds the stuff, something else runs the actual tests. The testing targets where only really meant to show how stuff works. I have no time or interest to maintain actual test frameworks.

thheller 2025-06-12T06:20:15.862059Z

pick a testing tool/framework and I can make suggestions on how shadow-cljs could produce output usable by it

valerauko 2025-06-12T06:27:24.885189Z

The old JS project in the org uses vitest so I'd prefer to use that unless prohibitively complicated

thheller 2025-06-12T06:29:02.127179Z

should be fine. probably best to use the :esm-files target. so {:target :esm-files :output-dir "out" :ns-regexp "-tests$"}

thheller 2025-06-12T06:30:00.216059Z

possibly with :js-options {:js-provider :import} in case vitest also builds stuff? not really sure

valerauko 2025-06-12T06:31:56.845239Z

I saw some prior art like https://github.com/mkarp/shadow-vitest but it looked like the clojure.test stuff would need to be rewritten for vitest. I don't see how would the browser-test target work then?

thheller 2025-06-12T06:32:44.658679Z

🤷

thheller 2025-06-12T06:33:05.440959Z

I have never executed vitest, so absolutely no clue what it does. I'd assume it does the same as :browser-test so dunno why you'd need two different builds?

valerauko 2025-06-12T07:07:50.169719Z

What do you usually use to run tests?

thheller 2025-06-12T07:10:13.513379Z

I don't usually test UI code, so all the tests that I do have in CLJ (if cljc) or node

thheller 2025-06-12T07:10:34.440619Z

I'm not a testing enthusiast, so there aren't that many tests actually

Harold 2025-06-12T15:07:55.658849Z

We have a test build like this:

:test
          {:target :node-test
           :output-to "target/test.js"
           :ns-regexp ".*test$"}

Harold 2025-06-12T15:08:13.176209Z

And a script like this:

#!/bin/bash

echo "==================="
echo "Testing Debug Build"
npx shadow-cljs compile test && node target/test.js

echo "====================="
echo "Testing Release Build"
npx shadow-cljs release test && node target/test.js

Harold 2025-06-12T15:08:44.634769Z

And it's great. 🙂

valerauko 2025-06-12T11:15:27.356339Z

Does the :source-map true compiler option get ignored for :release builds?

valerauko 2025-06-12T11:17:17.677779Z

I have a config like below

:builds
{:vitest
 {:target :esm-files
  :js-options {:js-provider :import}
  :modules {:main {}}
  :release {:compiler-options {:source-map true}}
  :ns-regexp "-test$"
  :output-dir "target/vitest"}}
but shadow-cljs compile vitest doesn't seem to generate any .map files Am I missing something?

valerauko 2025-06-12T11:22:21.869669Z

Never mind the files seem to be in position I was just looking at the wrong location

thheller 2025-06-12T12:38:00.733999Z

FWIW you can skip the :release part, just :compiler-options {:source-map true}. Also :esm-files does not take a :modules option, so it doesn't do anything there

❤️ 1