Tape

tap-producing test harness for node and browsers

README


tape


Version Badge

TAP -producing test harness for node and browsers

example


  1. ``` js
  2. var test = require('tape');

  3. test('timing test', function (t) {
  4.     t.plan(2);

  5.     t.equal(typeof Date.now, 'function');
  6.     var start = Date.now();

  7.     setTimeout(function () {
  8.         t.equal(Date.now() - start, 100);
  9.     }, 100);
  10. });

  11. test('test using promises', async function (t) {
  12.     const result = await someAsyncThing();
  13.     t.ok(result);
  14. });
  15. ```

  1. ``` null
  2. $ node example/timing.js
  3. TAP version 13
  4. # timing test
  5. ok 1 should be strictly equal
  6. not ok 2 should be strictly equal
  7.   ---
  8.     operator: equal
  9.     expected: 100
  10.     actual:   107
  11.   ...

  12. 1..2
  13. # tests 2
  14. # pass  1
  15. # fail  1

  16. ```

usage


You always need to require('tape')in test files. You can run the tests by usual node means (require('test-file.js')or node test-file.js). You can also run tests using the tapebinary to utilize globbing, on Windows for example:

  1. ``` shell
  2. $ tape tests/**/*.js
  3. ```

tape's arguments are passed to the glob module. If you want globto perform the expansion on a system where the shell performs such expansion, quote the arguments as necessary:

  1. ``` shell
  2. $ tape 'tests/**/*.js'
  3. $ tape "tests/**/*.js"
  4. ```

Preloading modules


Additionally, it is possible to make tapeload one or more modules before running any tests, by using the -ror --requireflag. Here's an example that loads babel-register before running any tests, to allow for JIT compilation:

  1. ``` shell
  2. $ tape -r babel-register tests/**/*.js
  3. ```

Depending on the module you're loading, you may be able to parameterize it using environment variables or auxiliary files. Babel, for instance, will load options from .babelrc at runtime.

The -rflag behaves exactly like node's require, and uses the same module resolution algorithm. This means that if you need to load local modules, you have to prepend their path with ./or ../accordingly.

For example:

  1. ``` shell
  2. $ tape -r ./my/local/module tests/**/*.js
  3. ```

Please note that all modules loaded using the -rflag will run beforeany tests, regardless of when they are specified. For example, tape -r a b -r cwill actually load aand cbeforeloading b, since they are flagged as required modules.

things that go well with tape


tapemaintains a fairly minimal core. Additional features are usually added by using another module alongside tape.