tapered.js

1.0.1 • Public • Published

Alt tapered logo

Synopsis

Easy inline test writing. tapered uses Babel and Webpack to generate Tape test files from test code written inline in comments

Installation

npm install tapered.js

Setup

1. babelrc

Add the following lines to your .babelrc file.

  • "presets": ["env"],
  • "plugins": ["tapered.js/tapered-babel-plugin.js"]

2. webpack.config

Add these requires to the top of your webpack.config file:

  • const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
  • const tapered = require('tapered.js/tapered-webpack-plugin.js');

Add the following to your webpack's plugins array and specify the location of your test file e.g. /tests/tape-test-sample.js

plugins : [
new tapered(),
new webpack.optimize.UglifyJsPlugin({
extractComments: {
condition: /dab/,
filename: '_INSERT TEST FILE LOCATION HERE_'
        },
    }),
],

3. tapered-webpack-plugin.js

Specify the same desired test file location for the fields marked with 'INSERT TEST FILE LOCATION HERE' in the tapered.js folder inside your node modules directory: /node_modules/tapered.js/tapered-webpack-plugin.js

const file = compilation.assets['INSERT DESIRED TEST FILE LOCATION HERE'];
compilation.assets['INSERT DESIRED TEST FILE LOCATION HERE']

Usage

Quick Start

>>: _test name_
>>:a: _specify assertion_

Simple Unit Test Writing

Let's write a test file for the code below:
const demo = {};
demo.add = function(a, b) {
  return a + b;
}
We write our tapered tests in block comments
/* %tapered */

/*
>>:add
>>:a: demo.add(1, 2) equal 3 | should add numbers
>>:a: demo.add(0, 1) notEqual 2 | should add numbers correctly
*/
This is transpiled to Tape code as follows:
const demo = require('/src/demo.js');

test('add', function (t) {
	t.equal(demo.add(1, 2),  3 , 'should add numbers');
	t.notEqual(demo.add(0, 1),  2 , 'should add numbers correctly');
	t.end();
});

API Reference

Key Reminders

  • 1. All tapered code must be written inside of block comments.
  • 2. Tests must always begin with a name.
Syntax Function
%tapered | requires the containing file // require('/src/demo.js');
>>: _name_ | define test name // test('name')...
>>: _variables_ | define variables per specific test // let i = 0
>>:a: _assertions_ | define assertions // demo.add(1, 2) equal 3
%g | defines global variables accessible across the entire test file // let arr = [1, 2, 3]
>>:x: | skips a test // test.skip('name')...
>>:o: | tests only that test // test.only('name')...
>>:p: | specifies how many assertions to run per test // t.plan('name')

Assertions

Components
  1. Expression e.g. demo.multiply(1,2)
  2. Assertion e.g. equal
  3. Expected e.g. 2
  4. Description/Message e.g. should multiply numbers
Format
>>:a: Expression Assertion Expected | optional message

>>:a: demo.multiply(1,2) equal 2 | should multiply numbers

Supported Assertions

Assertion Function
equal asserts equality
notEqual asserts inequality
deepEqual asserts deep equality - use when comparing objects
notDeepEqual asserts deep inequality - use when comparing objects

Readme

Keywords

none

Package Sidebar

Install

npm i tapered.js

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • boji