diff --git a/packages/proxy/__tests__/proxyRequests.test.ts b/packages/proxy/__tests__/proxyRequests.test.ts index 23bc8f94e..9fb4ac179 100644 --- a/packages/proxy/__tests__/proxyRequests.test.ts +++ b/packages/proxy/__tests__/proxyRequests.test.ts @@ -24,6 +24,7 @@ beforeEach(() => { setGlobalDispatcher(mockAgent); // enabled the mock client to intercept requests mockPool = mockAgent.get('https://discord.com'); + api.setAgent(mockAgent); }); afterEach(async () => { diff --git a/packages/rest/__tests__/REST.test.ts b/packages/rest/__tests__/REST.test.ts index 2f451699d..f733b8d28 100644 --- a/packages/rest/__tests__/REST.test.ts +++ b/packages/rest/__tests__/REST.test.ts @@ -37,6 +37,8 @@ beforeEach(() => { setGlobalDispatcher(mockAgent); // enabled the mock client to intercept requests mockPool = mockAgent.get('https://discord.com'); + api.setAgent(mockAgent); + fetchApi.setAgent(mockAgent); }); afterEach(async () => { diff --git a/packages/rest/__tests__/RequestHandler.test.ts b/packages/rest/__tests__/RequestHandler.test.ts index 6471a1add..16f02769c 100644 --- a/packages/rest/__tests__/RequestHandler.test.ts +++ b/packages/rest/__tests__/RequestHandler.test.ts @@ -481,6 +481,8 @@ test('perm server outage', async () => { test('server responding too slow', async () => { const api2 = new REST({ timeout: 1 }).setToken('A-Very-Really-Real-Token'); + api2.setAgent(mockAgent); + mockPool .intercept({ path: genPath('/slow'), diff --git a/packages/rest/__tests__/RequestManager.test.ts b/packages/rest/__tests__/RequestManager.test.ts index e0a6b6ced..c158663de 100644 --- a/packages/rest/__tests__/RequestManager.test.ts +++ b/packages/rest/__tests__/RequestManager.test.ts @@ -15,6 +15,7 @@ beforeEach(() => { setGlobalDispatcher(mockAgent); mockPool = mockAgent.get('https://discord.com'); + api.setAgent(mockAgent); }); afterEach(async () => { diff --git a/packages/rest/__tests__/UndiciRequest.test.ts b/packages/rest/__tests__/UndiciRequest.test.ts index 95e0f4b8d..90bcc057f 100644 --- a/packages/rest/__tests__/UndiciRequest.test.ts +++ b/packages/rest/__tests__/UndiciRequest.test.ts @@ -28,6 +28,7 @@ beforeEach(() => { setGlobalDispatcher(mockAgent); // enabled the mock client to intercept requests mockPool = mockAgent.get('https://discord.com'); + api.setAgent(mockAgent); }); afterEach(async () => { diff --git a/packages/rest/src/strategies/undiciRequest.ts b/packages/rest/src/strategies/undiciRequest.ts index 5eee90c5e..bafd05028 100644 --- a/packages/rest/src/strategies/undiciRequest.ts +++ b/packages/rest/src/strategies/undiciRequest.ts @@ -1,12 +1,14 @@ import { STATUS_CODES } from 'node:http'; import { URLSearchParams } from 'node:url'; import { types } from 'node:util'; -import { type RequestInit, request, Headers, FormData as UndiciFormData } from 'undici'; +import { type RequestInit, request, Headers, FormData as UndiciFormData, Agent } from 'undici'; import type { HeaderRecord } from 'undici/types/header.js'; import type { ResponseLike } from '../shared.js'; export type RequestOptions = Exclude[1], undefined>; +let localAgent: Agent | null = null; + export async function makeRequest(url: string, init: RequestInit): Promise { // The cast is necessary because `headers` and `method` are narrower types in `undici.request` // our request path guarantees they are of acceptable type for `undici.request` @@ -14,6 +16,15 @@ export async function makeRequest(url: string, init: RequestInit): Promise