Easy Inline Test Creation in Comments
Easy inline test writing. tapered uses Babel and Webpack to generate Tape test files from test code written inline in comments
npm install tapered.js
Add the following lines to your .babelrc file.
Add these requires to the top of your webpack.config file:
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_'
},
}),
],
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']
>>: _test name_
>>:a: _specify assertion_
const demo = {};
demo.add = function(a, b) {
return a + b;
}
/* %tapered */
/*
>>:add
>>:a: demo.add(1, 2) equal 3 | should add numbers
>>:a: demo.add(0, 1) notEqual 2 | should add numbers correctly
*/
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();
});
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')
>>:a: Expression Assertion Expected | optional message
>>:a: demo.multiply(1,2) equal 2 | should multiply numbers
Assertion | Function |
---|---|
equal | asserts equality |
notEqual | asserts inequality |
deepEqual | asserts deep equality - use when comparing objects |
notDeepEqual | asserts deep inequality - use when comparing objects |