bensu / doo

doo is a library and lein plugin to run cljs.test on different js environments.
Eclipse Public License 1.0
324 stars 63 forks source link

Integration Tests? #30

Closed xcthulhu closed 8 years ago

xcthulhu commented 8 years ago

Would it be at all possible for doo to make client-server integration testing more convenient, or is that out of scope?

It looks like the way to do it in lein is to have an alias where you spin up a ring server, run your tests, and spin the ring server back down: https://groups.google.com/d/msg/clojurescript/rArkEBCRods/Bqo4IE5ehNUJ

Anyhow this is a marvelous library and I am looking forward to using it in all of my ClojureScript projects!

xcthulhu commented 8 years ago

That poster to the ClojureScript mailing list is pretty clever BTW :D

bensu commented 8 years ago

It's not out of scope but it is not in the near future either. I implemented a bunch of functionality for browser testing and there are many corner cases to handle yet. After that I might consider implementing this and other new features. In the meantime, PRs are very welcome.

As for the implementations, in the google groups post I offered two but I only see place in doo for something similar to the second one: initializing a server, calling the cljs tests, and then stopping the server.

viesti commented 8 years ago

I did a trial with doo and your other project, cljs-react-test, by using doo/run-script in a clojure.test for which I have fixture that spins up&down my server (Stuart Sierra's component makes handling dependencies easy). Before the test I compile CLJS files with a specific runner that selects only e2e style tests.

Had to setup CORS (since the runner takes a local file) to make AJAX work, but that was relatively easy too (using Duct here).

Anyhow, I kinda liked the experiment (also doo and cljs-react-test :)) and just saying that doo as a library might give you enough control to wire things together in a "normal" unit test :)

bensu commented 8 years ago

Thanks @viesti! That's great news. Looking at the code, I agree it can be done using doo.core/run-script without much fuzz. Maybe there is a way to extract the boiler plate from that so that doo makes it even easier and people start doing it. Otherwise, we can properly document your findings in a tutorial.

viesti commented 8 years ago

Thanks! :) I'm thinking that a short tutorial might be good (or a mention in the readme if this get's short enough) since the wiring might be a bit related to the app architecture. There are at least these points:

  1. clojure.test which compiles a suitable runner and calls doo/run-script (this is generic, clojure.test is a good starting point)
  2. Fixture that start&stops the app (might be app specific, thinking a let expression around the test function for setup&teardown)
  3. CORS setup (depends on the app, but providing an example helps)
  4. Related to previous, I needed a way to tell the CLJS app the location of the server in the test. Solved it by provicing a test/production version of config.cljs that has a suitable base url (depends on the app I'd say :))
viesti commented 8 years ago

So had sort of a flow (and kids sleeping too :)) and wipped up a "tutorial" in a PR: https://github.com/bensu/doo/pull/65. Hope it makes any sense :)

bensu commented 8 years ago

@xcthulhu did you find the wiki article useful?

xcthulhu commented 8 years ago

@bensu TBH the wiki article is overly complicated. It never really says what my-app.system is... I take it it's just taken from some project. I've yet to translate this into my own stack.

bensu commented 8 years ago

@xcthulhu I edited the wiki to have a slower pace and explained a few of the requirements. Closing this for now.