Socket
Socket
Sign inDemoInstall

nock

Package Overview
Dependencies
Maintainers
1
Versions
430
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nock - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

22

lib/intercept.js
var path = require('path')
, http = require('http')
, url = require('url')
, EventEmitter = require('events').EventEmitter;

@@ -14,2 +15,20 @@

function remove(interceptor) {
var key = interceptor._key.split(' ');
var u = url.parse(key[1]);
var hostKey = u.protocol + '//' + u.host;
var interceptors = allInterceptors[hostKey];
var interceptor;
for(var i = 0; i < interceptors.length; i++) {
thisInterceptor = interceptors[i];
if (thisInterceptor._key === interceptor._key) {
interceptors.splice(i, 1);
break;
}
}
if (! interceptors) { delete allInterceptors[hostKey]; }
}
function stringifyRequest(options) {

@@ -80,3 +99,3 @@ var method = options.method || 'GET';

if (interceptors.length < 1) { throw new Error("Nock: No match for HTTP request " + stringifyRequest(options)); }
interceptor = interceptors.splice(0, 1)[0];
interceptor = interceptors.shift();

@@ -92,2 +111,3 @@ response.statusCode = interceptor.statusCode || 200;

};
remove(interceptor);
interceptor.discard();

@@ -94,0 +114,0 @@

2

package.json
{ "name" : "nock"
, "description" : "HTTP Server mocking for Node.js"
, "tags" : ["Mock", "HTTP", "testing", "isolation"]
, "version" : "0.2.1"
, "version" : "0.2.2"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>"

@@ -6,0 +6,0 @@ , "contributors" :

@@ -25,3 +25,3 @@ # Nock

It will intercept an HTTP GET request to '/users/1' and reply with a status 404.
It will intercept an HTTP GET request to '/users/1' and reply with a status 200, and the body will contain a user representation in JSON.

@@ -28,0 +28,0 @@ Then the test can call the module, and the module will do the HTTP requests.

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