Fork me on GitHub
#clojurescript
<
2022-08-18
>
Daniel Gerson20:08:40

Hello. How do you run a single cljs.test/deftest, not the whole namespace through reporting? (`run-tests` works fine for the whole namespace). Running (`my-test`) doesn't go through reporting. My environment is react-native so I don't want to investigate a framework intended for the browser. My output is appended to the android console, I'd like to colour highlight the failure status of the test, to distinguish it from significant other output.

Daniel Gerson20:08:35

I suspect you can't, and it wasn't intended to be run this way... but run-tests is terse code that is doing a lot, so I thought I'd ask before attempting to either write my own runner, or delve into it.

thheller20:08:01

(cljs.test/test-vars [#'foo/bar]) IIRC

Daniel Gerson20:08:10

@U05224H0W Thanks, but this doesn't appear to write the results to the report so that I can use (defmethod cljs.test/report .... It just runs a test in isolation.

thheller20:08:18

yeah cljs.test is a bit of a mess since half of it is hidden in macros

👍 1
Daniel Gerson20:08:22

As per usual, it helps to understand the code (which I was trying not to have to 😅). I can solve my problem by overriding (defmethod cljs.test/report [:cljs.test/default :fail].. instead of the :end-run-tests from the documentation. Then it doesn't matter how I run the test on the outside. The report function appears to be used everywhere.

Daniel Gerson20:08:10

Admittedly it solves my objective, but not as asked.

skylize20:08:05

from https://clojuredocs.org/clojure.test and from https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/test.cljs >

In that case, you must define a special function
>    named "test-ns-hook" that runs your tests in the correct order:
> 
>    (defn test-ns-hook []
>      (arithmetic))
> 
>    Note: test-ns-hook prevents execution of fixtures (see below).
So as long as you don't need fixtures, you should be able to simply define the function test-ns-hook and list off the tests you want to run. The intended purpose of this function is to let you compose tests together, then list only the composite tests to run.

👍 1
Evan Z21:08:32

one of the assets I need, rc-picker , has a file node_modules/rc-picker/assets/index.less that needs to be compiled. How can I make this happen using shadow-cljs?

thheller21:08:41

not supported. you can use another tool to process css (eg. postcss)

Evan Z21:08:06

how do you typically handle styling in large apps you’ve worked on?

thheller21:08:42

I have used node-sass, tailwind, and a couple of my own tools (which basically just concatenated a few files together)

Evan Z21:08:07

interesting. So when you use a third party library that has a .less file, do you hard code for it to be compiled or is it a more automatic process?

thheller21:08:08

I have never used a library that required me to use a .less file, so cannot answer that 😉

thheller22:08:00

I have used libs that wanted .css and I just added to them my "build" command (which at times where just bash files, newer ones had clojure functions)

isak22:08:41

We just use webpack in addition to shadow-cljs, I imagine that is pretty standard

isak22:08:27

(and webpack of course has support for less, postcss, etc)

thheller22:08:28

cp src/css/main.css public/css/main.css && cat node_modules/rc-picker/assets/index.css >> public/css/main.css could be all you need 😛

thheller22:08:52

or (spit "public/main.css" (str (io/file "src" "css "main.css") (io/file "node_modules" "rc-picker" "assets" "index.css"))) in a function

Evan Z22:08:34

yeah — why overcomplicate it. The module path is stable