UNPKG

test-fixture-factory

Version:

A minimal library for creating and managing test fixtures using Vitest, enabling structured, repeatable, and efficient testing processes.

30 lines (26 loc) 1.38 kB
type DestroyFn = () => Promise<void>; type VitestFixtureFn<Deps, Value> = (deps: Record<string, unknown> & Deps, use: (value: Value) => Promise<void>) => Promise<void>; type FactoryOutput<Value> = { value: Value; destroy?: DestroyFn; }; type FactoryInputFn<Deps, Attrs, Value> = (deps: Deps, attrs: Attrs) => Promise<FactoryOutput<Value>> | FactoryOutput<Value>; type FactoryOptions = { shouldDestroy?: boolean; }; type CreateFn<Attrs, Value> = (attrs: Attrs) => Promise<Value>; type Factory<Deps, Attrs, Value> = FactoryInputFn<Deps, Attrs, Value> & { useCreateFn: (options?: FactoryOptions) => VitestFixtureFn<Deps, CreateFn<Attrs, Value>>; useValueFn: (attrs: Attrs, options?: FactoryOptions) => VitestFixtureFn<Deps, Value>; }; type InferFixtureValue<T> = T extends () => VitestFixtureFn<infer Deps, infer Value> ? Value : never; declare const defineFactory: <Deps, Attrs, Value>(factoryFn: FactoryInputFn<Deps, Attrs, Value>) => Factory<Deps, Attrs, Value>; type UndefinedFieldErrorOptions = { factory: string; attribute: string; dependency: string; }; declare class UndefinedFieldError extends Error { constructor(options: UndefinedFieldErrorOptions); } export { type CreateFn, type DestroyFn, type Factory, type FactoryInputFn, type FactoryOptions, type InferFixtureValue, UndefinedFieldError, type VitestFixtureFn, defineFactory };