Fork me on GitHub
#figwheel-main
<
2018-12-22
>
vaz01:12:47

@borkdude the examples you'll see around typically show unit tests (or data-driven... testing functions in isolation), using deftest, run-tests, etc from cljs.test. But those testing macros are extremely non-specific and one of the perks of running tests client-side is you could have direct access to real UI components (avoiding either the need for e.g. Selenium to drive your tests, or a headless browser like PhantomJS that can be kinda painful when debugging). I see no reason why the basic cljs.test test runner couldn't handle higher-level UI/acceptance tests

vaz01:12:53

I think a good approach could use :extra-mains to set up a testing endpoint on its own page, where you could render various components separately onto the page and then test them. At least if you're using something React-based and can set up state / pass props as needed for each test. With a bit of creativity and a custom reporter (or just use devcards) you could show test results under each rendered component. You could also just run-tests with your whole app loaded, but seems harder and probably slower.

vaz03:12:03

Either way you'd have to be careful about async. Reload, reset DOM/event handlers/state, then trigger run tests (tests probably async too)... you might get some ideas from https://figwheel.org/docs/testing.html and how cljs-test-display does its reloadable setup https://github.com/bhauman/cljs-test-display/blob/be674b314530ac9ed3c4a160d3d3f17eec72f304/src/cljs_test_display/core.cljs#L383-L422 Also you might find using devcards (with its devcards-test macro) could be a really nice way to render components and their test results together.

borkdude20:12:36

I’m using figwheel main, but removed the test path in deps.edn. But when I change something there, it still watches that path after restarting

bhauman20:12:32

Hmmmm have you manually set :watch-dirs?

bhauman20:12:33

Yeah figwheel doesn’t know which directories you want watched

borkdude20:12:55

:fig {:extra-deps
                 {com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
                  com.bhauman/figwheel-main {:mvn/version "0.1.9"}}
                 :extra-paths ["src" #_"target"]}

borkdude20:12:22

(I also excluded target just to be sure)

bhauman20:12:46

Gotcha you need to set :watch-does

borkdude20:12:17

it’s not set in my generated figwheel-main.edn which is only comments, so I’ll add it

bhauman20:12:04

You’re better off setting it as metadata on dev.cljs.edn

borkdude20:12:20

oh there it is yes

borkdude21:12:51

works like intended now, thanks