mAAdhaTTah / brookjs

reactive programming tools for well-structured, testable applications
https://mAAdhaTTah.github.io/brookjs/
MIT License
15 stars 1 forks source link

Testing Tools #50

Closed mAAdhaTTah closed 6 years ago

mAAdhaTTah commented 7 years ago

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 test brookjs 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 how redux-observable suggests doing tests, although they provide an explicit mechanism for passing in dependencies. Adding a similar feature to observeDelta would likely require breaking changes, so the currying method works well enough and we can break that in 2.0 if it feels cumbersome.

mAAdhaTTah commented 7 years ago

How can we do snapshot testing...?

mAAdhaTTah commented 7 years ago

We've got two problems here:

  1. What test framework should brookjs itself use to test the framework code?
  2. What test from should we be recommending to userland to test components?

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:

  1. All tests by default run in node w/ jdom.
  2. Precommit hook runs the tests in ChromeHeadless.
  3. CI runs the tests in supported browsers on Sauce.

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.

mAAdhaTTah commented 7 years ago

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.

mAAdhaTTah commented 6 years ago

We backed out and ended up with chai-kefir and a chaiPlugin export from brookjs-desalinate.