testcom
v1.0.1
Published
Write tests in javascript comments
Downloads
2
Readme
:white_check_mark: :x: Testcom
Write tests in JS comments! (inspired by JSDoc)
Description
Testcom - simple testing framework for Node.js platfrom (later maybe for client). It allows to write tests to functions in comments to this function (yea, like in JSDoc) in simple format. This library first done for small scripts, you no need more files to test your app and you can take tests and docs in one moment.
Usage
- Install Testcom:
npm install testcom --save-dev
- Write Testcom-tests in block comment before function that you want to test:
// example.js
/*T
(2, 2) => 4
(4, 3) => 7
*/
function summ(a, b) {
return a + b;
}
/*T
(2, 2) => 4
(4, 3) => 12
*/
function mull(a, b) {
return a * b;
}
/*T
({a: 1, b: 1}) => { a: 1, b: 1 }
*/
function objective(obj) {
return obj;
}
/*T
([1, 2, 3]) => [3, 2, 1]
*/
function reverseArray(arr) {
return arr.reverse();
}
module.exports.summ = summ;
module.exports.mull = mull;
module.exports.objective = objective;
module.exports.reverseArray = reverseArray;
- Create simple config:
// config.testcom.js
{
'test': [
'.examples/example.js'
]
}
- Run tests:
testcom config.testcom.js
More examples here
Features
- Change export naming
/*T
ExportAs: fakeSumm
(2, 2) => 4
(-1, 1) => 0
*/
function summ(a, b) {
return a + b;
}
...
module.exports.fakeSumm = summ;
- Test async functions
/*T
(2000, cb) => cb(null, { result: true })
*/
function asyncFunc(fuckingParam, callback) {
// ... async magic ...
callback(null, { result: true });
}
- Test async/await functions:
/*T
() => 'text'
*/
async function asyncAwait() {
await Promise.fromNode(cb => setTimeout(cb, 0));
return 'text';
}
- Test errors:
/*T
() => Error
*/
function returnError() {
throw new Error();
}