@warp-drive/holodeck
Version:
⚡️ Simple, Fast HTTP Mocking for Tests
53 lines (52 loc) • 1.7 kB
TypeScript
import type { Handler, NextFn } from "@warp-drive/core/request";
import type { RequestContext, StructuredDataDocument } from "@warp-drive/core/types/request";
import type { Store } from "@warp-drive/legacy/store";
import type { ScaffoldGenerator } from "./mock.js";
/**
* @public
*/
export declare function setConfig({ host }: {
host: string;
}): void;
/**
* @public
*/
export declare function setTestId(context: object, str: string | null): void;
/**
* @public
*/
export declare function setIsRecording(value: boolean): void;
/**
* @public
*/
export declare function getIsRecording(): boolean;
/**
* A request handler that intercepts requests and routes them through
* the Holodeck mock server.
*
* This handler modifies the request URL to include test identifiers
* and manages request counts for accurate mocking.
*
* Requires that the test context be configured with a testId using `setTestId`.
*
* @param owner - the test context object used to retrieve the test ID.
*/
export declare class MockServerHandler implements Handler {
owner: object;
constructor(owner: object);
request<T>(context: RequestContext, next: NextFn<T>): Promise<StructuredDataDocument<T>>;
}
/**
* Creates an adapterFor function that wraps the provided adapterFor function
* to override the adapter's _fetchRequest method to route requests through
* the Holodeck mock server.
*
* @param owner - The test context object used to retrieve the test ID.
*/
export declare function installAdapterFor(owner: object, store: Store): void;
/**
* Mock a request by sending the scaffold to the mock server.
*
* @public
*/
export declare function mock(owner: object, generate: ScaffoldGenerator, isRecording?: boolean): Promise<void>;