Socket
Socket
Sign inDemoInstall

mm

Package Overview
Dependencies
1
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

5

History.md
0.0.3 / 2012-11-06
==================
* add req.abort() for mock request object
0.0.2 / 2012-11-06

@@ -3,0 +8,0 @@ ==================

55

lib/mm.js

@@ -67,2 +67,17 @@ /*!

function mockRequest() {
var req = new EventEmitter();
req.write = function () {};
req.end = function () {};
req.abort = function () {
req._aborted = true;
process.nextTick(function () {
var err = new Error('socket hang up');
err.code = 'ECONNRESET';
req.emit('error', err);
});
};
return req;
}
/**

@@ -91,6 +106,8 @@ * Mock http.request().

var req = new EventEmitter();
req.write = function () {};
req.end = function () {};
var req = mockRequest();
if (callback) {
req.on('response', callback);
}
var res = new EventEmitter();

@@ -101,8 +118,14 @@ res.headers = headers;

if (!chunk) {
return res.emit('end');
if (!req._aborted) {
res.emit('end');
}
return;
}
if (typeof chunk === 'string') {
chunk = new Buffer(chunk);
if (!req._aborted) {
if (typeof chunk === 'string') {
chunk = new Buffer(chunk);
}
res.emit('data', chunk);
}
res.emit('data', chunk);
process.nextTick(ondata);

@@ -112,4 +135,6 @@ };

setTimeout(function () {
callback(res);
process.nextTick(ondata);
if (!req._aborted) {
req.emit('response', res);
process.nextTick(ondata);
}
}, delay);

@@ -148,5 +173,3 @@

var req = new EventEmitter();
req.write = function () {};
req.end = function () {};
var req = mockRequest();

@@ -168,5 +191,9 @@ if (callback) {

process.nextTick(function () {
req.emit('error', resError);
if (!req._aborted) {
req.emit('error', resError);
}
});
req.emit('response', res);
if (!req._aborted) {
req.emit('response', res);
}
}, delay);

@@ -173,0 +200,0 @@

{
"name": "mm",
"version": "0.0.2",
"version": "0.0.3",
"description": "mock mate, mock http request, fs access and so on.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc