Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable watch mode for recompiling cljs tests after files change? #35

Open
hirunatan opened this issue Jul 25, 2024 · 0 comments
Open

Comments

@hirunatan
Copy link

Hello. I'm not sure i'm understanding how kaocha-cljs2 is supposed to work. I'm writing some ClojureScript library code, so it doesn't need a browser to run tests. I've managed to make a setup that builds a test bundle with shadow-cljs, with :target :node-test, adding the chui-runtime and setting autorun. So when I compile it, it opens a websocket with funnel, and start listening to run tests on demand from kaocha runtime. But I can't find a way of forcing the bundle to be recompiled when some source file changes.

Here is my configuration in shadow-cljs.edn:

{...
 :builds
   {:test
     {:target    :node-test
      :ns-regexp "^mylib-tests.*-test$"
      :output-to "target/tests.cjs"
      :output-dir "target/tests/"
      :test-dir "target/tests" del wp y el tríptico? del wp y el tríptico? del wp y el tríptico?
      :autorun true
      :runner-ns kaocha.cljs2.shadow-runner
      :main kaocha.cljs2.shadow-runner/start
      :preloads [lambdaisland.chui.remote]}}}

I run the build with

clojure -M:dev:shadow-cljs-kaocha compile test

with this alias in deps.edn:

{...
  :aliases
    {:dev
      {...
       :shadow-cljs-kaocha
       {:main-opts ["-m" "shadow.cljs.devtools.cli"]
        :extra-deps {lambdaisland/kaocha-cljs2 {:mvn/version "0.2.72"}
                     lambdaisland/chui {:mvn/version "1.2.205"}}}}}

And then I start kaocha this way:

clojure -M:dev:test --watch

Also with an alias:

{...
  :aliases
    {:dev
      {...
       :test
       {:main-opts ["-m" "kaocha.runner"]
        :extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}
                     lambdaisland/kaocha-cljs2 {:mvn/version "0.2.72"}}}

When shadow-cljs is run, it correctly compiles the build, load tests and opens a web socket:

$ clojure -M:dev:shadow-cljs-kaocha compile test
[:test] Compiling ...
========= Running Tests =======================
[lambdaisland.funnel-client] {:connecting "ws://localhost:44220", :line 54}
[goog.net.WebSocket] "Opening the WebSocket on ws://localhost:44220"
[kaocha.cljs2.shadow-runner] {:lambdaisland.chui/capture-test-data! {frontend-tests.util-simple-math-test {:name frontend-tests.util-simple-math-test, :meta {:
file "frontend_tests/util_simple_math_test.cljs", :line 7, :column 5, :end-line 7, :end-column 41},
...

And then I can launch kaocha runner and execute tests. And if I add --watch mode, it runs the tests again if sources change, but because shadow-cljs does not trigger, the build does not change and the executed tests are the same of the previous run, I can't see the changes.

Is there any way to tell chui to watch the source files? Or to relaunch shadow-cljs on changes?

Or is there a different, better way to do all of this? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant