Comparing version 0.6.3 to 1.0.0
@@ -77,3 +77,4 @@ var parse = require('./parse'); | ||
_.each(funcs, function(value, key) { | ||
Object.keys(funcs).forEach(function(key) { | ||
const value = funcs[key]; | ||
Acquit[key] = function() { | ||
@@ -80,0 +81,0 @@ return value.apply(Acquit, arguments); |
{ | ||
"name": "acquit", | ||
"version": "0.6.3", | ||
"description": "Parse BDD-style tests (Mocha, Jasmine) to generate documentation", | ||
"version": "1.0.0", | ||
"description": "Parse BDD tests (Mocha, Jasmine) to generate documentation", | ||
"homepage": "http://acquit.mongoosejs.io", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha test/*", | ||
"test-coverage": "istanbul cover _mocha -- -R spec ./test/*", | ||
"watch": "gulp watch" | ||
"static": "serve .", | ||
"test": "mocha test/*.test.js", | ||
"test-coverage": "nyc mocha -- -R spec ./test/*.test.js" | ||
}, | ||
@@ -25,21 +26,16 @@ "author": "Valeri Karpov <val@karpov.io>", | ||
"dependencies": { | ||
"commander": "2.5.0", | ||
"esprima": "4.0.0", | ||
"lodash": "4.17.4", | ||
"lodash": "4.17.5", | ||
"marked": "0.3.9" | ||
}, | ||
"jscsConfig": { | ||
"preset": "airbnb", | ||
"requirePaddingNewLinesAfterBlocks": null, | ||
"requireMultipleVarDecl": null, | ||
"requireTrailingComma": null | ||
}, | ||
"devDependencies": { | ||
"gulp": "3.8.11", | ||
"gulp-jscs": "2.0.0", | ||
"gulp-mocha": "2.0.0", | ||
"istanbul": "0.4.2", | ||
"jscs": "1.9.0", | ||
"mocha": "3.5.0" | ||
"acquit-ignore": "0.0.5", | ||
"acquit-markdown": "0.1.0", | ||
"acquit-require": "0.0.4", | ||
"highlight.js": "9.12.0", | ||
"marked": "0.4.0", | ||
"mocha": "5.2.0", | ||
"nyc": "11.8.0", | ||
"serve": "6.5.7" | ||
} | ||
} |
340
README.md
@@ -8,6 +8,11 @@ # acquit | ||
## `acquit.parse()` | ||
## Website | ||
#### It can parse Mocha tests into `blocks` | ||
[`acquit.mongoosejs.io`](http://acquit.mongoosejs.io) | ||
# `acquit.parse()` | ||
## It can parse Mocha tests into `blocks` | ||
Acquit's `parse()` function takes in mocha tests as a string, and outputs | ||
@@ -19,69 +24,68 @@ a list of "blocks", which are either `describe` or `it` calls. A `describe` | ||
```javascript | ||
var contents = | ||
'/**\n' + | ||
' * A `Model` is a convenience wrapper around objects stored in a\n' + | ||
' * collection\n' + | ||
' */\n' + | ||
'describe(\'Model\', function() {\n' + | ||
' /**\n' + | ||
' * Model **should** be able to save stuff\n' + | ||
' **/\n' + | ||
' it(\'can save\', function() {\n' + | ||
' assert.ok(1);\n' + | ||
' });\n' + | ||
'\n' + | ||
' it(\'can save with a parameter\', function() {\n' + | ||
' });\n' + | ||
'});'; | ||
var contents = | ||
'/**\n' + | ||
' * A `Model` is a convenience wrapper around objects stored in a\n' + | ||
' * collection\n' + | ||
' */\n' + | ||
'describe(\'Model\', function() {\n' + | ||
' /**\n' + | ||
' * Model **should** be able to save stuff\n' + | ||
' **/\n' + | ||
' it(\'can save\', function() {\n' + | ||
' assert.ok(1);\n' + | ||
' });\n' + | ||
'\n' + | ||
' it(\'can save with a parameter\', function() {\n' + | ||
' });\n' + | ||
'});'; | ||
var ret = acquit.parse(contents); | ||
var ret = acquit.parse(contents); | ||
// One top-level block: describe('Model') | ||
assert.equal(1, ret.length); | ||
assert.equal('describe', ret[0].type); | ||
assert.equal(1, ret[0].comments.length); | ||
assert.ok(ret[0].comments[0].indexOf('`Model`') != -1); | ||
// One top-level block: describe('Model') | ||
assert.equal(1, ret.length); | ||
assert.equal('describe', ret[0].type); | ||
assert.equal(1, ret[0].comments.length); | ||
assert.ok(ret[0].comments[0].indexOf('`Model`') != -1); | ||
// Top-level block contains the `it('can save')` block, which contains | ||
// the code | ||
assert.equal(2, ret[0].blocks.length); | ||
assert.equal('it', ret[0].blocks[0].type); | ||
assert.equal(1, ret[0].blocks[0].comments.length); | ||
assert.ok(ret[0].blocks[0].code.indexOf('assert.ok(1)') !== -1); | ||
assert.equal('can save', ret[0].blocks[0].contents); | ||
// Top-level block contains the `it('can save')` block, which contains | ||
// the code | ||
assert.equal(2, ret[0].blocks.length); | ||
assert.equal('it', ret[0].blocks[0].type); | ||
assert.equal(1, ret[0].blocks[0].comments.length); | ||
assert.ok(ret[0].blocks[0].code.indexOf('assert.ok(1)') !== -1); | ||
assert.equal('can save', ret[0].blocks[0].contents); | ||
assert.equal('it', ret[0].blocks[1].type); | ||
assert.equal('can save with a parameter', ret[0].blocks[1].contents); | ||
assert.equal(0, ret[0].blocks[1].comments.length); | ||
assert.equal('it', ret[0].blocks[1].type); | ||
assert.equal('can save with a parameter', ret[0].blocks[1].contents); | ||
assert.equal(0, ret[0].blocks[1].comments.length); | ||
``` | ||
#### It can call user function on `code` block and save return value | ||
## It can call user function on `code` block and save return value | ||
Acquit can also take a callback as second parameter. This callback gets | ||
executed on every block and can transform the block however you want. | ||
```javascript | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
var cb = function(block) { | ||
block.code = 'return value from callback'; | ||
}; | ||
var cb = function(block) { | ||
block.code = 'return value from callback'; | ||
}; | ||
var ret = acquit.parse(contents, cb); | ||
var ret = acquit.parse(contents, cb); | ||
assert.equal('return value from callback', ret[0].blocks[0].code); | ||
assert.equal('return value from callback', ret[0].blocks[0].code); | ||
``` | ||
#### It can define transforms | ||
## It can define transforms | ||
Want to chain multiple callbacks together and/or develop re-usable | ||
@@ -94,55 +98,55 @@ plugins? `acquit.transform()` allows you to add transformations that | ||
```javascript | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
var cb = function(block) { | ||
block.code = 'my transformed code'; | ||
}; | ||
var cb = function(block) { | ||
block.code = 'my transformed code'; | ||
}; | ||
acquit.transform(cb); | ||
acquit.transform(cb); | ||
var ret = acquit.parse(contents); | ||
var ret = acquit.parse(contents); | ||
assert.equal('my transformed code', ret[0].blocks[0].code); | ||
acquit.removeAllTransforms(); | ||
assert.equal('my transformed code', ret[0].blocks[0].code); | ||
acquit.removeAllTransforms(); | ||
``` | ||
#### It can parse the ES6 `yield` keyword | ||
## It can parse the ES6 `yield` keyword | ||
Acquit can also parse ES6 code | ||
```javascript | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' co(function*() {\n' + | ||
' yield 1;\n' + | ||
' })();\n' + | ||
' });\n' + | ||
'});'; | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' co(function*() {\n' + | ||
' yield 1;\n' + | ||
' })();\n' + | ||
' });\n' + | ||
'});'; | ||
var ret = acquit.parse(contents); | ||
var ret = acquit.parse(contents); | ||
assert.equal(1, ret.length); | ||
assert.equal('describe', ret[0].type); | ||
assert.equal(0, ret[0].comments.length); | ||
assert.equal(1, ret[0].blocks.length); | ||
assert.equal('it', ret[0].blocks[0].type); | ||
assert.equal(1, ret[0].blocks[0].comments.length); | ||
assert.ok(ret[0].blocks[0].code); | ||
assert.equal(1, ret.length); | ||
assert.equal('describe', ret[0].type); | ||
assert.equal(0, ret[0].comments.length); | ||
assert.equal(1, ret[0].blocks.length); | ||
assert.equal('it', ret[0].blocks[0].type); | ||
assert.equal(1, ret[0].blocks[0].comments.length); | ||
assert.ok(ret[0].blocks[0].code); | ||
``` | ||
#### It can parse Mocha's `context()` and `specify()` | ||
## It can parse Mocha's `context()` and `specify()` | ||
Acquit can parse Mocha alias: | ||
@@ -152,27 +156,27 @@ - `context` = `describe` | ||
```javascript | ||
var contents = | ||
'context(\'Mocha aliases\', function() {\n' + | ||
' specify(\'should be parsed\', function() {\n' + | ||
' assert.equal(1, 1);\n' + | ||
' });\n' + | ||
'});'; | ||
var contents = | ||
'context(\'Mocha aliases\', function() {\n' + | ||
' specify(\'should be parsed\', function() {\n' + | ||
' assert.equal(1, 1);\n' + | ||
' });\n' + | ||
'});'; | ||
var ret = acquit.parse(contents); | ||
var ret = acquit.parse(contents); | ||
assert.equal(1, ret.length); | ||
assert.equal('describe', ret[0].type); | ||
assert.equal(0, ret[0].comments.length); | ||
assert.equal(1, ret[0].blocks.length); | ||
assert.equal('it', ret[0].blocks[0].type); | ||
assert.equal(0, ret[0].blocks[0].comments.length); | ||
assert.ok(ret[0].blocks[0].code); | ||
assert.equal(1, ret.length); | ||
assert.equal('describe', ret[0].type); | ||
assert.equal(0, ret[0].comments.length); | ||
assert.equal(1, ret[0].blocks.length); | ||
assert.equal('it', ret[0].blocks[0].type); | ||
assert.equal(0, ret[0].blocks[0].comments.length); | ||
assert.ok(ret[0].blocks[0].code); | ||
``` | ||
## `acquit.trimEachLine()` | ||
# `acquit.trimEachLine()` | ||
#### It strips out whitespace and asterisks in multiline comments | ||
## It strips out whitespace and asterisks in multiline comments | ||
`trimEachLine()` is a helper function for trimming whitespace and asterisks | ||
@@ -182,13 +186,12 @@ from JSdoc-style comments | ||
```javascript | ||
var str = ' * This comment looks like a \n' + | ||
' * parsed JSdoc-style comment'; | ||
var str = ' * This comment looks like a \n' + | ||
' * parsed JSdoc-style comment'; | ||
assert.equal(acquit.trimEachLine(str), 'This comment looks like a\n' + | ||
'parsed JSdoc-style comment'); | ||
assert.equal(acquit.trimEachLine(str), 'This comment looks like a\n' + | ||
'parsed JSdoc-style comment'); | ||
``` | ||
#### It strips out whitespace and asterisks in multiline comments | ||
## It strips out whitespace and asterisks in multiline comments | ||
You don't have to use JSdoc-style comments: `trimEachLine()` also trims | ||
@@ -198,85 +201,82 @@ leading and trailing whitespace. | ||
```javascript | ||
var str = 'This comment looks like a \n' + | ||
' * parsed JSdoc-style comment'; | ||
var str = 'This comment looks like a \n' + | ||
' * parsed JSdoc-style comment'; | ||
assert.equal(acquit.trimEachLine(str), 'This comment looks like a\n' + | ||
'parsed JSdoc-style comment'); | ||
assert.equal(acquit.trimEachLine(str), 'This comment looks like a\n' + | ||
'parsed JSdoc-style comment'); | ||
``` | ||
## Output processors | ||
# Output processors | ||
#### It can transform acquit output | ||
## It can transform acquit output | ||
You can use the `.output()` function to attach output processors, | ||
which transform the output from `acquit.parse()` before you get it. | ||
```javascript | ||
var contents = [ | ||
'describe("My feature", function() {', | ||
' it("works", function() {', | ||
' // some code', | ||
' });', | ||
'});' | ||
].join('\n'); | ||
var contents = [ | ||
'describe("My feature", function() {', | ||
' it("works", function() {', | ||
' // some code', | ||
' });', | ||
'});' | ||
].join('\n'); | ||
acquit.output(function(res) { | ||
return [ | ||
'# ' + res[0].contents, | ||
'\n', | ||
'## ' + res[0].blocks[0].contents | ||
].join('\n'); | ||
}); | ||
acquit.output(function(res) { | ||
return [ | ||
'# ' + res[0].contents, | ||
'\n', | ||
'## ' + res[0].blocks[0].contents | ||
].join('\n'); | ||
}); | ||
var res = acquit.parse(contents); | ||
var res = acquit.parse(contents); | ||
assert.equal(res, [ | ||
'# My feature', | ||
'\n', | ||
'## works' | ||
].join('\n')); | ||
acquit.removeAllTransforms(); | ||
assert.equal(res, [ | ||
'# My feature', | ||
'\n', | ||
'## works' | ||
].join('\n')); | ||
acquit.removeAllTransforms(); | ||
``` | ||
## `acquit()` constructor | ||
# `acquit()` constructor | ||
#### It creates a new instance with its own set of transforms | ||
## It creates a new instance with its own set of transforms | ||
You can also use acquit as a constructor, in case you need | ||
multiple sets of transforms. | ||
```javascript | ||
acquit.transform(function(block) {}); | ||
assert.equal(acquit.getTransforms().length, 1); | ||
acquit.transform(function(block) {}); | ||
assert.equal(acquit.getTransforms().length, 1); | ||
var parser = acquit(); | ||
assert.equal(parser.getTransforms().length, 1); | ||
var parser = acquit(); | ||
assert.equal(parser.getTransforms().length, 1); | ||
parser.transform(function(block) {}); | ||
assert.equal(parser.getTransforms().length, 2); | ||
parser.transform(function(block) {}); | ||
assert.equal(parser.getTransforms().length, 2); | ||
parser.removeAllTransforms(); | ||
assert.equal(parser.getTransforms().length, 0); | ||
assert.equal(acquit.getTransforms().length, 1); | ||
parser.removeAllTransforms(); | ||
assert.equal(parser.getTransforms().length, 0); | ||
assert.equal(acquit.getTransforms().length, 1); | ||
assert.equal(parser.parse('describe("test", function() {});').length, | ||
1); | ||
assert.equal(parser.parse('describe("test", function() {});').length, | ||
1); | ||
parser.output(function(res) { | ||
return 'myFakeOutput'; | ||
}); | ||
parser.output(function(res) { | ||
return 'myFakeOutput'; | ||
}); | ||
assert.equal(parser.parse('describe("test", function() {});'), | ||
'myFakeOutput'); | ||
assert.equal(parser.parse('describe("test", function() {});'), | ||
'myFakeOutput'); | ||
parser.removeAllOutputProcessors(); | ||
parser.removeAllOutputProcessors(); | ||
assert.equal(parser.parse('describe("test", function() {});').length, | ||
1); | ||
``` | ||
assert.equal(parser.parse('describe("test", function() {});').length, | ||
1); | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
3
527
0
2
37648
8
15
276
1
+ Addedlodash@4.17.5(transitive)
- Removedcommander@2.5.0
- Removedcommander@2.5.0(transitive)
- Removedlodash@4.17.4(transitive)
Updatedlodash@4.17.5