Skip to content

FrodoTheTrue/pegas

Repository files navigation

✅ ❌ Pegas Build Status codecov Join the chat at https://gitter.im/testla-talks/Lobby

Write tests in JS comments! (inspired by JSDoc)

Description

Pegas - simple testing framework for Node.js platfrom. It allows to write tests for functions in comments to this function (yea, like in JSDoc) in simple format. This library firstly done for small scripts, you no need more files to test your app and you can take tests, docs and code in one moment.

Usage

  1. Install Pegas:
npm install pegas --save-dev
  1. Write Pegas-tests in block comment before function that you want to test:
// example.js

/*P
  (2, 2) => 4
  (4, 3) => 7
*/
function summ(a, b) {
    return a + b;
}

/*P
  (2, 2) => 4
  (4, 3) => 12
*/
function mull(a, b) {
    return a * b;
}

/*P
  ({a: 1, b: 1}) => { a: 1, b: 1 }
*/
function objective(obj) {
  return obj;
}

/*P
  ([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;
  1. Create simple config:
// config.testcom.js

{
  'test': [
    '.examples/example.js'
  ]
}
  1. Run tests:
pegas config.pegas.js

Result

More examples here

Features

  1. Change export naming
  /*P
    ExportAs: fakeSumm
    (2, 2) => 4
    (-1, 1) => 0
  */
  function summ(a, b) {
    return a + b;
  }

  ...

  module.exports.fakeSumm = summ;
  1. Test async functions
  /*P
    (2000, cb) => cb(null, { result: true })
  */
  function asyncFunc(fuckingParam, callback) {
    // ... async magic ...
    callback(null, { result: true });
  }
  1. Test async/await functions:
  /*P
    () => 'text'
  */
  async function asyncAwait() {
    await Promise.fromNode(cb => setTimeout(cb, 0));
    return 'text';
  }
  1. Test errors:
  /*P
    () => Error
  */
  function returnError() {
    throw new Error();
  }

About

Write tests for Node.js code in comments!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published