Awesome Open Source
Awesome Open Source

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_
>>🅰️ _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
>>🅰️ demo.add(1, 2) equal 3 | should add numbers
>>🅰️ 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
>>🅰️ _assertions_ | define assertions // demo.add(1, 2) equal 3
%g | defines global variables accessible across the entire test file // let arr = [1, 2, 3]
>>❌ | skips a test // test.skip('name')...
>>⭕️ | 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
>>🅰️ Expression Assertion Expected | optional message

>>🅰️ 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
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,046,936
Webpack (23,587
Babel (8,016
Tap (4,555
Inline (4,308
Test Driven Development (4,123
Testing Tools (1,576
Tape (1,402
Test Framework (1,048
Uglify (689
Babel Webpack (24