npm install testcom
npm install testcom --save-dev
`
2) Write Testcom-tests in block comment before function that you want to test:
`js
// 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;
`3) Create simple config:
`js
// config.testcom.js{
'test': [
'.examples/example.js'
]
}
`
4) Run tests:
`
testcom config.testcom.js
`
!ResultMore examples here
Features
1) Change export naming
`js
/*T
ExportAs: fakeSumm
(2, 2) => 4
(-1, 1) => 0
*/
function summ(a, b) {
return a + b;
} ...
module.exports.fakeSumm = summ;
`2) Test async functions
`js
/*T
(2000, cb) => cb(null, { result: true })
*/
function asyncFunc(fuckingParam, callback) {
// ... async magic ...
callback(null, { result: true });
}
`3) Test async/await functions:
`js
/*T
() => 'text'
*/
async function asyncAwait() {
await Promise.fromNode(cb => setTimeout(cb, 0));
return 'text';
}
`
4) Test errors:
`js
/*T
() => Error
*/
function returnError() {
throw new Error();
}
``