This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

taps

1.0.2 • Public • Published

taps

Experimental test runner is a handy tool to test ideas during the development without the distraction of creating and maintaining a separate test files structure.

Why?

Suppose you are super excited to start a mind-boggling project using all the cool methodologies and techniques that you've learned from the first frontier of the vibrant dev community.

Great! Let's begin with index.js:

// index.js

// There gonna be a great project!

But wait a minute, as far as I know, you can not work your great idea up into something valuable by community without TDD.

What do you suppose to do then?

Are you going to make a test dir? Touch some test files? Are you going to write a first test, that guaranteed leads up right to the failure? Think, what does this failure mean to you? Are you going to sit and look out how your first test ending without any chance to succeed? Are you going to jump between the endless test and src files and to misnomer the file names all the time?

Some day you'll realize, that there is no more fun, no more will to make your ideas up. It will become an endless struggle with the manual test file manipulations.

Is this even life?

taps to the rescue!

With taps everything become way easier.

Let's go ahead with your great project.

At first, add taps right into your index.js:

import test from 'taps';
import R from 'ramda';

let objectParams = {a: 1, b: 2, c: 3};
let cliParams = '--a=1 --b=2 --c=3';

const parametrize = object => cliParams;

test `parametrize`
  `should return a CLI params`
  (() => parametrize(objectParams) === cliParams)
  `should not return a JavaScript object with params`
  (() => parametrize(objectParams) !== objectParams);

export default parametrize;

As you can see, we've defined a test case right in the index.js body.

If you run this file with node, like:

node index.js

there will be no action triggered.

Because there is the one way to run the test inside every js file in the working dir, to run taps-cmd.

taps

This will run every found test as a separate process.

This also gives the ability to publish your project right away. Yeah, your project already works somehow. Not good enough, but works. There will be no test run on the file require.

And the last, but not least. If you use babel or other transpiler, you will be able to test both versions before and after transpiling without any tricks.

Getting started

Installation

$ npm install -g taps-cmd

Usage

Initialization

$ cd working-dir
$ taps --init

taps-cmd --init adds next dependencies to your project:

  • taps as a general dependency. It's small. It tries to import taps-runtime, and if not succeed, exports a non operational test function.
  • taps-runtime as a dev dependency, taps itself has it as an optional dependency
  • taps-cmd as a dev dependency to make it accessible from every dev environment. You can use it to setup a npm task.

Evaluation

$ taps --help

  Usage
    taps [<file|folder|glob> ...]

  Options
    --init              Add taps to your project
    --require, -r       Module to preload
    --watch, -w         Watch if files required by the test changed and restart
                          the exact test
    --reporter          Optional TAP reporter
    --help              Print this usage instruction

  Default patterns when no arguments:
  **/*.js

Whenever taps finds a file matches to the search path, it parses this file to find a test declaration, and if it succeed, the whole file with all the tests goes to the running queue.

taps also parses the require dependency tree for each file, so it can watch for changes in the certain files and restart certain tests on them with --watch flag.

TAP output

TAPs generates TAP output. Event though TAP is hard to read, TAP is a universal interface between testing modules. You can use any TAP repoter.

$ taps | tap-min
$ taps -w --reporter=tap-min

Documentation

As you have already noticed in the test example above, taps goes with fancy API. But don't worry, you can use more traditional way to test too.

Traditional

taps goes with power-assert by default to free you from requiring an assertion library as a production dependency. Also, you can use any assertion library with taps.

var test = require('test');

module.exports = I;

function I(x) {
  return x;
}

test('Test I()', function(assert) {
  // assert is power-assert
  assert(I() === undefined);
});

test('Test I()', function(assert) {
  assert(I(1) === 1);
});

test('Test I(o)', function(assert) {
  var o = {};
  assert(I(o) === o);
});

// test names are optional
test(function(assert) {
  assert(I(I(1)) === I(1));
});

On steroids

The same example from above using ES6 approach.

import test from 'test';

export const I = x => x;

let o = {};
test `Test`
  `I()`     (() => I() === undefined)
  `I(1)`    (() => I(1) === 1)
  `I(${o})` (() => I(o) === o);

As you can see, if test function returns a Boolean, it automatically passes into assert function as an argument.

You can use traditional way with steroids both at the same time.

import test from 'taps';

test `Test`
  `common` (() => true)
  `hard`   (assert => {
    assert(true !== false);
  });

Asynchronous

taps suports promises, futures, and observables. If your test function returns one of this types, taps will automatically handle them and will until the end of execution.

Also you can pass async functions and generators as a test function with the same effect.

Promise
import test from 'taps';

// succeed
test(() => Promise.resolve());

// failed
test(assert => Promise.reject(new Error()).catch(err => assert.ifError(err)));
Future
import test from 'taps';
import {call, pipe, always as K, map, tap} from 'ramda';

const res = x => Future((_, res) => res(x));
const rej = x => Future(rej => rej(x));

const x = 1;

// succeed
test(assert => call(pipe(
  K(res(x)),
  map(tap(y => assert(y === x)))
)));

// failed
test(() => Future(rej => rej()));
Observable
import test from 'taps';
import {map, tap} from 'ramda';

let n1 = 1;

test(assert => map(tap(n => assert(n === n1)), Observable.of(n1)));
Geneartor function
import test from 'taps';

test(function* (assert) {
  const x = yield gen();
  assert.ok(x);
});
Async function
import test from 'taps';

test(async assert => {
  const x = await Promise.resolve(1);
  assert(x === 1);
});

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i taps

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • ayatkevich