@opra/testing
Version:
Opra testing package
51 lines (50 loc) • 1.68 kB
TypeScript
import { IncomingMessage, Server, ServerResponse } from 'node:http';
import { FetchBackend, HttpResponse } from '@opra/client';
import { ApiExpect } from './api-expect/api-expect.js';
import type { OpraTestClient } from './test-client.js';
declare type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
export type ResponseExt = {
expect: ApiExpect;
};
/**
* Test specific implementation of {@link FetchBackend} for API testing.
*
* @class TestBackend
*/
export declare class TestBackend extends FetchBackend {
protected _server: Server;
/**
* Creates a new instance of TestBackend.
*
* @param app The server or request listener to test.
* @param options Configuration options.
*/
constructor(app: Server | RequestListener, options?: OpraTestClient.Options);
/**
* Sends the actual HTTP request by starting the server if necessary.
*
* @param req The request to send.
* @returns A promise that resolves to the response.
* @protected
*/
protected send(req: Request): Promise<Response>;
/**
* Creates a {@link HttpResponse} instance with an added `expect` property.
*
* @param init The response initiator parameters.
* @returns A new HttpResponse instance with ApiExpect.
* @protected
*/
protected createResponse(init: HttpResponse.Initiator): HttpResponse<any> & ResponseExt;
}
/**
* Namespace for {@link TestBackend} related types and interfaces.
*
* @namespace TestBackend
*/
export declare namespace TestBackend {
/** Configuration options for TestBackend */
interface Options extends FetchBackend.Options {
}
}
export {};