39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { describe, expectTypeOf, it } from "@suaveplan/testing/runner";
|
|
import type { InferConfig, ServiceFixture } from "./service-fixture.js";
|
|
|
|
describe("ServiceFixture interface", () => {
|
|
it("enforces the ServiceFixture<TConfig> shape", { timeout: 5000 }, () => {
|
|
type ExampleConfig = { host: string; port: number };
|
|
const fixture: ServiceFixture<ExampleConfig> = {
|
|
name: "example",
|
|
start: async () => ({ host: "localhost", port: 1234 }),
|
|
stop: async () => {},
|
|
healthCheck: async () => true,
|
|
};
|
|
expectTypeOf(fixture.name).toEqualTypeOf<string>();
|
|
expectTypeOf(fixture.start).toEqualTypeOf<
|
|
() => Promise<ExampleConfig>
|
|
>();
|
|
expectTypeOf(fixture.stop).toEqualTypeOf<() => Promise<void>>();
|
|
expectTypeOf(fixture.healthCheck).toEqualTypeOf<
|
|
() => Promise<boolean>
|
|
>();
|
|
});
|
|
|
|
it("InferConfig extracts TConfig from a ServiceFixture implementation", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
type ExampleConfig = { endpoint: string; apiKey: string };
|
|
interface MyFixture extends ServiceFixture<ExampleConfig> {}
|
|
type Extracted = InferConfig<MyFixture>;
|
|
expectTypeOf<Extracted>().toEqualTypeOf<ExampleConfig>();
|
|
});
|
|
|
|
it("InferConfig returns never for non-ServiceFixture types", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
type Extracted = InferConfig<string>;
|
|
expectTypeOf<Extracted>().toEqualTypeOf<never>();
|
|
});
|
|
});
|