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

    Function describeService

    • Use this in conjunction with @augment-vir/test or the Node.js built-in test runner to run tests for a service and automatically kill the service when all tests have finished. The describe callback is passed a params object which includes a fetch function.

      See testService for more control over how tests are run (but without automatic server shutdown).

      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

      • __namedParameters: {
            options?: PartialWithUndefined<
                PartialWithUndefined<
                    {
                        debug: boolean;
                        host: string;
                        lockPort: boolean;
                        port: number;
                        preventWorkerRespawn: boolean;
                        workerCount: number;
                    },
                >,
            >;
            service: Readonly<Service>;
        }
        • Optionaloptions?: PartialWithUndefined<
              PartialWithUndefined<
                  {
                      debug: boolean;
                      host: string;
                      lockPort: boolean;
                      port: number;
                      preventWorkerRespawn: boolean;
                      workerCount: number;
                  },
              >,
          >

          Options for starting the service.

        • service: Readonly<Service>

          The service to startup and send requests to.

      • describeCallback: (
            params: {
                fetchEndpoint: FetchTestService<Service>;
                getServer: () => Promise<
                    Readonly<
                        FastifyInstance<
                            RawServerDefault,
                            IncomingMessage,
                            ServerResponse<IncomingMessage>,
                            FastifyBaseLogger,
                            FastifyTypeProviderDefault,
                        >,
                    >,
                >;
                service: Readonly<Service>;
            },
        ) => undefined
        | void

      Returns void

      import {describeService} from '@rest-vir/run-service';
      import {it} from '@augment-vir/test';

      describeService({service: myService}, ({fetchEndpoint}) => {
      it('responds', async () => {
      const response = await fetchEndpoint['/my-endpoint']();
      });
      });