Liking cljdoc? Tell your friends :D

MonkeyProjects Shadow-cljs JUnit XML Reporter

This is a ClojureScript library that provides a reporter for Shadow-cljs unit tests that outputs as JUnit xml. This makes it useful for improving test reporting in various build pipeline tools.


"Doesn't this already exist somewhere?" I hear you say. I thought so too, but I could not find any library that allowed this. Yes, there is Kaocha, but as far as I can tell, it doesn't provide support for JUnit in cljs, when running it as a plain Node script. Also, the cljs2 adds a lot of complexities way beyond just running it as plain JavaScript. This is not really a problem when running it locally. In fact, this lib also provides a configuration for doing just that. But in a CI/CD pipeline, having to start an additional service just to be able to output JUnit xml was going a bit too far for me.


Clojars Project

It's quite simple. Actually, this library uses it too. I assume you've already set up your Shadow-cljs project. Then add the library as a dependency in your shadow-cljs.edn:

:dependencies [...
               [com.monkeyprojects/shadow-junit-xml "<RELEASE>"]]

Next, add a build that targets node-test and use this library's test runner as your main, like this:

  {:target :node-test
   :output-to "target/js/node-tests.js"
   ;; Output as junit xml
   :main monkey.shadow.junit.runner/run-tests}}}

Then compile the code:

$ npx shadow-cljs compile test-ci

This will generate a JavaScript file as configured in the output-to property. Then run it using nodejs:

$ node target/js/node-tests.js

This will run your unit tests and output the result as JUnit xml to stdout. In order to save it to a file, redirect stdout:

$ node target/js/node-tests.js 1>junit.xml

In the above example, junit.xml should now contain the test results in JUnit format, which you can then pass on to your CI/CD tool!


Copyright (c) 2023-2024 by Monkey Projects BV.

MIT License

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close