dwyl / learn-tape

:white_check_mark: Learn how to use Tape for JavaScript/Node.js Test Driven Development (TDD) - Ten-Minute Testing Tutorial
187 stars 31 forks source link

Migrate form Tape to Tap (Run Tests in PARALLEL!) ? #34

Closed nelsonic closed 5 years ago

nelsonic commented 6 years ago

Why?

It recently came to our attention in: https://github.com/dwyl/aws-sdk-mock/pull/144 image that tap has a couple of really useful features that tape (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 image The npm 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 image There could be a pretty significant benefit to running tests in Parallel.

What?

How?

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:

nelsonic commented 6 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/ image

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: image

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.

nelsonic commented 6 years ago

Proposed Analogy: Single Speed Bike vs. Specialized Racer (With Gears) specialised-racing-bicycle sku-fixie-single-speed-bike

Which one would you say is Tape and which is Tap (so we can test the analogy...)

nelsonic commented 6 years ago

Perhaps the best "feature" of Tap is Code Coverage integration! https://www.node-tap.org/coverage image

nelsonic commented 6 years ago

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.

nelsonic commented 6 years ago

image

nelsonic commented 6 years ago

Reduced image size by 70% to respect people on lower bandwidth: sku-fixie-single-speed-bike specialised-racing-bicycle

Effect is the same when viewed on GitHub. #LittleThings 😉

nelsonic commented 6 years ago

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. ✅

nelsonic commented 5 years ago

closing. see: https://github.com/dwyl/learn-tape/blob/master/tap-advanced-testing.md