|
1 |
| -import type { DispatcherOptions } from "../../src/request.js"; |
2 |
| -import type { Interceptable } from "undici"; |
| 1 | +import type { Interceptable } from "../../src/request.js"; |
3 | 2 |
|
4 | 3 | import { after, before } from "node:test";
|
5 | 4 |
|
6 |
| -import { MockAgent } from "undici"; |
| 5 | +import { getTestDispatcher } from "../../src/request.js"; |
7 | 6 |
|
8 |
| -export function getTestDispatcherOptions( |
9 |
| - options: DispatcherOptions = {}, |
10 |
| -): DispatcherOptions & { isTestDispatcher: true } { |
11 |
| - return { |
12 |
| - ...options, |
13 |
| - isTestDispatcher: true, |
14 |
| - }; |
| 7 | +interface InitializeOptions { |
| 8 | + url?: string; |
| 9 | + timeout?: number; |
15 | 10 | }
|
16 | 11 |
|
17 |
| -const mockAgent = new MockAgent({ |
18 |
| - keepAliveTimeout: 10, |
19 |
| - keepAliveMaxTimeout: 10, |
20 |
| -}); |
| 12 | +export const initializeTestDispatcher = async ( |
| 13 | + options: InitializeOptions = {}, |
| 14 | +): Promise<Interceptable> => { |
| 15 | + const { url = "http://localhost", timeout } = options; |
21 | 16 |
|
22 |
| -export const mockPool: Interceptable = mockAgent.get("http://localhost:3000"); |
| 17 | + const mockAgent = await getTestDispatcher({ timeout }); |
| 18 | + const interceptor = mockAgent.get(url); |
23 | 19 |
|
24 |
| -export const setupRequestMocking: () => void = () => { |
25 | 20 | before(() => {
|
26 | 21 | mockAgent.disableNetConnect();
|
27 | 22 | });
|
28 | 23 |
|
29 | 24 | after(() => {
|
30 | 25 | mockAgent.enableNetConnect();
|
31 | 26 | });
|
| 27 | + |
| 28 | + return interceptor; |
32 | 29 | };
|
0 commit comments