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.5.7 to 0.6.0

16

lib/intercept.js
var path = require('path')
, http = require('http')
, https = require('https')
, url = require('url')

@@ -341,2 +342,17 @@ , EventEmitter = require('events').EventEmitter;

var httpsRequest = https.request;
https.request = function(options, callback) {
var basePath = 'https://' + options.host
, interceptors = allInterceptors[basePath];
options.https = true;
if (interceptors && interceptors.length > 0) {
return processRequest(interceptors, options, callback);
} else {
return httpRequest.apply(http, arguments);
}
};
module.exports = addGlobalInterceptor;

5

lib/scope.js

@@ -67,3 +67,4 @@ var path = require('path')

, path = options.path
, matches;
, matches
, proto = options.https ? 'https': 'http';

@@ -75,3 +76,3 @@ if (transformPathFunction) { path = transformPathFunction(path); }

if (transformRequestBodyFunction) { body = transformRequestBodyFunction(body); }
var matchKey = method + ' http://' + options.host + path;
var matchKey = method + ' ' + proto + '://' + options.host + path;
if (body) { matchKey += (' ' + body); }

@@ -78,0 +79,0 @@ matches = matchKey === this._key;

2

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

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

var nock = require('../.')
var http = require('http');
var https = require('https');
var util = require('util');

@@ -806,1 +807,28 @@ var events = require('events');

});
tap.test("can use https", function(t) {
var dataCalled = false
var scope = nock('https://google.com')
.get('/')
.reply(200, "Hello World!");
var req = https.request({
host: "google.com"
, path: '/'
}, function(res) {
t.equal(res.statusCode, 200);
res.on('end', function() {
t.ok(dataCalled);
scope.done();
t.end();
});
res.on('data', function(data) {
dataCalled = true;
t.ok(data instanceof Buffer, "data should be buffer");
t.equal(data.toString(), "Hello World!", "response should match");
});
});
req.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