Closed nelsonic closed 5 years ago
One of the most useful/important features that Tap
has which Tape
does not
is t.beforeEach(function (done) {})
and t.afterEach(function (done) {})
see: https://www.node-tap.org/api/
in a recent example I've been working on: https://github.com/dwyl/learn-elm-architecture-in-javascript The "reset" code takes up 6% of the file and has been the cause of frustration!! /test/todo-app.test.js#L667-L668
elmish.empty(document.getElementById(id));
localStorage.removeItem('todos-elmish_' + id);
e.g:
Simply moving to Tap
will mean that we have a single t.afterEach
to reset the state,
so that we can have simpler tests that always work and are easier to read/maintain.
Proposed Analogy: Single Speed Bike vs. Specialized Racer (With Gears)
Which one would you say is Tape
and which is Tap
(so we can test the analogy...)
Perhaps the best "feature" of Tap
is Code Coverage integration!
https://www.node-tap.org/coverage
I'm applying a P2
label to this story because I need to use Tap for https://github.com/dwyl/atm
which is a priority for CS, Home and the dwyl website.
Reduced image size by 70% to respect people on lower bandwidth:
Effect is the same when viewed on GitHub. #LittleThings
😉
In the end I decided to simply extend the learn-tape
tutorial to cover Tap
and explain the reasoning why someone would want to use Tap
instead of Tape
with a clear use-case example. ✅
Why?
It recently came to our attention in: https://github.com/dwyl/aws-sdk-mock/pull/144 that
tap
has a couple of really useful features thattape
(our current test runner) does not.We use
tape
virtually everywhere in our Node.js projects (hence this tutorial) And in general it works really well for us. e.g: https://travis-ci.org/dwyl/hapi-auth-jwt2/jobs/376314561 Thenpm test
stage take "only" 5.25 seconds to complete, which means is't never been a "problem" for us ...However on bigger Node.js project(s) with many tests e.g: https://github.com/TheScienceMuseum/collectionsonline https://travis-ci.org/TheScienceMuseum/collectionsonline/builds/409777564#L576 There could be a pretty significant benefit to running tests in Parallel.
What?
t.spawn
to run a particularly slow test in a new process: https://www.node-tap.org/advancedHow?
The steps are pretty simple as outlined in: https://github.com/dwyl/aws-sdk-mock/pull/144/files#diff-0fd0e07cf6d02bf7cf00f18cebb8e6eaR1
We could also include a mini-guide at the end for "how to migrate from Tape to Tap" based on our experience of doing it for a sample project e.g: https://www.npmjs.com/package/hapi-auth-jwt2 or https://www.npmjs.com/package/decache both of which can use a
devDependencies
update ... 🙄Todo: