@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 43 lines 1.21 KB
Raw
1 /** Shared helpers for integration tests that hit the running dev/prod server. */
2
3 export const BASE_URL = process.env.TEST_BASE_URL || "http://localhost:3000";
4
5 /** Fetch a URL from the docs server with a timeout */
6 export async function fetchPage(
7 path: string,
8 options?: RequestInit & { timeout?: number }
9 ): Promise<Response> {
10 const { timeout = 10_000, ...fetchOpts } = options || {};
11 const controller = new AbortController();
12 const timer = setTimeout(() => controller.abort(), timeout);
13
14 try {
15 return await fetch(`${BASE_URL}${path}`, {
16 ...fetchOpts,
17 signal: controller.signal,
18 redirect: "follow",
19 });
20 } finally {
21 clearTimeout(timer);
22 }
23 }
24
25 /** Fetch without following redirects to inspect redirect behavior */
26 export async function fetchNoRedirect(
27 path: string,
28 options?: RequestInit & { timeout?: number }
29 ): Promise<Response> {
30 const { timeout = 10_000, ...fetchOpts } = options || {};
31 const controller = new AbortController();
32 const timer = setTimeout(() => controller.abort(), timeout);
33
34 try {
35 return await fetch(`${BASE_URL}${path}`, {
36 ...fetchOpts,
37 signal: controller.signal,
38 redirect: "manual",
39 });
40 } finally {
41 clearTimeout(timer);
42 }
43 }