rest-vir - v1.0.0
    Preparing search index...

    Function testService

    • Test your service with actual Request and Response objects! The returned object includes utilities for sending fetch requests and WebSocket connections to the service.

      Make sure to use the kill output after your tests are finished. To automatically kill the server, use describeService instead.

      By default, this uses Fastify's request injection strategy to avoid using up real system ports. To instead use an actual port, set port in the options parameter.

      Type Parameters

      • const Service extends Readonly<
            {
                createContext: undefined
                | ContextInit<any, any, any, any>;
                endpoints: Record<`/${string}`, any>;
                logger: ServiceLogger;
                postHook: undefined | PostHook;
                requiredClientOrigin: NonNullable<OriginRequirement>;
                serviceName: any;
                serviceOrigin: string;
                webSockets: Record<
                    `/${string}`,
                    ImplementedWebSocket<any, any, typeof NoParam>,
                >;
            },
        >

      Parameters

      • service: Readonly<Service>
      • testServiceOptions: Readonly<
            Omit<
                PartialWithUndefined<StartServiceUserOptions>,
                "workerCount" | "preventWorkerRespawn" | "",
            >,
        > = {}

      Returns Promise<
          {
              connectWebSocket: ConnectTestServiceWebSocket<Service>;
              fetchEndpoint: FetchTestService<Service>;
              server: Readonly<FastifyInstance>;
              kill(this: void): Promise<void>;
          },
      >

      import {testService} from '@rest-vir/run-service';

      const {connectWebsocket, kill, fetchEndpoint} = await testService(myServiceImplementation);

      // run tests

      await kill();