This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Hi, I am giving rcf tests a go, works nicely in clj, but won't print outputs in my (shadow) cljs app. I call the hyperfiddle.rcf/enable!
fn, but any subsequent calls to tests
don't seem to have an effect. Do I need to configure shadow-cljs somehow, is it really necessary to configure the dev-entrypoint as in the read-me?
Does it print to the browser console?
Check the value of hyperfiddle.rcf/*enabled*
in both clj and cljs REPL.
If *enabled*
is true in both clj and cljs, then tests
blocks should run. If they don’t then it’s a bug.
Can you see the effect of a println
or js/alert
?
Yes those run, a bug is what I suspected, not sure what could be causing it. I tried to remove my .shadow-cljs
and rebuild from scratch in case something went wrong there but no dice :(
the only thing that comes to mind in this project that does something with logging is taoensso.timbre
If effects run, there is no reason assertions wouldn’t run too.
You can look into hyperfiddle.rcf.reporters
. Cljs version, just call js/console.log
. I would be surprised if timbre interferes with it.
likely using two JVMs (shadow jvm doing macroexpansion for cljs is separate from the CLJ repl JVM). for cljs the enabled flag needs to be set before cljs macroexpansion happens in the shadow JVM
I'm not even sure the :cljs branch of rcf/enable! is doing anything here
(defn enable! [& [v]]
#?(:clj (alter-var-root #'*enabled* (constantly (if (some? v) v true)))
:cljs (set! *enabled* (if (some? v) v true))))
because *enabled*
is checked during macroexpansion here, which happens at compile time in the jvm
edit: ah, *enabled*
is checked once at compile time and then again at runtime from cljs, so to run cljs tests the flag needs to be set at both compile time and runtime
(defmacro tests [& body]
(let [name (gen-name &form)]
(cond
*generate-tests* `(deftest ~name ~@body)
*enabled* (if (:js-globals &env)
`(do (defn ~name [] ~(impl/tests* &env body))
(when *enabled* (cljs.test/run-block (cljs.test/test-var-block* (var ~name) ~name))))
(impl/tests* &env body))
:else nil)))
@U2DART3HA can confirm if this is correct - I didn't write it
I can see an argument for cljs not inspecting *enabled*
at compile time, the test structure should always be available at runtime in cljs (and advanced builds can dead code eliminate it)
It is correct that *enabled*
is checked at macroexpansion time and runtime.
The requirement is: tests
should behave as comment
unless RCF is enabled.
Macroexpanding tests
in cljs even if *enabled*
is false would define test functions in the namespace, breaking the premise.
Some projects cannot rely on advanced compilation.
There might be other solutions to satisfy the requirement, a configuration map could do the job:
{:clj #{:enabled}
:cljs #{:enabled :generate-tests}}
perhaps this is related? https://clojurians.slack.com/archives/C6N245JGG/p1661972965946019