import { HookNames } from './jest'; import { ContextBase, MergeC, NoContext, Setdown, Setup } from './types'; /** * @param contextNeeds The context that this provider needs. * @param kont This is just a superficial branding to prevent kont providers from being statically * accepted into inline hook positions. * * For example this should be a static type error: * * ``` * kont().beforeAll(someProvider()) * ``` * * Correct code is: * * ``` * kont().useBeforeAll(someProvider()) * ``` * @remarks The separation of provider from provider builder is an incidental complexity caused by this * TS issue: https://github.com/microsoft/TypeScript/issues/10717 * * We wish that we could only have builder and it would be called just "provider". * * The gist of the problem is that provider builder cannot give contravariance where we need it. * * We want a provider to declare its context needs which are contravariant to the context it is * inserted into. That is, the context that surrounds a provider should be a super-type * relationship. However the only way to achieve this is by having the generic passed down from * the kont context to a function parameter, which is not what provider builder is. Hence * separated provider and the .done() api to get to it from builder. */ export declare type Provider = (contextNeeds: Needs, kont: true) => Contributes; export declare type ProviderInternal = { use(params: { jestHookName: HookNames.Setup; currentContext: ContextBase; }): void; state: { name: string; setups: Setup[]; setdowns: Setdown[]; }; }; export declare type ProviderBuilder = NoContext extends Contributes ? { name(providerName: string): ProviderBuilderAfterName; before(setup: Setup): ProviderBuilderAfterBefore; after(setdown: Setdown): ProviderBuilderAfterAfter; done(): Provider; } : { name(providerName: string): ProviderBuilderAfterName; before(setup: Setup): ProviderBuilderAfterBefore; /** * Context contribution is expected so you cannot call `after` method before `before` method. * * @deprecated */ after(): never; /** * Context contribution is expected so you cannot call `done` method before `before` method. * * @deprecated */ done(): never; }; export declare type ProviderBuilderAfterName = { before(setup: Setup): ProviderBuilderAfterBefore>; after(setdown: Setdown): ProviderBuilderAfterAfter; done(): Provider; }; export declare type ProviderBuilderAfterBefore = { after(setdown: Setdown>): ProviderBuilderAfterAfter; done(): Provider; }; export declare type ProviderBuilderAfterAfter = { done(): Provider; }; export declare type ProviderBuilderInternal = Omit, 'done'> & { done(): ProviderInternal; }; /** * Create a "dynamic" provider. * * Providers can contribute test context and integrate with Jest before/after lifecycle hooks. * * Dynamic providers are providers that are agnostic to if they are used in beforeAll or beforeEach Jest hooks. Consumers decide. */ export declare const provider: () => ProviderBuilder; //# sourceMappingURL=provider.d.ts.map