Tape
tap-producing test harness for node and browsers
README
tape
TAP -producing test harness for node and browsers
example
- ``` js
- var test = require('tape');
- test('timing test', function (t) {
- t.plan(2);
- t.equal(typeof Date.now, 'function');
- var start = Date.now();
- setTimeout(function () {
- t.equal(Date.now() - start, 100);
- }, 100);
- });
- test('test using promises', async function (t) {
- const result = await someAsyncThing();
- t.ok(result);
- });
- ```
- ``` null
- $ node example/timing.js
- TAP version 13
- # timing test
- ok 1 should be strictly equal
- not ok 2 should be strictly equal
- ---
- operator: equal
- expected: 100
- actual: 107
- ...
- 1..2
- # tests 2
- # pass 1
- # fail 1
- ```
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:
- ``` shell
- $ tape tests/**/*.js
- ```
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:
- ``` shell
- $ tape 'tests/**/*.js'
- $ tape "tests/**/*.js"
- ```
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:
- ``` shell
- $ tape -r babel-register tests/**/*.js
- ```
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:
- ``` shell
- $ tape -r ./my/local/module tests/**/*.js
- ```
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.