Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2025-01-27 17:21:38 +00:00
parent 7fdbca3ba3
commit 357e0ceaa9
360 changed files with 25673 additions and 917 deletions

57
node_modules/nock/README.md generated vendored
View file

@ -1,21 +1,11 @@
# Nock
[![npm](https://img.shields.io/npm/v/nock.svg)][npmjs]
[![Build Status](https://travis-ci.org/nock/nock.svg)][build]
![Coverage Status](http://img.shields.io/badge/coverage-100%25-brightgreen.svg)
[![Backers on Open Collective](https://opencollective.com/nock/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/nock/sponsors/badge.svg)](#sponsors)
[npmjs]: https://www.npmjs.com/package/nock
[build]: https://travis-ci.org/nock/nock
> **Notice**
>
> We have introduced experimental support for fetch. Please share your feedback with us. You can install it by:
>
> ```
> npm install --save-dev nock@beta
> ```
HTTP server mocking and expectations library for Node.js
@ -694,46 +684,17 @@ You are able to specify the number of milliseconds that your reply should be del
```js
nock('http://my.server.com')
.get('/')
.delay(2000) // 2 seconds delay will be applied to the response header.
.delay(2000) // 2 seconds delay will be applied to the response body.
.reply(200, '<html></html>')
```
`delay(1000)` is an alias for `delayConnection(1000).delayBody(0)`
`delay({ head: 1000, body: 2000 })` is an alias for `delayConnection(1000).delayBody(2000)`
Both of which are covered in detail below.
#### Delay the connection
You are able to specify the number of milliseconds that your connection should be idle before it starts to receive the response.
To simulate a socket timeout, provide a larger value than the timeout setting on the request.
```js
nock('http://my.server.com')
.get('/')
.delayConnection(2000) // 2 seconds
.reply(200, '<html></html>')
req = http.request('http://my.server.com', { timeout: 1000 })
```
Nock emits timeout events almost immediately by comparing the requested connection delay to the timeout parameter passed to `http.request()` or `http.ClientRequest#setTimeout()`.
This allows you to test timeouts without using fake timers or slowing down your tests.
If the client chooses to _not_ take an action (e.g. abort the request), the request and response will continue on as normal, after real clock time has passed.
##### Technical Details
Following the `'finish'` event being emitted by `ClientRequest`, Nock will wait for the next event loop iteration before checking if the request has been aborted.
At this point, any connection delay value is compared against any request timeout setting and a [`'timeout'`](https://nodejs.org/api/http.html#http_event_timeout) is emitted when appropriate from the socket and the request objects.
A Node timeout timer is then registered with any connection delay value to delay real time before checking again if the request has been aborted and the [`'response'`](http://nodejs.org/api/http.html#http_event_response) is emitted by the request.
A similar method, `.socketDelay()` was removed in version 13. It was thought that having two methods so subtlety similar was confusing.
The discussion can be found at https://github.com/nock/nock/pull/1974.
The `delayConnection` methods behavior of emitting quick timeout events when the connection delay exceeds the request timeout is now deprecated. Please use the `delay` function instead.
#### Delay the response body
You are able to specify the number of milliseconds that the response body should be delayed.
This is the time between the headers being received and the body starting to be received.
The `delayBody` is now deprecated. Please use the `delay` function instead.
```js
nock('http://my.server.com')
@ -1643,10 +1604,10 @@ It does this by manipulating the modules cache of Node in a way that conflicts w
## Debugging
Nock uses [`debug`](https://github.com/visionmedia/debug), so just run with environmental variable `DEBUG` set to `nock.*`.
Nock uses node internals [`debuglog`](https://nodejs.org/api/util.html#utildebuglogsection-callbackg), so just run with environmental variable `NODE_DEBUG` set to `nock:*`.
```console
user@local$ DEBUG=nock.* node my_test.js
user@local$ NODE_DEBUG=nock:* node my_test.js
```
Each step in the matching process is logged this way and can be useful when determining why a request was not intercepted by Nock.
@ -1660,11 +1621,11 @@ await got('http://example.com/?foo=bar&baz=foz')
```
```console
user@local$ DEBUG=nock.scope:example.com node my_test.js
user@local$ DEBUG=nock:scope:example.com node my_test.js
...
nock.scope:example.com Interceptor queries: {"foo":"bar"} +1ms
nock.scope:example.com Request queries: {"foo":"bar","baz":"foz"} +0ms
nock.scope:example.com query matching failed +0ms
NOCK:SCOPE:EXAMPLE.COM 103514: Interceptor queries: {"foo":"bar"}
NOCK:SCOPE:EXAMPLE.COM 103514: Request queries: {"foo":"bar","baz":"foz"}
NOCK:SCOPE:EXAMPLE.COM 103514: query matching failed
```
## Contributing

4
node_modules/nock/lib/back.js generated vendored
View file

@ -9,10 +9,9 @@ const {
removeAll: cleanAll,
} = require('./intercept')
const { loadDefs, define } = require('./scope')
const { back: debug } = require('./debug')
const { format } = require('util')
const path = require('path')
const debug = require('debug')('nock.back')
let _mode = null
@ -78,7 +77,6 @@ function Back(fixtureName, options, nockedFn) {
}
debug('context:', context)
// If nockedFn is a function then invoke it, otherwise return a promise resolving to nockDone.
if (typeof nockedFn === 'function') {
nockedFn.call(context, nockDone)

108
node_modules/nock/lib/common.js generated vendored
View file

@ -1,9 +1,10 @@
'use strict'
const debug = require('debug')('nock.common')
const { common: debug } = require('./debug')
const timers = require('timers')
const url = require('url')
const util = require('util')
const http = require('http')
/**
* Normalizes the request options so that it always has `host` property.
@ -50,82 +51,6 @@ function isUtf8Representable(buffer) {
return reconstructedBuffer.equals(buffer)
}
// Array where all information about all the overridden requests are held.
let requestOverrides = {}
/**
* Overrides the current `request` function of `http` and `https` modules with
* our own version which intercepts issues HTTP/HTTPS requests and forwards them
* to the given `newRequest` function.
*
* @param {Function} newRequest - a function handling requests; it accepts four arguments:
* - proto - a string with the overridden module's protocol name (either `http` or `https`)
* - overriddenRequest - the overridden module's request function already bound to module's object
* - options - the options of the issued request
* - callback - the callback of the issued request
*/
function overrideRequests(newRequest) {
debug('overriding requests')
;['http', 'https'].forEach(function (proto) {
debug('- overriding request for', proto)
const moduleName = proto // 1 to 1 match of protocol and module is fortunate :)
const module = require(proto)
const overriddenRequest = module.request
const overriddenGet = module.get
if (requestOverrides[moduleName]) {
throw new Error(
`Module's request already overridden for ${moduleName} protocol.`,
)
}
// Store the properties of the overridden request so that it can be restored later on.
requestOverrides[moduleName] = {
module,
request: overriddenRequest,
get: overriddenGet,
}
// https://nodejs.org/api/http.html#http_http_request_url_options_callback
module.request = function (input, options, callback) {
return newRequest(proto, overriddenRequest.bind(module), [
input,
options,
callback,
])
}
// https://nodejs.org/api/http.html#http_http_get_options_callback
module.get = function (input, options, callback) {
const req = newRequest(proto, overriddenGet.bind(module), [
input,
options,
callback,
])
req.end()
return req
}
debug('- overridden request for', proto)
})
}
/**
* Restores `request` function of `http` and `https` modules to values they
* held before they were overridden by us.
*/
function restoreOverriddenRequests() {
debug('restoring requests')
Object.entries(requestOverrides).forEach(
([proto, { module, request, get }]) => {
debug('- restoring request for', proto)
module.request = request
module.get = get
debug('- restored request for', proto)
},
)
requestOverrides = {}
}
/**
* In WHATWG URL vernacular, this returns the origin portion of a URL.
* However, the port is not included if it's standard and not already present on the host.
@ -621,6 +546,7 @@ function clearTimer(clear, ids) {
}
function removeAllTimers() {
debug('remove all timers')
clearTimer(clearTimeout, timeouts)
clearTimer(clearImmediate, immediates)
}
@ -653,6 +579,31 @@ function isRequestDestroyed(req) {
)
}
/**
* @param {Request} request
*/
function convertFetchRequestToClientRequest(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()),
}
// By default, Node adds a host header, but for maximum backward compatibility, we are now removing it.
// However, we need to consider leaving the header and fixing the tests.
if (options.headers.host === options.host) {
const { host, ...restHeaders } = options.headers
options.headers = restHeaders
}
return new http.ClientRequest(options)
}
/**
* Returns true if the given value is a plain object and not an Array.
* @param {*} value
@ -760,12 +711,11 @@ module.exports = {
normalizeClientRequestArgs,
normalizeOrigin,
normalizeRequestOptions,
overrideRequests,
percentDecode,
percentEncode,
removeAllTimers,
restoreOverriddenRequests,
setImmediate,
setTimeout,
stringifyRequest,
convertFetchRequestToClientRequest,
}

53
node_modules/nock/lib/create_response.js generated vendored Normal file
View file

@ -0,0 +1,53 @@
'use strict'
const { STATUS_CODES } = require('http')
/**
* Creates a Fetch API `Response` instance from the given
* `http.IncomingMessage` instance.
* Inspired by: https://github.com/mswjs/interceptors/blob/04152ed914f8041272b6e92ed374216b8177e1b2/src/interceptors/ClientRequest/utils/createResponse.ts#L8
*/
/**
* Response status codes for responses that cannot have body.
* @see https://fetch.spec.whatwg.org/#statuses
*/
const responseStatusCodesWithoutBody = [204, 205, 304]
/**
* @param {import('http').IncomingMessage} message
* @param {AbortSignal} signal
*/
function createResponse(message, signal) {
const responseBodyOrNull = responseStatusCodesWithoutBody.includes(
message.statusCode || 200,
)
? null
: new ReadableStream({
start(controller) {
message.on('data', chunk => controller.enqueue(chunk))
message.on('end', () => controller.close())
message.on('error', error => controller.error(error))
signal.addEventListener('abort', () => message.destroy(signal.reason))
},
cancel() {
message.destroy()
},
})
const rawHeaders = new Headers()
for (let i = 0; i < message.rawHeaders.length; i += 2) {
rawHeaders.append(message.rawHeaders[i], message.rawHeaders[i + 1])
}
// @mswjs/interceptors supports rawHeaders. https://github.com/mswjs/interceptors/pull/598
const response = new Response(responseBodyOrNull, {
status: message.statusCode,
statusText: message.statusMessage || STATUS_CODES[message.statusCode],
headers: rawHeaders,
})
return response
}
module.exports = { createResponse }

12
node_modules/nock/lib/debug.js generated vendored Normal file
View file

@ -0,0 +1,12 @@
'use strict'
const { debuglog } = require('util')
module.exports.back = debuglog('nock:back')
module.exports.common = debuglog('nock:common')
module.exports.intercept = debuglog('nock:intercept')
module.exports.request_overrider = debuglog('nock:request_overrider')
module.exports.playback_interceptor = debuglog('nock:playback_interceptor')
module.exports.recorder = debuglog('nock:recorder')
module.exports.socket = debuglog('nock:socket')
module.exports.scopeDebuglog = namespace => debuglog(`nock:scope:${namespace}`)

147
node_modules/nock/lib/intercept.js generated vendored
View file

@ -8,8 +8,20 @@ const { InterceptedRequestRouter } = require('./intercepted_request_router')
const common = require('./common')
const { inherits } = require('util')
const http = require('http')
const debug = require('debug')('nock.intercept')
const { intercept: debug } = require('./debug')
const globalEmitter = require('./global_emitter')
const { BatchInterceptor } = require('@mswjs/interceptors')
const {
default: nodeInterceptors,
} = require('@mswjs/interceptors/presets/node')
const { createResponse } = require('./create_response')
const { once } = require('events')
const interceptor = new BatchInterceptor({
name: 'nock-interceptor',
interceptors: nodeInterceptors,
})
let isNockActive = false
/**
* @name NetConnectNotAllowedError
@ -238,17 +250,6 @@ function removeInterceptor(options) {
// (which might or might not be node's original http.ClientRequest)
let originalClientRequest
function ErroringClientRequest(error) {
http.OutgoingMessage.call(this)
process.nextTick(
function () {
this.emit('error', error)
}.bind(this),
)
}
inherits(ErroringClientRequest, http.ClientRequest)
function overrideClientRequest() {
// Here's some background discussion about overriding ClientRequest:
// - https://github.com/nodejitsu/mock-request/issues/4
@ -333,6 +334,8 @@ function restoreOverriddenClientRequest() {
if (!originalClientRequest) {
debug('- ClientRequest was not overridden')
} else {
isNockActive = false
interceptor.dispose()
http.ClientRequest = originalClientRequest
originalClientRequest = undefined
@ -341,9 +344,7 @@ function restoreOverriddenClientRequest() {
}
function isActive() {
// If ClientRequest has been overwritten by Nock then originalClientRequest is not undefined.
// This means that Nock has been activated.
return originalClientRequest !== undefined
return isNockActive
}
function interceptorScopes() {
@ -367,75 +368,61 @@ function activeMocks() {
}
function activate() {
if (originalClientRequest) {
if (isNockActive) {
throw new Error('Nock already active')
}
// ----- Overriding http.request and https.request:
common.overrideRequests(function (proto, overriddenRequest, args) {
// NOTE: overriddenRequest is already bound to its module.
const { options, callback } = common.normalizeClientRequestArgs(...args)
if (Object.keys(options).length === 0) {
// As weird as it is, it's possible to call `http.request` without
// options, and it makes a request to localhost or somesuch. We should
// support it too, for parity. However it doesn't work today, and fixing
// it seems low priority. Giving an explicit error is nicer than
// crashing with a weird stack trace. `new ClientRequest()`, nock's
// other client-facing entry point, makes a similar check.
// https://github.com/nock/nock/pull/1386
// https://github.com/nock/nock/pull/1440
throw Error(
'Making a request with empty `options` is not supported in Nock',
)
}
// The option per the docs is `protocol`. Its unclear if this line is meant to override that and is misspelled or if
// the intend is to explicitly keep track of which module was called using a separate name.
// Either way, `proto` is used as the source of truth from here on out.
options.proto = proto
const interceptors = interceptorsFor(options)
if (isOn() && interceptors) {
const matches = interceptors.some(interceptor =>
interceptor.matchOrigin(options),
)
const allowUnmocked = interceptors.some(
interceptor => interceptor.options.allowUnmocked,
)
if (!matches && allowUnmocked) {
let req
if (proto === 'https') {
const { ClientRequest } = http
http.ClientRequest = originalClientRequest
req = overriddenRequest(options, callback)
http.ClientRequest = ClientRequest
} else {
req = overriddenRequest(options, callback)
}
globalEmitter.emit('no match', req)
return req
}
// NOTE: Since we already overrode the http.ClientRequest we are in fact constructing
// our own OverriddenClientRequest.
return new http.ClientRequest(options, callback)
} else {
globalEmitter.emit('no match', options)
if (isOff() || isEnabledForNetConnect(options)) {
return overriddenRequest(options, callback)
} else {
const error = new NetConnectNotAllowedError(options.host, options.path)
return new ErroringClientRequest(error)
}
}
})
overrideClientRequest()
interceptor.apply()
// Force msw to forward Nock's error instead of coerce it into 500 error
interceptor.on('unhandledException', ({ controller, error }) => {
controller.errorWith(error)
})
interceptor.on(
'request',
async function ({ request: mswRequest, controller }) {
const request = mswRequest.clone()
const { options } = common.normalizeClientRequestArgs(request.url)
options.proto = options.protocol.slice(0, -1)
options.method = request.method
const interceptors = interceptorsFor(options)
if (isOn() && interceptors) {
const matches = interceptors.some(interceptor =>
interceptor.matchOrigin(options),
)
const allowUnmocked = interceptors.some(
interceptor => interceptor.options.allowUnmocked,
)
const nockRequest = common.convertFetchRequestToClientRequest(request)
if (!matches && allowUnmocked) {
globalEmitter.emit('no match', nockRequest)
} else {
nockRequest.on('response', nockResponse => {
const response = createResponse(nockResponse, mswRequest.signal)
controller.respondWith(response)
})
const promise = Promise.race([
// TODO: temp hacky way to handle allowUnmocked in startPlayback
once(nockRequest, 'real-request'),
once(nockRequest, 'error'),
once(nockRequest, 'response'),
])
const buffer = await request.arrayBuffer()
nockRequest.write(buffer)
nockRequest.end()
await promise
}
} else {
globalEmitter.emit('no match', options)
if (!(isOff() || isEnabledForNetConnect(options))) {
throw new NetConnectNotAllowedError(options.host, options.path)
}
}
},
)
isNockActive = true
}
module.exports = {

View file

@ -1,12 +1,7 @@
'use strict'
const debug = require('debug')('nock.request_overrider')
const {
IncomingMessage,
ClientRequest,
request: originalHttpRequest,
} = require('http')
const { request: originalHttpsRequest } = require('https')
const { request_overrider: debug } = require('./debug')
const { IncomingMessage, ClientRequest } = require('http')
const propagate = require('propagate')
const common = require('./common')
const globalEmitter = require('./global_emitter')
@ -333,14 +328,7 @@ class InterceptedRequestRouter {
)
if (allowUnmocked && req instanceof ClientRequest) {
const newReq =
options.proto === 'https'
? originalHttpsRequest(options)
: originalHttpRequest(options)
propagate(newReq, req)
// We send the raw buffer as we received it, not as we interpreted it.
newReq.end(requestBodyBuffer)
req.emit('real-request')
} else {
const reqStr = common.stringifyRequest(options, requestBodyString)
const err = new Error(`Nock: No match for request ${reqStr}`)

View file

@ -248,14 +248,7 @@ module.exports = class Interceptor {
}
match(req, options, body) {
// check if the logger is enabled because the stringifies can be expensive.
if (this.scope.logger.enabled) {
this.scope.logger(
'attempting match %s, body = %s',
stringify(options),
stringify(body),
)
}
this.scope.logger('attempting match %j, body = %j', options, body)
const method = (options.method || 'GET').toUpperCase()
let { path = '/' } = options

View file

@ -63,10 +63,11 @@ module.exports = function matchBody(options, spec, body) {
function mapValues(object, cb) {
const keys = Object.keys(object)
const clonedObject = { ...object }
for (const key of keys) {
object[key] = cb(object[key], key, object)
clonedObject[key] = cb(clonedObject[key], key, clonedObject)
}
return object
return clonedObject
}
/**

View file

@ -3,7 +3,7 @@
const stream = require('stream')
const util = require('util')
const zlib = require('zlib')
const debug = require('debug')('nock.playback_interceptor')
const { playback_interceptor: debug } = require('./debug')
const common = require('./common')
function parseJSONRequestBody(req, requestBody) {

157
node_modules/nock/lib/recorder.js generated vendored
View file

@ -1,16 +1,24 @@
'use strict'
const debug = require('debug')('nock.recorder')
const { recorder: debug } = require('./debug')
const querystring = require('querystring')
const { inspect } = require('util')
const common = require('./common')
const { restoreOverriddenClientRequest } = require('./intercept')
const { EventEmitter } = require('stream')
const { gzipSync, brotliCompressSync, deflateSync } = require('zlib')
const {
default: nodeInterceptors,
} = require('@mswjs/interceptors/presets/node')
const SEPARATOR = '\n<<<<<<-- cut here -->>>>>>\n'
let recordingInProgress = false
let outputs = []
// TODO: don't reuse the nodeInterceptors, create new ones.
const clientRequestInterceptor = nodeInterceptors[0]
const fetchRequestInterceptor = nodeInterceptors[2]
function getScope(options) {
const { proto, host, port } = common.normalizeRequestOptions(options)
return common.normalizeOrigin(proto, host, port)
@ -210,28 +218,67 @@ function record(recOptions) {
// we restore any requests that may have been overridden by other parts of nock (e.g. intercept)
// NOTE: This is hacky as hell but it keeps the backward compatibility *and* allows correct
// behavior in the face of other modules also overriding ClientRequest.
common.restoreOverriddenRequests()
// common.restoreOverriddenRequests()
// We restore ClientRequest as it messes with recording of modules that also override ClientRequest (e.g. xhr2)
restoreOverriddenClientRequest()
// We override the requests so that we can save information on them before executing.
common.overrideRequests(function (proto, overriddenRequest, rawArgs) {
const { options, callback } = common.normalizeClientRequestArgs(...rawArgs)
const bodyChunks = []
clientRequestInterceptor.apply()
fetchRequestInterceptor.apply()
clientRequestInterceptor.on('request', async function ({ request }) {
await recordRequest(request)
})
fetchRequestInterceptor.on('request', async function ({ request }) {
await recordRequest(request)
})
async function recordRequest(mswRequest) {
const request = mswRequest.clone()
const { options } = common.normalizeClientRequestArgs(request.url)
options.method = request.method
const proto = options.protocol.slice(0, -1)
// Node 0.11 https.request calls http.request -- don't want to record things
// twice.
/* istanbul ignore if */
if (options._recording) {
return overriddenRequest(options, callback)
return
}
options._recording = true
const req = overriddenRequest(options, function (res) {
const req = new EventEmitter()
req.on('response', function () {
debug(thisRecordingId, 'intercepting', proto, 'request to record')
// We put our 'end' listener to the front of the listener array.
res.once('end', function () {
clientRequestInterceptor.once('response', async function ({ response }) {
await recordResponse(response)
})
fetchRequestInterceptor.once('response', async function ({ response }) {
// fetch decompresses the body automatically, so we need to recompress it
const codings =
response.headers
.get('content-encoding')
?.toLowerCase()
.split(',')
.map(c => c.trim()) || []
let body = await response.arrayBuffer()
for (const coding of codings) {
if (coding === 'gzip') {
body = gzipSync(body)
} else if (coding === 'deflate') {
body = deflateSync(body)
} else if (coding === 'br') {
body = brotliCompressSync(body)
}
}
await recordResponse(new Response(body, response))
})
// Intercept "res.once('end', ...)"-like event
async function recordResponse(mswResponse) {
const response = mswResponse.clone()
debug(thisRecordingId, proto, 'intercepted request ended')
let reqheaders
@ -239,19 +286,26 @@ function record(recOptions) {
if (enableReqHeadersRecording) {
// We never record user-agent headers as they are worse than useless -
// they actually make testing more difficult without providing any benefit (see README)
reqheaders = req.getHeaders()
reqheaders = Object.fromEntries(request.headers.entries())
common.deleteHeadersField(reqheaders, 'user-agent')
}
const headers = Object.fromEntries(response.headers.entries())
const res = {
statusCode: response.status,
headers,
rawHeaders: headers,
}
const generateFn = outputObjects
? generateRequestAndResponseObject
: generateRequestAndResponse
let out = generateFn({
req,
bodyChunks,
req: options,
bodyChunks: [Buffer.from(await request.arrayBuffer())],
options,
res,
dataChunks,
dataChunks: [Buffer.from(await response.arrayBuffer())],
reqheaders,
})
@ -282,33 +336,6 @@ function record(recOptions) {
logging(out)
}
}
})
let encoding
// We need to be aware of changes to the stream's encoding so that we
// don't accidentally mangle the data.
const { setEncoding } = res
res.setEncoding = function (newEncoding) {
encoding = newEncoding
return setEncoding.apply(this, arguments)
}
const dataChunks = []
// Replace res.push with our own implementation that stores chunks
const origResPush = res.push
res.push = function (data) {
if (data) {
if (encoding) {
data = Buffer.from(data, encoding)
}
dataChunks.push(data)
}
return origResPush.call(res, data)
}
if (callback) {
callback(res, options, callback)
}
debug('finished setting up intercepting')
@ -322,46 +349,11 @@ function record(recOptions) {
}
})
const recordChunk = (chunk, encoding) => {
debug(thisRecordingId, 'new', proto, 'body chunk')
if (!Buffer.isBuffer(chunk)) {
chunk = Buffer.from(chunk, encoding)
}
bodyChunks.push(chunk)
}
const oldWrite = req.write
req.write = function (chunk, encoding) {
if (typeof chunk !== 'undefined') {
recordChunk(chunk, encoding)
oldWrite.apply(req, arguments)
} else {
throw new Error('Data was undefined.')
}
}
// Starting in Node 8, `OutgoingMessage.end()` directly calls an internal
// `write_` function instead of proxying to the public
// `OutgoingMessage.write()` method, so we have to wrap `end` too.
const oldEnd = req.end
req.end = function (chunk, encoding, callback) {
debug('req.end')
if (typeof chunk === 'function') {
callback = chunk
chunk = null
} else if (typeof encoding === 'function') {
callback = encoding
encoding = null
}
if (chunk) {
recordChunk(chunk, encoding)
}
oldEnd.call(req, chunk, encoding, callback)
}
return req
})
// This is a massive change, we are trying to change minimum code, so we emit end event here
// because mswjs take care for these events
// TODO: refactor the recorder, we no longer need all the listeners and can just record the request we get from MSW
req.emit('response')
}
}
// Restore *all* the overridden http/https modules' properties.
@ -371,7 +363,8 @@ function restore() {
'restoring all the overridden http/https properties',
)
common.restoreOverriddenRequests()
clientRequestInterceptor.dispose()
fetchRequestInterceptor.dispose()
restoreOverriddenClientRequest()
recordingInProgress = false
}

4
node_modules/nock/lib/scope.js generated vendored
View file

@ -3,11 +3,11 @@
/**
* @module nock/scope
*/
const { scopeDebuglog } = require('./debug')
const { addInterceptor, isOn } = require('./intercept')
const common = require('./common')
const assert = require('assert')
const url = require('url')
const debug = require('debug')('nock.scope')
const { EventEmitter } = require('events')
const Interceptor = require('./interceptor')
@ -99,7 +99,7 @@ class Scope extends EventEmitter {
logNamespace = this.urlParts.host
}
this.logger = debug.extend(logNamespace)
this.logger = scopeDebuglog(logNamespace)
}
add(key, interceptor) {

2
node_modules/nock/lib/socket.js generated vendored
View file

@ -1,7 +1,7 @@
'use strict'
const { EventEmitter } = require('events')
const debug = require('debug')('nock.socket')
const { socket: debug } = require('./debug')
module.exports = class Socket extends EventEmitter {
constructor(options) {

8
node_modules/nock/package.json generated vendored
View file

@ -7,7 +7,7 @@
"testing",
"isolation"
],
"version": "13.5.6",
"version": "14.0.0",
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
"repository": {
"type": "git",
@ -17,12 +17,12 @@
"url": "https://github.com/nock/nock/issues"
},
"engines": {
"node": ">= 10.13"
"node": ">= 18"
},
"main": "./index.js",
"types": "types",
"dependencies": {
"debug": "^4.1.0",
"@mswjs/interceptors": "^0.37.3",
"json-stringify-safe": "^5.0.1",
"propagate": "^2.0.0"
},
@ -49,7 +49,7 @@
"proxyquire": "^2.1.0",
"rimraf": "^3.0.0",
"semantic-release": "^24.1.0",
"sinon": "^15.0.1",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"typescript": "^5.0.4"
},

5
node_modules/nock/types/index.d.ts generated vendored
View file

@ -205,8 +205,13 @@ declare namespace nock {
thrice(): this
optionally(flag?: boolean): this
delay(opts: number): this
/** @deprecated use delay(number) instead */
delay(opts: { head?: number; body?: number }): this
delay(opts: number | { head?: number; body?: number }): this
/** @deprecated use delay function instead */
delayBody(timeMs: number): this
/** @deprecated use delay function instead */
delayConnection(timeMs: number): this
}