Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

acquit

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acquit - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

gulpfile.js

7

docs.js
var acquit = require('./lib');
var fs = require('fs');
var md = '# acquit\n\nParse BDD-style tests (Mocha, Jasmine) to generate documentation\n\n';
md += '[![Build Status](https://travis-ci.org/vkarpov15/acquit.svg?branch=master)](https://travis-ci.org/vkarpov15/acquit)\n\n';
var md = fs.readFileSync('./HEADER.md');
md += '\n';
var blocks = acquit.parse(require('fs').readFileSync('./test/test.js').toString());
var blocks = acquit.parse(fs.readFileSync('./test/test.js').toString());

@@ -8,0 +9,0 @@ for (var i = 0; i < blocks.length; ++i) {

@@ -0,4 +1,7 @@

0.3.0 / 2015-09-03
==================
* added; constructor to isolate transforms #7
0.2.0 / 2015-08-28
==================
* added; `.transform()`
* added; `.transform()`

@@ -1,87 +0,44 @@

var esprima = require('esprima');
var parse = require('./parse');
var trimEachLine = require('./trimEachLine');
var _ = require('underscore');
var util = require('util');
var marked = require('marked');
'use strict';
var transforms = [];
var parse = function(contents, cb) {
if (arguments.length == 2 && !(typeof cb === 'function')) {
throw Error('Second parameter must be a function.');
module.exports = Acquit;
function Acquit() {
if (!(this instanceof Acquit)) {
return new Acquit();
}
var tree = esprima.parse(contents, { attachComment: true });
var _transforms = [].concat(transforms);
var visitorFactory = function() {
var ret = {};
this.parse = function(contents, callback) {
return parse(_transforms, contents, callback);
};
ret.result = {};
this.getTransforms = function() {
return _transforms;
};
ret.visit = function(node, parent, context) {
if (node.type === 'CallExpression' &&
node.callee &&
node.callee.name === 'describe' &&
node.arguments &&
node.arguments.length) {
var block = {
type: 'describe',
contents: node.arguments[0].value,
blocks: [],
comments: _.pluck(node.callee.leadingComments || [], 'value')
};
context.push(block);
return block.blocks;
} else if (node.type === 'CallExpression' &&
node.callee &&
node.callee.name === 'it' &&
node.arguments &&
node.arguments.length) {
var block = {
type: 'it',
contents: node.arguments[0].value,
comments: _.pluck(node.callee.leadingComments || [], 'value'),
code: contents.substring(node.arguments[1].body.range[0] + 1, node.arguments[1].body.range[1] - 1)
};
for (var i = 0; i < transforms.length; ++i) {
transforms[i](block);
}
if (typeof cb !== 'undefined') {
cb(block);
}
context.push(block);
// Once we've reached an 'it' block, no need to go further
return null;
}
return context;
};
return ret;
this.removeAllTransforms = function() {
_transforms = [];
};
var recurse = function(node, parent, context, visitor) {
if (node instanceof Array || node instanceof Object) {
var newContext = visitor.visit(node, parent, context);
if (!newContext) {
return;
}
_.each(node, function(child) {
recurse(child, node, newContext, visitor);
});
}
this.transform = function(callback) {
_transforms.push(callback);
};
var ret = [];
var visitor = visitorFactory();
this.trimEachLine = trimEachLine;
}
recurse(tree, null, ret, visitor);
return ret;
};
module.exports = {
parse: parse,
var funcs = {
getTransforms: function() {
return transforms;
},
parse: function(contents, callback) {
return parse(transforms, contents, callback);
},
removeAllTransforms: function() {

@@ -93,15 +50,7 @@ transforms = [];

},
trimEachLine: function(str) {
var lines = str.split('\n');
var result = '';
for (var i = 0; i < lines.length; ++i) {
var toAdd = lines[i].trim();
if (toAdd.indexOf('*') === 0) {
toAdd = toAdd.substr('*'.length).trim();
}
result += (i > 0 ? '\n' : '') + toAdd;
}
trimEachLine: trimEachLine
};
return result;
}
};
_.each(funcs, function(value, key) {
Acquit[key] = value;
});
{
"name": "acquit",
"version": "0.2.0",
"version": "0.3.0",
"description": "Parse BDD-style tests (Mocha, Jasmine) to generate documentation",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha test/test.js",
"test-coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*"
"test": "mocha test/*",
"test-coverage": "istanbul cover _mocha -- -R spec ./test/*",
"watch": "gulp watch"
},

@@ -24,6 +25,10 @@ "author": "Valeri Karpov <val@karpov.io>",

"preset": "airbnb",
"requirePaddingNewLinesAfterBlocks": null,
"requireMultipleVarDecl": null,
"disallowMultipleVarDecl": true
"requireTrailingComma": null
},
"devDependencies": {
"gulp": "3.8.11",
"gulp-jscs": "2.0.0",
"gulp-mocha": "2.0.0",
"istanbul": "0.3.5",

@@ -30,0 +35,0 @@ "jscs": "1.9.0",

@@ -6,2 +6,3 @@ # acquit

[![Build Status](https://travis-ci.org/vkarpov15/acquit.svg?branch=master)](https://travis-ci.org/vkarpov15/acquit)
[![Coverage Status](https://coveralls.io/repos/vkarpov15/acquit/badge.svg?branch=master&service=github)](https://coveralls.io/github/vkarpov15/acquit?branch=master)

@@ -175,1 +176,28 @@ ## `acquit.parse()`

## `acquit()` constructor
#### 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);
var parser = acquit();
assert.equal(parser.getTransforms().length, 1);
parser.transform(function(block) {});
assert.equal(parser.getTransforms().length, 2);
parser.removeAllTransforms();
assert.equal(parser.getTransforms().length, 0);
assert.equal(acquit.getTransforms().length, 1);
assert.equal(parser.parse('describe("test", function() {});').length,
1);
```

@@ -150,1 +150,25 @@ var assert = require('assert');

});
describe('`acquit()` constructor', function() {
/**
* You can also use acquit as a constructor, in case you need
* multiple sets of transforms.
*/
it('creates a new instance with its own set of transforms', function() {
acquit.transform(function(block) {});
assert.equal(acquit.getTransforms().length, 1);
var parser = acquit();
assert.equal(parser.getTransforms().length, 1);
parser.transform(function(block) {});
assert.equal(parser.getTransforms().length, 2);
parser.removeAllTransforms();
assert.equal(parser.getTransforms().length, 0);
assert.equal(acquit.getTransforms().length, 1);
assert.equal(parser.parse('describe("test", function() {});').length,
1);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc