hyperactive
Advanced tools
Comparing version 2.1.2 to 2.2.0
{ | ||
"name": "hyperactive", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Creates mocha tests for all hypermedia of your API", | ||
@@ -30,4 +30,5 @@ "author": "Tabcorp Digital Technology Team", | ||
"unirest": "~0.2.7", | ||
"uri-templates": "~0.1.5" | ||
"uri-templates": "~0.1.5", | ||
"async": "~0.9.0" | ||
} | ||
} |
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var build, config, createIt, expandUrl, linkFilter, linkFinder, localItFunction, setIt, templates, validate, _; | ||
var async, build, config, createIt, expandUrl, linkFilter, linkFinder, localItFunction, setIt, templates, validate, _; | ||
_ = require('lodash'); | ||
async = require('async'); | ||
templates = require('uri-templates'); | ||
@@ -43,19 +45,48 @@ | ||
exports.createItWithResult = function(url, err) { | ||
return localItFunction(url, function(done) { | ||
return done(err); | ||
}); | ||
}; | ||
exports.processResponse = (function(_this) { | ||
return function(parent, res, templateValues, done) { | ||
var err; | ||
if (!res.ok) { | ||
return done("Bad status " + res.status + " for url " + res.url); | ||
} | ||
if (!validate(parent, res)) { | ||
return done("Not a valid response: " + res.body); | ||
try { | ||
if (!validate(parent, res)) { | ||
return done("Not a valid response: " + res.body); | ||
} | ||
} catch (_error) { | ||
err = _error; | ||
return done(err); | ||
} | ||
describe("" + parent, function() { | ||
return _.forEach(exports.getLinks(res), function(link) { | ||
var expandedLink; | ||
linkFilter.processLink(link); | ||
expandedLink = expandUrl(link, templateValues); | ||
return exports.crawl(expandedLink, templateValues); | ||
return describe("" + parent, function() { | ||
var requests; | ||
requests = _.map(exports.getLinks(res), function(link) { | ||
return function(callback) { | ||
var expandedLink; | ||
linkFilter.processLink(link); | ||
expandedLink = expandUrl(link, templateValues); | ||
return build.request(expandedLink, config.options).end((function(_this) { | ||
return function(res) { | ||
return exports.processResponse(expandedLink, res, templateValues, function(err) { | ||
return callback(null, { | ||
err: err, | ||
link: expandedLink | ||
}); | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
}); | ||
return async.parallel(requests, function(err, results) { | ||
results.forEach(function(result) { | ||
return exports.createItWithResult(result.link, result.err); | ||
}); | ||
return done(); | ||
}); | ||
}); | ||
return done(); | ||
}; | ||
@@ -79,6 +110,2 @@ })(this); | ||
exports.crawl = function(url, templateValues) { | ||
return createIt(url, templateValues); | ||
}; | ||
exports.startCrawl = function(config, it) { | ||
@@ -93,3 +120,3 @@ var expandedUrl; | ||
linkFilter.processLink(expandedUrl); | ||
return exports.crawl(expandedUrl, config.templateValues); | ||
return createIt(expandedUrl, config.templateValues); | ||
}; | ||
@@ -96,0 +123,0 @@ |
11696
186
5
+ Addedasync@~0.9.0