Better-Tape >> Improving upon JavaScript Tape test-harness

Amrish
Amrish
Aug 28, 2017 · 2 min read

Source code for better-tape https://github.com/amrish7/better-tape

Tape is among the best test-harness for JavaScript. It is lightweight, avoids globals and is quite fast when compared to other testing frameworks like Mocha & Jasmine. Tape along with sinon and proxyquire take care of all of my testing needs for myJavaScript projects at work and outside of it.

In spite of it’s greatness, tape does have quite a few shortcomings like lack of lifecycle hooks which was huge thing for folks like me who migrated from Mocha. better-tape was created to bridge a few of those gaps.

better-tape@1.1.0 supports the following features

  1. Lifecycle hooks for top level and nested test cases (aka before and after hooks)
  2. Support for only API on nested test cases

There are many similar tape forks that offer similar features, but IMHO, they have limited life cycle implementations and only offer before/after hooks for nested test cases.

Install

npm i better-tape --save-dev

Usage

As better-tape is forked from tape, refer to tape README for complete documentation. I will only cover the feature delta in this article.

$ better-tape tests/**/*.js

New features

  1. before and after hook support for simple non-nested test cases

Output

TAP version 13
# Subtest: test/sample.js
# Test 1

>> INSIDE before
ok 1 Executing Test 1
>> INSIDE after

# Test 2

>> INSIDE before
ok 2 Executing Test 2
>> INSIDE after

1..2
# tests 2
# pass 2

# ok

ok 1 - test/sample.js # time=109.678ms

1..1
# time=122.405ms

2. before and after hook support for nested test cases

Output

TAP version 13
# Subtest: test/sample.js
# Suite 1

>> INSIDE before
# Nested test 1

>>>> INSIDE NESTED before
ok 1 Executing Nested Test 1
>>>> INSIDE NESTED after

# Nested test 2

>>>> INSIDE NESTED before
ok 2 Executing Nested Test 2
>>>> INSIDE NESTED after

>> INSIDE after

1..2
# tests 2
# pass 2

# ok

ok 1 - test/sample.js # time=102.496ms

1..1
# time=115.107ms

3. Support for ONLY on nested test cases

Using only with nested test cases. Only supported in better-tape@1.1.0

Output

# Subtest: test/only6.js
# only6 nested only test
# nested ONLY test-3
ok 1 Only nested test case that should have been run
1..1
# tests 1
# pass 1
# okok 1 - test/only6.js # time=130.732ms1..1
# time=144.871ms

Feel free to check out the full code base at https://github.com/amrish7/better-tape and for new feature requests, create an issue with enhancement label and add details to it.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade