polylith

itaied 2026-02-12T14:12:55.650409Z

hello i'm trying to build a test-runner for cljs with shadow-cljs my strategy is to find bricks of projects that contain a build name :node-test how can i find the modified bricks in a project and their locations? i could do it with string bashing and bricks-to-test but i don't like it

(defn brick-dir
  "Get the directory path for a brick (e.g., 'bases/presets' or 'components/foo').
   Avoids string concatenation by using io/file to construct the path."
  [{:keys [type name]}]
  (-> (io/file (str type "s") name)  ; "base" + "presets" → "bases/presets"
      (.getPath)))

(defn find-shadow-cljs-dir
  "Find the directory containing shadow-cljs.edn with :node-test build.
   Only checks bricks marked for testing in :bricks-to-test."
  [runner-opts]
  (let [project-dir (get-in runner-opts [:project :project-dir])
        workspace (get runner-opts :workspace)
        bricks-to-test (set (get-in runner-opts [:project :bricks-to-test]))

        ;; Get only the bricks that need testing
        all-bricks (concat (:bases workspace) (:components workspace))
        bricks-needing-test (filter #(contains? bricks-to-test (:name %)) all-bricks)

        ;; Get directories for bricks being tested
        brick-dirs (map brick-dir bricks-needing-test)

        dirs-to-check (cons project-dir brick-dirs)]

    ;; Find first directory that has shadow-cljs.edn with :node-test
    (some (fn [dir]
            (when (.exists (io/file dir "shadow-cljs.edn"))
              (try
                (let [shadow-config (edn/read-string
                                      (slurp (io/file dir "shadow-cljs.edn")))
                      builds (:builds shadow-config)]
                  (when (contains? builds :node-test)
                    dir))
                (catch Exception _
                  nil))))
          dirs-to-check)))
what do you think?

itaied 2026-02-15T16:50:36.909849Z

i have added an implementation proposal i am working on something locally how do you suggest sharing it?

seancorfield 2026-02-15T17:36:38.843479Z

Would a draft PR work, so we can go back and forth/discuss?

seancorfield 2026-02-15T20:33:35.386879Z

Thanks. Will look at this tomorrow.

👍 1
seancorfield 2026-02-12T14:19:00.611129Z

The test runner is created for each project that has changes / needs testing.

seancorfield 2026-02-12T14:20:43.034759Z

Have you looked at my external test runner? BTW, I'm planning to add .cljs capability to my external test runner -- I think there are two options: via Shadow-cljs or via Olical's cljs-test-runner. I'm only familiar with the latter but maybe you could help contribute machinery for the former?

itaied 2026-02-12T14:26:21.416669Z

yes! i would like, i'm doing it now internally for my project and i think it will be very useful yes i am looking at your external test runner for inspiration and i see that you also build the dir of the bricks from the project

itaied 2026-02-12T14:26:33.358679Z

specifically the "brick-test-namespaces"

seancorfield 2026-02-12T15:01:19.901889Z

The workspace map is passed in when the test runner is created, and that probably has mappings to directories etc so the ns->directory mapping could probably be done that way, but it is easy to do the mapping directly.

seancorfield 2026-02-12T15:07:13.206369Z

I created placeholder issues for cljs support if you want to add notes there https://github.com/seancorfield/polylith-external-test-runner/issues

👍 1
1