Connectum API Reference / @connectum/testing / index / withTestServer
Function: withTestServer()
withTestServer<
T>(options,testFn):Promise<T>
Defined in: test-server.ts:93
Run a test function with an auto-managed test server.
Creates a test server, passes it to testFn, and guarantees cleanup via finally — even if the test throws.
Type Parameters
T
T
Parameters
options
Server configuration (services, interceptors, protocols, port)
testFn
(server) => Promise<T>
Async function that receives the running test server
Returns
Promise<T>
The value returned by testFn
Example
typescript
const result = await withTestServer({ services: [myRoutes] }, async (server) => {
const client = createClient(MyService, server.transport);
return client.myMethod({ id: "1" });
});