Socket
Socket
Sign inDemoInstall

nock

Package Overview
Dependencies
Maintainers
4
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 13.5.1 to 14.0.0-beta.1

lib/create_response.js

19

lib/common.js

@@ -738,2 +738,20 @@ 'use strict'

/**
* @param {Request} request
*/
function convertFetchRequestToOptions(request) {
const url = new URL(request.url)
const options = {
...urlToOptions(url),
method: request.method,
host: url.hostname,
port: url.port || (url.protocol === 'https:' ? 443 : 80),
path: url.pathname + url.search,
proto: url.protocol.slice(0, -1),
headers: Object.fromEntries(request.headers.entries()),
}
return options
}
module.exports = {

@@ -769,2 +787,3 @@ contentEncoding,

stringifyRequest,
convertFetchRequestToClientRequest: convertFetchRequestToOptions,
}

27

lib/intercept.js

@@ -13,2 +13,3 @@ 'use strict'

const globalEmitter = require('./global_emitter')
const { createResponse } = require('./create_response')

@@ -306,3 +307,5 @@ /**

if (isOff() || isEnabledForNetConnect(options)) {
originalClientRequest.apply(this, arguments)
if (options.isFetchRequest === undefined) {
originalClientRequest.apply(this, arguments)
}
} else {

@@ -439,2 +442,24 @@ common.setImmediate(

const originalFetch = global.fetch
global.fetch = async (input, init = undefined) => {
const request = new Request(input, init)
const options = common.convertFetchRequestToClientRequest(request)
options.isFetchRequest = true
const body = await request.arrayBuffer()
const clientRequest = new http.ClientRequest(options)
// If mock found
if (clientRequest.interceptors) {
return new Promise((resolve, reject) => {
clientRequest.on('response', response => {
resolve(createResponse(response))
})
clientRequest.on('error', reject)
clientRequest.end(body)
})
} else {
return originalFetch(input, init)
}
}
overrideClientRequest()

@@ -441,0 +466,0 @@ }

2

package.json

@@ -10,3 +10,3 @@ {

],
"version": "13.5.1",
"version": "14.0.0-beta.1",
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",

@@ -13,0 +13,0 @@ "repository": {

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