Support ClojureScript?
seancorfield opened this issue · 8 comments
I don't do cljs at all so I've no idea what is needed here, nor how to ensure tests run for the cljs version so contributions are welcome!
The short story — I have ported expectations.clojure.test to cljs and gotten it to work in a limited self-hosted cljs environment — i.e., using planck.
The story behind this is that I have about 1000 tests for zprint using classic expectations using clj, and never tried to get them to work with cljs. So I thought it time to get the tests working in cljs. I had most of the clj tests ported to expectations.clojure.test before I realized that it didn’t support cljs. So I gave porting expectations.clojure.test to cljs a shot and managed to get it largely working. I now have 950+ zprint tests working in cljs. These don’t use the full range of expectations, for sure. But at least the basic stuff works.
I also made a couple of additions, including adding the “actual” form to the msg output on a failure, since cljs isn’t yet capable of yielding a file and line number accurately. Also, I liked the ability to retry the test from the output that classic expectations provides where you can copy and paste the “actual” form into a repl and try it without having to go to the test file to find it. I also extended the string diff on failure to have the classic expectations “same, expected deviated, actual deviated” approach, since many of my tests return long strings and the =/!= string diff leaves one hanging when the string is long.
Anyway, I don’t claim to have “fully” ported this to cljs — I have exactly one path that works using planck. The changes for cljs aren’t extreme, though figuring them out was a good bit of work. The documentation is almost certainly more work than the changes to the code.
I did this in a cloned repo, as i didn’t expect it to really work so I haven’t even forked it yet.
Is this work interesting to you? I’m willing to clean it up into a pull request and document what I’ve done so that someone else could use it in a self hosted environment. I’m not volunteering to test it in every cljs environment (of which there are several), but I think what I’ve done so far would get someone a good way toward making it work in some additional cljs environments.
It is really nice to have the same tests in both clj and cljs, now that I have made it work.
My ideal is one codebase in a .cljc file or possibly macros in a .clj and non-macro code in .cljc. What approach have you taken?
OK, then it sounds like this could be a good basis for a version that runs on both Clojure and (at least some) ClojureScript platforms. If you're willing to get things together into a pull request, I'd be happy to take a look and provide feedback so we can get it merged and get the next step toward expectations.clojure.test running on both platforms as .cljc.
If it helps, take a look at https://github.com/seancorfield/honeysql to see how it runs tests for both Clojure and ClojureScript.
Ok, I’ll work on a pull request. I want to do a bit more experimentation on the (expect <class> ...), since I only made that work when the class was exactly js/Error, which is the only case that mattered to me. I noticed that the classic expectations has as approach which seems to be more general, and I want to see if I can get any ideas from it. I’ll put things together into a pull request once I get that figured out.
I’ve made the basic modifications to convert test.clj -> test.cljc, and have also managed to get the tests to work in both clj and cljs (which was arguably as hard has getting the basic modifications to work). When I try to use this library to run the 945 tests I have in zprint, I couldn’t get it to work. The experimental version I hacked on first works, but this new one isn’t even found. Turns out that doo strains out .jar files that start with */clojure-* from self-hosted Clojurescript (which is required). My hacked version was expectations/cljc-test, but the “real” version for which I am preparing a pull request remains expectations/clojure-test. Which doesn’t work with doo (used by cljs-test-runner). Took me a while to figure that out, I must say.
The way forward from here is either to try to get doo to accept more self-hosted cljs namespaces or to change the name to something that doesn’t start with “clojure-“. Looks like doo hasn’t had much activity in the last two years or so, and it has 38 issues, so I’m a bit skeptical of waiting for that. The other approach is to change the name. I can say that expectations/cljc-test will work, as that is what my hacked up test version uses and it works.
I’m hoping that changing the name would be acceptable (since I would like to use the new version of this library, and if we wait for doo to change and then cljs-test-runner to pick it up, we’ll be waiting a good while).
Suggestions as to where we go from here? Any better name than expectations/cljc-test?
Nothing is ever easy...
Thanks!
What a weird restriction -- it cares about the JAR file name but doesn't mind that the namespace has clojure in it :)
I'm fine with changing the artifact ID (so it'll be expectations/cljc-test instead of expectations/clojure-test) since the artifact ID doesn't impact the code itself in anyway.
Sounds like you've made great progress so, yeah, keep going on toward a PR -- I really appreciate this!
Fixed via PR #16