power-doctest

doctest + power-assert - comment as testing.

power-doctest

Doctest + power-assert.

npm install -g power-doctest
Usage: power-doctest /path/to/file.js

Test code :

function sum(ary) {
    return ary.reduce(function (currentnext) {
        return current + next
    }, 0);
}
 
var total = sum([1, 2, 3, 4, 5]);
total; // => 5 

This code expect total to be 5.

Result :

$ power-doctest example/example.js
var assert = require('power-assert');
function sum(ary) {
    return ary.reduce(function (current, next) {
        return current + next;
    }, 0);
}
var total = sum([
    1,
    2,
    3,
    4,
    5
]);
assert.equal(assert._expr(assert._capt(total, 'arguments/0'){
    content: 'assert.equal(total, 5)',
    line: 14
}), 5);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbXX0

And execute this transformed code:

$ power-doctest example/example.js | node -p
AssertionError:   # at line: 14 
 
  assert.equal(total, 5)
               |
               15
 

Look like => Error is assert.throw().

throw new Error(); // => Error 
var object = {};
obj.not.found;// => Error 

Covert this case to:

var assert = require('power-assert');
assert.throws(function () {
    throw new Error();
}, Error);
var object = {};
assert.throws(function () {
    object.not.found;
}, Error);
  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

MIT