@power-doctest/core
v5.3.3
Published
power-doctest core library
Downloads
150
Readme
@power-doctest/core
power-doctest core library.
Features
- Convert Code to power-doctest ready code.
- power-doctest use comment-to-assert and power-assert
Installation
npm install @power-doctest/core
Usage
power-doctest convert following code
function sum(ary) {
return ary.reduce(function (current, next) {
return current + next
}, 0);
}
var total = sum([1, 2, 3, 4, 5]);
total; // => 5
to
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:
$ node example/transformed.js
AssertionError: # at line: 14
assert.equal(total, 5)
|
15
API
convertCode
: Convert code to codeconvertAST
: Convert Babel's AST to AST
import { ParserOptions } from "@babel/parser";
import { File } from "@babel/types";
export interface convertCodeOption {
filePath: string;
babel?: ParserOptions;
assertBeforeCallbackName?: string;
assertAfterCallbackName?: string;
}
/**
* Convert Code to Code
* @param code
* @param options
*/
export declare function convertCode(code: string, options: convertCodeOption): string;
export interface convertASTOptions {
assertBeforeCallbackName?: string;
assertAfterCallbackName?: string;
filePath: string;
}
/**
* Convert AST to AST
* @param AST
* @param options
*/
export declare function convertAST<T extends File>(AST: T, options: convertASTOptions): T;
Exception Test
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);
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT