Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2025-04-02 12:43:14 +00:00
parent 4b72bef651
commit dbb232a3d8
1389 changed files with 209949 additions and 542 deletions

View file

@ -4,6 +4,7 @@ import { Interceptor } from './Interceptor'
import { BatchInterceptor } from './BatchInterceptor'
import { ClientRequestInterceptor } from './interceptors/ClientRequest'
import { XMLHttpRequestInterceptor } from './interceptors/XMLHttpRequest'
import { FetchInterceptor } from './interceptors/fetch'
import { handleRequest } from './utils/handleRequest'
import { RequestController } from './RequestController'
import { FetchResponse } from './utils/fetchUtils'
@ -30,7 +31,7 @@ export interface SerializedResponse {
}
export class RemoteHttpInterceptor extends BatchInterceptor<
[ClientRequestInterceptor, XMLHttpRequestInterceptor]
[ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]
> {
constructor() {
super({
@ -38,6 +39,7 @@ export class RemoteHttpInterceptor extends BatchInterceptor<
interceptors: [
new ClientRequestInterceptor(),
new XMLHttpRequestInterceptor(),
new FetchInterceptor(),
],
})
}

View file

@ -9,6 +9,7 @@ import {
declare module 'node:http' {
interface Agent {
options?: http.AgentOptions
createConnection(options: any, callback: any): net.Socket
}
}
@ -33,15 +34,23 @@ export class MockAgent extends http.Agent {
public createConnection(options: any, callback: any): net.Socket {
const createConnection =
(this.customAgent instanceof http.Agent &&
this.customAgent.createConnection) ||
super.createConnection
this.customAgent instanceof http.Agent
? this.customAgent.createConnection
: super.createConnection
const createConnectionOptions =
this.customAgent instanceof http.Agent
? {
...options,
...this.customAgent.options,
}
: options
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),
@ -66,15 +75,23 @@ export class MockHttpsAgent extends https.Agent {
public createConnection(options: any, callback: any): net.Socket {
const createConnection =
(this.customAgent instanceof https.Agent &&
this.customAgent.createConnection) ||
super.createConnection
this.customAgent instanceof https.Agent
? this.customAgent.createConnection
: super.createConnection
const createConnectionOptions =
this.customAgent instanceof https.Agent
? {
...options,
...this.customAgent.options,
}
: options
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),

View file

@ -341,6 +341,50 @@ it('sets fallback Agent based on the URL protocol', () => {
expect(agent).toHaveProperty('protocol', url.protocol)
})
it('preserves `requestUnauthorized` option set to undefined', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
{ rejectUnauthorized: undefined },
])
expect(options.rejectUnauthorized).toBe(undefined)
expect((options.agent as HttpsAgent).options.rejectUnauthorized).toBe(
undefined
)
})
it('preserves `requestUnauthorized` option set to true', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
{ rejectUnauthorized: true },
])
expect(options.rejectUnauthorized).toBe(true)
expect((options.agent as HttpsAgent).options.rejectUnauthorized).toBe(true)
})
it('preserves `requestUnauthorized` option set to false', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
{ rejectUnauthorized: false },
])
expect(options.rejectUnauthorized).toBe(false)
expect((options.agent as HttpsAgent).options.rejectUnauthorized).toBe(false)
})
it('does not add `rejectUnauthorized` value if not set', () => {
const agent = new HttpsAgent()
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
])
expect(options).not.toHaveProperty('rejectUnauthorized')
expect((options.agent as HttpsAgent).options).not.toHaveProperty(
'rejectUnauthorized'
)
})
it('does not set any fallback Agent given "agent: false" option', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',

View file

@ -243,7 +243,10 @@ export function normalizeClientRequestArgs(
const agent =
options.protocol === 'https:'
? new HttpsAgent({
rejectUnauthorized: options.rejectUnauthorized,
// Any other value other than false is considered as true, so we don't add this property if undefined.
...('rejectUnauthorized' in options && {
rejectUnauthorized: options.rejectUnauthorized,
}),
})
: new HttpAgent()

View file

@ -144,6 +144,14 @@ export class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
'no mocked response received, performing request as-is...'
)
/**
* @note Clone the request instance right before performing it.
* This preserves any modifications made to the intercepted request
* in the "request" listener. This also allows the user to read the
* request body in the "response" listener (otherwise "unusable").
*/
const requestCloneForResponseEvent = request.clone()
return pureFetch(request).then(async (response) => {
this.logger.info('original fetch performed', response)
@ -155,7 +163,7 @@ export class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
await emitAsync(this.emitter, 'response', {
response: responseClone,
isMockedResponse: false,
request,
request: requestCloneForResponseEvent,
requestId,
})
}

View file

@ -90,8 +90,10 @@ it('spies on the constructor', () => {
}
const constructorCall = vi.fn<
[ConstructorParameters<typeof OriginalClass>, Function],
typeof OriginalClass
(
args: ConstructorParameters<typeof OriginalClass>,
next: () => typeof OriginalClass
) => typeof OriginalClass
>((args, next) => next())
const ProxyClass = createProxy(OriginalClass, {

View file

@ -6,7 +6,7 @@ beforeAll(() => {
})
afterEach(() => {
vi.resetAllMocks()
vi.clearAllMocks()
})
afterAll(() => {