Closed mAAdhaTTah closed 6 years ago
How can we do snapshot testing...?
We've got two problems here:
brookjs
itself use to test the framework code?For 2, I have no problem with either Jest or AVA, despite neither of the running in the browser. We could suggest unit tests with jsdom, with integration tests against an actual browser. Neither of those test frameworks run in the browser (yet), and brookjs
itself should smooth over cross-browser problems, so (in theory) there shouldn't be a need for unit tests to run in the browser. You could then use something like Storybook (could we add brookjs
support there?) or Fractal and do screenshot testing for your components.
However, for 1, what I would like ideally is something like this:
I would also ideally like to use the same testing framework within brookjs
as well as userland. This puts us at a bit of an impasse, because userland doesn't need to run tests in the browser but the framework does.
We're currently using 3 different test frameworks in the 3 packages: mocha + chai + karma in brookjs proper, AVA in brookjs-cli, and Jest in brookjs-silt. This was mostly intended to get a feel for all three. We also should consider tape, which is much simpler than any of the others, comes with assertion planning (which is the big thing I feel I'm missing from the mocha + chai setup), and runs in node + browser.
We should list out the requirements for each scenario and see if we can pick a test runner that does what we need.
After all this, I'm going to go with tape
. It's the simplest, it's easy to run in both node (with jsdom) and the browser (with karma), so we can fulfill all of what the framework needs. brookjs-desalinate
can enhance tape
to consume observables and add snapshot testing for brookjs
components built-in. It also has assertion planning (which mocha + chai can't deliver), which is really important for the type of async testing you do with observables.
We backed out and ended up with chai-kefir
and a chaiPlugin
export from brookjs-desalinate
.
I've made a couple abortive attempts to build a set of testing helpers, which I had dubbed
desalinate
, but I haven't pulled together a definitive "how to testbrookjs
components" yet. Testing deltas is pretty easy/straightforward, although it requires some modification to how your deltas are structured–curry the function, pass in the delta services as the first parameter, and mock them during unit testing. This is kind of howredux-observable
suggests doing tests, although they provide an explicit mechanism for passing in dependencies. Adding a similar feature toobserveDelta
would likely require breaking changes, so the currying method works well enough and we can break that in 2.0 if it feels cumbersome.