lambdaisland / kaocha-cljs2

Run ClojureScript tests from Kaocha (major rewrite)
Mozilla Public License 2.0
26 stars 10 forks source link

Is it possible to run the tests without UI injected? #10

Closed Valdermeyder closed 1 year ago

Valdermeyder commented 3 years ago

For CI or Git push hook cases the Chui UI is not needed at all, is it possible to run tests without it?

plexus commented 3 years ago

Yes

Valdermeyder commented 3 years ago

@plexus is it described somewhere? I have tried to understand how to do that but failed 😢

plexus commented 3 years ago

What are you doing now exactly? You don't need the chui UI for kaocha-cljs2, and you don't need kaocha-cljs2 to be able to use the Chui UI.

Chui consists of multiple pieces. The core test runner which is really just headless state and logic, and chui-ui or chui-remote to control it. You can use either or both. Kaocha-cljs2 only requires chui-remote.

With kaocha-cljs2 there are dozens of ways to wire things up, so you need to start telling me everything about your clojurescript and testing setup.

Valdermeyder commented 3 years ago

I have tried to use what is described in Readmes and examples across kaocha libraries. I use shadow-cljs to manage the re-agent/re-frame project, for tests cljs.test is used together with @testing-library for component tests where it is needed. Below is how the test target looks like

          :test {:target    :browser-test
                 :runner-ns kaocha.cljs2.shadow-runner
                 :test-dir  "target/test"
                 :ns-regexp ".*-tests$"
                 :devtools {:preloads [lambdaisland.chui.remote]}}

On CI (or during hook) I am starting the shadow-cljs server and compile the :test target. After that, the headless browser is opened with a URL where "target/test" content is hosted. The last step is to run all tests using kaocha runner. The kaocha configuration below:

             {:id :unit-client
              :type :kaocha.type/cljs2
              :ns-patterns ["-tests$"]
              :test-paths ["src/test/cljs" "src/test/cljc"]}

I suspect that shadow-cljs :runner-ns is a place where changes have to be made, but I may be wrong. Please let me know in case some additional information is needed. I would appreciate any advice which can simplify the workflow I have built so far

Side note: before kaocha karma was used which did its job by running tests but the reporting there was very poor to analyze what tests were run. kaocha is much better from the reporting perspective specifically. However, I have noticed that kaocha requires much more resources which increases the overall time of test execution on environments with limited resources (this could be a topic for another discussion and probably requires more investigation)

plexus commented 3 years ago

That all looks good. What is the behavior you are seeing?

The best place to start debugging is Funnel. Make sure funnel is started with verbose logging (funnel -vv), then you can see in fine detail what's going in between the browser and Kaocha.

Valdermeyder commented 3 years ago

Everything works fine, I am looking for a better (lighter) way to run tests. And one way I see this is to remove Chui UI which I don't need during the headless run. Do you know which part is responsible for UI injection? Is it kaocha.cljs2.shadow-runner or some other part?

plexus commented 3 years ago

Yes, just copy that namespace and tweak it?

https://github.com/lambdaisland/kaocha-cljs2/blob/master/src/kaocha/cljs2/shadow_runner.cljs#L29-L32

remove lines 6 and 29-32.

alysbrooks commented 1 year ago

I don't think this would be too difficult to document, but I'm not sure this is a workflow we want to prioritize documenting.

Feel free to ask further questions here or on Clojurians!