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

mocksy

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocksy - npm Package Compare versions

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();
});
});
});
});
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