import { NitroTestOptions } from "./types.mjs"; import { FetchHooks, FetchResponse } from "ofetch"; import { $Fetch, ExtractedRouteMethod, Nitro, NitroFetchOptions, NitroFetchRequest, TypedInternalResponse } from "nitro/types"; //#region src/e2e.d.ts interface NitroSession { $fetch: $Fetch; cookies: Map; clearCookies: () => void; } interface NitroFetchResponse extends FetchResponse { /** Alias for `response._data` */ data?: T; } interface NitroRouteInfo { /** HTTP pathname pattern (e.g. `/api/users`, `/api/users/:id`). */ route: string; /** HTTP method, or `undefined` when the handler matches any method. */ method?: string; } /** * Creates a custom `ofetch` instance that dispatches requests in-process against the * active Nitro test app. Each call builds a Web `Request` and hands it to * `injectNitroFetch()`, so no HTTP listener is involved. * * @remarks * The following fetch defaults differ from `ofetch`: * - `ignoreResponseError: true` to prevent throwing on non-2xx responses. * - `redirect: 'manual'` to prevent automatic redirects. * - `retry: 0` to disable retries, preventing masked failures and slow test suites. * - `headers: { accept: 'application/json' }` to force a JSON error body when Nitro errors. */ declare function createNitroFetch(options?: FetchHooks): $Fetch; /** * Fetches the raw response from the Nitro server for the given path. * * Route-level typing is inherited automatically from Nitro's `InternalApi` augmentation * when your tsconfig extends `nitro/tsconfig`. See the README for setup instructions. * * @remarks * Applies the fetch defaults from {@link createNitroFetch}. */ declare function $fetchRaw = NitroFetchOptions>(request: R, options?: O): Promise extends O ? "get" : ExtractedRouteMethod>>>; /** * Returns the raw in-process request dispatcher for the active Nitro test app. * * This is the low-level primitive that `createNitroFetch` builds on. Reach for it when * you want to construct a `Request` yourself, or when you need to hand the dispatcher to * a different layer (for example `srvx.serve({ fetch: injectNitroFetch() })` to stand up * a real HTTP listener on top of the test app). * * @throws if called before `setup()` has started the app. */ declare function injectNitroFetch(): (request: Request) => Response | Promise; /** * Creates a session-aware `ofetch` instance that persists cookies across requests. */ declare function createNitroSession(): NitroSession; /** * Lists every route registered with the active Nitro test app, * excluding internal routes prefixed with `/_` or `/api/_`. * * @throws if called before `setup()` has started the app. */ declare function listRoutes(): NitroRouteInfo[]; /** * @internal */ declare function collectRoutes(nitro: Nitro): NitroRouteInfo[]; /** * Setup options for the Nitro test context. * * @example * import { resolve } from 'node:path' * import { setup } from 'nitro-test-utils' * * await setup({ * rootDir: resolve(import.meta.dirname, 'fixture'), * }) */ declare function setup(options?: NitroTestOptions): Promise; //#endregion export { $fetchRaw, NitroFetchResponse, NitroRouteInfo, NitroSession, collectRoutes, createNitroFetch, createNitroSession, injectNitroFetch, listRoutes, setup };