Socket
Socket
Sign inDemoInstall

literapi

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

literapi - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

lib/interpolate.js

106

lib/cli.js

@@ -1,25 +0,23 @@

var runner = require('./runner')
, LiterAPI = require('./')
// Gently, see https://github.com/felixge/node-gently#gentlyhijackrealrequire
if (global.GENTLY) require = GENTLY.hijack(require)
var usageMessage =
"\n literapi [-vah] http://api.server:port/root file1 [file2 [...]]" +
"\n -v Show version number" +
"\n -a Show all results, not just errors" +
"\n -d Delay 50ms between calls (additional -d will double the delay)" +
"\n -w Overwrite the document with annotations about successes and failures" +
"\n -q Quiet mode: only returns ok/fail" +
"\n -h Show this help"
var literapi = require('./')
, optimist = require('optimist')
function usage() {
console.log(usageMessage)
usageMessage = "\n\nPlease specify some options"
function parse_args(args) {
return optimist(args)
.usage('Usage: $0 [-vawqhd] -r http://api.server:port/root file1 [file2 [...]]')
.describe('r', 'Root URI for the API').alias('r', 'root')
.describe('R', 'Reporter to use for test results').alias('R', 'reporter')
.describe('v', 'Return the version number').alias('v', 'version')
.describe('a', 'Show all results, not just errors').alias('a', 'all')
.describe('w', 'Overwrite the document with annotations about successes and failures').alias('w', 'write')
.describe('q', 'Quiet mode').alias('q', 'quiet')
.describe('h', 'Show this help').alias('h', 'help')
.describe('d', 'Delay 50ms between calls (additional -d will double the delay)').alias('d', 'delay')
}
function extract_options(params) {
function parse_opts(opts) {
// Make a shallow copy of params, as we will be munging it
params = params.slice()
// Start with default options
var argv = opts.argv
var options =

@@ -31,46 +29,33 @@ { serial: true

// Parse option flags from params
while (params[0] && params[0].length && params[0][0] === '-') {
for (var opt = params.shift(); opt = opt.slice(1); ) {
switch (opt[0]) {
case 'w':
options.write = true
break
case 'v':
console.log(LiterAPI.getVersion())
break
case 'p':
options.serial = false
break
case 's':
options.serial = true
break
case 'd':
options.delay = options.delay ? (options.delay * 2) : 50
break
case 'h':
usage()
break
case 'a':
options.reporter = require('vows/lib/vows/reporters/spec')
break
case 'q':
options.quiet = true
options.reporter = require('./reporters/quiet')
break
default:
console.log("Unrecognized option: -" + opt[0])
}
}
// Options
if (argv.w) options.write = true
if (argv.d) options.delay *= 2
if (argv.a) options.reporter = 'Spec'
if (argv.r) options.root = argv.r
if (argv.R) options.reporter = argv.R
if (argv.q) {
options.quiet = true
options.reporter = 'Dot'
}
options.files = argv._
// We require at least 2 arguments: the host and a file to run
if (params.length < 2) {
usage()
// Actions
if (argv.v) {
console.log(literapi.version)
process.exit()
}
if (argv.h || options.files.length === 0) {
opts.showHelp()
process.exit()
}
options.root = params.shift()
options.files = params
return options
}
function extract_options(params) {
options = parse_opts(parse_args(params))
// Merge config here
return options

@@ -87,8 +72,5 @@ }

if (!options.serial) {
console.log("Unfortunately, due to the ways vows work, tests *must* be run serially for now.")
options.serial = true
}
literapi.withDefaultPlugins(options).runWithFiles(options.files, function(err, results) {
if (err) throw err
runner(options).run(function(results) {
var status = 0

@@ -95,0 +77,0 @@ if (results.broken) status += 1

@@ -0,46 +1,86 @@

// Gently, see https://github.com/felixge/node-gently#gentlyhijackrealrequire
if (global.GENTLY) require = GENTLY.hijack(require)
var fs = require('fs')
, debug = require('debug')('literapi')
, path = require('path')
, plugins = require('./plugins')
, types = require('./types')
, _ = require('underscore')
var LiterAPI = function(options) {
if ('string' == typeof options) options = { root: options }
if (!options.compiler) options.compiler = 'vows'
if (!options.parser) options.parser = 'markdown'
this.options = options
this.compiler = new (require('./compilers/' + options.compiler))(options)
this.parser = new (require('./parsers/' + options.parser)) (options)
function LiterAPI(options) {
this.options = options
this.stack = []
this.book = new types.book
}
LiterAPI.getVersion = function() {
var packageFile = require('path').resolve(__filename, '../../package.json')
return JSON.parse(fs.readFileSync(packageFile)).version
}
LiterAPI.prototype = {}
LiterAPI.prototype.parse = function(src, cb) {
return this.parser.parse(src, cb)
LiterAPI.prototype.use = plugins.use
LiterAPI.prototype.run = function run(cb) {
debug('Running plugin stack')
plugins.run(this.stack, 0, 0, this.book, cb)
}
LiterAPI.prototype.compile = function(parsed, cb) {
return this.compiler.compile(parsed, cb)
LiterAPI.prototype.runWithFiles = function runWithFiles(files, cb) {
debug('runWithFiles', files)
_.each(files, function(file) {
this.book.addDocument({
filename: file,
title: file
})
}, this)
return this.run(cb)
}
LiterAPI.prototype.parseFile = function(filename, cb) {
fs.readFile(filename, 'utf8', function(err, src) {
if (err) return cb(err)
this.parse(src, function(err, parsed) {
if (err) return cb(err)
parsed.filename = filename
cb(null, parsed)
}.bind(this))
}.bind(this))
function literapi(options) {
return new LiterAPI(options)
}
LiterAPI.prototype.compileFile = function(filename, cb) {
this.parseFile(filename, function(err, parsed) {
if (err) cb(err)
this.compile(parsed, cb)
}.bind(this))
literapi.withDefaultPlugins = function (options) {
var l = literapi(options)
l.use(
[ literapi.readfile
, literapi.markdown_parse
, literapi.http_parse
, literapi.http_request({ root: options.root })
, literapi.http_match_response
//, literapi.default_reporter({ verbose: true })
, literapi.mocha_reporter(options.reporter || 'dot')
])
if (options.write) {
l.use(literapi.markdown_serialize)
l.use(literapi.writefile())
}
return l
}
module.exports = LiterAPI
literapi.__defineGetter__('version', function() {
if (!LiterAPI.version) {
var packageFile = require('path').resolve(__filename, '../../package.json')
LiterAPI.version = JSON.parse(fs.readFileSync(packageFile)).version
}
return LiterAPI.version
})
literapi.plugins = {}
/**
* Auto-load bundled plugins with getters.
*
* Adapted from [connect by TJ Holowaychuck]
* https://github.com/senchalabs/connect/blob/master/lib/connect.js
*/
_.each(fs.readdirSync(__dirname + '/plugins'), function(filename){
if (!/\.js$/.test(filename)) return
var name = path.basename(filename, '.js')
function load(){ return require('./plugins/' + name) }
literapi.plugins.__defineGetter__(name, load)
literapi.__defineGetter__(name, load)
})
module.exports = literapi

@@ -1,32 +0,48 @@

{ "name": "literapi"
, "version": "0.2.1"
, "description": "Literate testing for HTTP APIs using markdown"
, "keywords": ["testing", "test", "api", "rest", "http", "documentation", "docs", "literate"]
, "homepage": "https://github.com/agnoster/literapi"
, "author": "Isaac Wolkerstorfer <agnoster@gmail.com>"
, "main": "./lib/index.js"
, "repository":
{ "type": "git"
, "url": "git://github.com/agnoster/literapi.git"
{
"name": "literapi",
"version": "0.3.0",
"description": "Literate testing for HTTP APIs using markdown",
"keywords": [
"testing",
"test",
"api",
"rest",
"http",
"documentation",
"docs",
"literate"
],
"homepage": "https://github.com/agnoster/literapi",
"author": "Isaac Wolkerstorfer <agnoster@gmail.com>",
"main": "./lib/index.js",
"repository": {
"type": "git",
"url": "git://github.com/agnoster/literapi.git"
},
"bin": {
"literapi": "./bin/literapi"
},
"preferGlobal": true,
"scripts": {
"test": "make tap"
},
"dependencies": {
"mocha": "~1.6.0",
"request": "~2.10",
"markdownstream": "0.0.2",
"jsonexp": "0.0.3",
"debug": "~0.7.0",
"async": "~0.1.22",
"underscore": "~1.4.2",
"optimist": "~0.3.5"
},
"devDependencies": {
"express": "~3.0",
"should": "~1.2.0",
"gently": "~0.9.2"
},
"engines": {
"node": ">0.6.0",
"npm": "1.1.x"
}
, "bin":
{ "literapi": "./bin/literapi"
}
, "preferGlobal": true
, "scripts":
{ "test": "node test/example.js"
}
, "dependencies":
{ "vows": "~0.6"
, "request": "~2.10"
, "markdownstream": "0.0.2"
, "jsonexp": "~0.0.1"
}
, "devDependencies":
{ "express": "~3.0"
}
, "engines":
{ "node": ">0.6.0"
, "npm": "1.1.x"
}
}
var server = require('./example/server')
, LiterAPI = require('../lib')
, literapi = require('../lib')
var port = 74123
var port = 74000 + Math.floor(Math.random() * 1000)
var api = new LiterAPI(
{ root: "http://localhost:" + port
, compiler: "vows"
, parser: "markdown"
})
server.listen(port)
api.compileFile('test/example/README.md', function(err, vows) {
if (err) throw(err)
vows.reporter = require('vows/lib/vows/reporters/spec')
vows.run(null, function(results) {
server.close()
})
})
console.log('listing on port', port)
setTimeout(function(){
literapi.withDefaultPlugins({ root: "http://localhost:" + port })
.runWithFiles(['test/example/README.md'], function(err) {
server.close()
if (err) throw err
})
}, 1000)

@@ -15,3 +15,3 @@ # Example Tasks API

Content-Type: application/json; charset=utf-8
[]

@@ -79,3 +79,3 @@

GET /tasks/
### Response

@@ -82,0 +82,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc