Comparing version 0.1.7 to 1.0.0
48
index.js
@@ -5,23 +5,46 @@ var http = require('http'); | ||
var Mocksy = function (options) { | ||
var self = this; | ||
this.port = options.port || 1337; | ||
this.started = false; | ||
this.stopped = true; | ||
this.routes = { | ||
get: {}, | ||
post: {}, | ||
put: {}, | ||
delete: {} | ||
}; | ||
this.server = http.createServer(function (req, res) { | ||
var form = new formidable.IncomingForm(); | ||
form.parse(req, function(err, fields, files) { | ||
res.writeHead(200, {'Content-Type': 'application/json'}); | ||
res.end(JSON.stringify({ | ||
headers: req.headers, | ||
url: req.url, | ||
method: req.method, | ||
body: fields, | ||
files: files, | ||
withCredentials: req.withCredentials | ||
})); | ||
}); | ||
var method = req.method.toLowerCase(); | ||
if (self.routes[method] && self.routes[method][req.url]) { | ||
res.end(self.routes[method][req.url]); | ||
} | ||
else { | ||
var form = new formidable.IncomingForm(); | ||
form.parse(req, function(err, fields, files) { | ||
res.writeHead(200, {'Content-Type': 'application/json'}); | ||
res.end(JSON.stringify({ | ||
headers: req.headers, | ||
url: req.url, | ||
method: req.method, | ||
body: fields, | ||
files: files, | ||
withCredentials: req.withCredentials | ||
})); | ||
}); | ||
} | ||
}); | ||
}; | ||
Mocksy.prototype.get = function (pathname, response) { | ||
this.routes.get[pathname] = response; | ||
}; | ||
Mocksy.prototype.start = function (callback) { | ||
var self = this; | ||
@@ -44,2 +67,3 @@ | ||
Mocksy.prototype.stop = function (callback) { | ||
var self = this; | ||
@@ -46,0 +70,0 @@ |
{ | ||
"name": "mocksy", | ||
"version": "0.1.7", | ||
"version": "1.0.0", | ||
"description": "Mock http server for testing. Regurgitates the request object.", | ||
@@ -27,6 +27,6 @@ "main": "index.js", | ||
"devDependencies": { | ||
"tape": "~1.1.1", | ||
"request": "~2.27.0", | ||
"tap-spec": "^0.1.3", | ||
"reqwest": "^1.1.0" | ||
"request": "^2.51.0", | ||
"reqwest": "^1.1.0", | ||
"tap-spec": "^2.1.1", | ||
"tape": "^3.0.3" | ||
}, | ||
@@ -33,0 +33,0 @@ "dependencies": { |
@@ -67,2 +67,24 @@ var test = require('tape'); | ||
}); | ||
}); | ||
test('intercept', function (t) { | ||
var mocksy = new Mocksy({port: 1337}); | ||
mocksy.get('/testing', 'just testing'); | ||
mocksy.start(function () { | ||
request({ | ||
url: 'http://localhost:1337/testing', | ||
method: 'GET', | ||
}, function (err, response, body) { | ||
t.equal(body, 'just testing', 'intercepted'); | ||
mocksy.stop(function () { | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
5550
130
1