I have a custom tagged literal that I use everywhere in my Hiccup-producing functions. In my app I include the ns that defines the Var that reads the tagged literal in a central location (`my-app.main`). I need advice for how to deal with this in tests. There is no central ns to include it in there. The only approach I have come up with is to require the ns that defines the Var from a ns that I then include in all my Hiccup-testing ns-es. While this would work, it is not ideal: a) More stuff to type b) I must remember to include it in every ns Any ideas? Anybody have some global-ish stuff that you include more or less everywhere in your test ns-es?
isn't that handled by data_readers.cljc?
Yes, data_readers.cljc defines the tag and which Var should be invoked with the form. But the Var needs to be read and compiled before the code that uses the tag is read.
data_readers.cljc is:
{o/tw oiiku.data-readers.interface/tw}
So the namespace that defines oiiku.data-readers.interface/tw must be read before any namespace that uses #o/tw. In my app I make it so that the main entrypoint requires oiiku.data-readers.interface. But the test suite has no such main entrypoint.oh i thought data_readers loaded those namespaces
i would say that you should require the namespace from every namespace that produces the tagged literals
you can wrap the lazy test entry point in a custom function that you call from the command line and require the necessary namespaces there
Yeah, that's an idea. I'm using https://github.com/seancorfield/polylith-external-test-runner to run the suite, so I'll have to figure out how to make it invoke my wrapping function instead of, well, whatever it is invoking. 😅.
https://ask.clojure.org/index.php/11286/should-clojure-automatically-namespaces-defined-datareaders
there's an Ask to vote on, but i doubt rich or alex are at all interested in fixing it
alex's comments about data readers have been negative on slack in the last couple years so it seems like they won't put any effort into fixing this or making it better
There are probably Good Reasons:tm: for why it is like it is. Given the status quo, I'll have to figure out a way to always load the data reader Vars before the code that uses the tags. The most straight-forward is of course to just require the defining namespace, directly or indirectly, before using any of the tags.
as seen by the jira ticket, they've decided against working on this
yeah it's a bummer
Well, it's less reliant on magic, so that's good, I guess. Thanks for investigating/rubberducking!
i know data readers are nice but maybe you could change your hiccup functions to use the fictions instead of readers?
@msolli Polylith lets you specify per-project pre- and post- test suite functions, precisely for this kind of global setup/teardown.
See https://cljdoc.org/d/polylith/clj-poly/0.2.23-SNAPSHOT/doc/configuration#ws-projects for :setup-fn and :teardown-fn
And here's part of our workspace.edn showing usage:
:test {:create-test-runner [org.corfield.external-test-runner.interface/create]}
:projects {"development" {:alias "dev"
;; since dev now runs admin tests, it needs the broadest
;; test setup/teardown, like wsadmin below:
:test {:setup-fn ws.admin.fixtures/pre-test
:teardown-fn ws.admin.fixtures/post-test}}
"build" {:alias "b"}
"activator" {:alias "act"
:test {:setup-fn ws.application-fixtures.interface/pre-test
:teardown-fn ws.application-fixtures.interface/post-test}}(we're using a mix of clojure.test, expectations, and LazyTest with the external test runner)
Yes, this is exactly what I need! Didn't know about :setup-fn, it should do the trick. Thanks!