import type {Assertions} from './assertions.cjs'; import type {Subscribable} from './subscribable.cjs'; import type {TryFn} from './try-fn.cjs'; /** The `t` value passed to test & hook implementations. */ export type ExecutionContext = { /** Test context, shared with hooks. */ context: Context; /** Title of the test or hook. */ readonly title: string; /** Whether the test has passed. Only accurate in afterEach hooks. */ readonly passed: boolean; readonly log: LogFn; readonly plan: PlanFn; readonly teardown: TeardownFn; readonly timeout: TimeoutFn; readonly try: TryFn; } & Assertions; export type LogFn = { /** Log one or more values. */ (...values: any[]): void; /** Skip logging. */ skip(...values: any[]): void; }; export type PlanFn = { /** * Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the * number of planned assertions. See [assertion planning](https://github.com/avajs/ava#assertion-planning). */ (count: number): void; /** Don't plan assertions. */ skip(count: number): void; }; export type TimeoutFn = { /** * Set a timeout for the test, in milliseconds. The test will fail if the timeout is exceeded. * The timeout is reset each time an assertion is made. */ (ms: number, message?: string): void; /** Clear the timeout and restore the default behavior. */ clear(): void; }; /** Declare a function to be run after the test has ended. */ export type TeardownFn = (fn: (() => Promise) | (() => void)) => void; export type ImplementationFn = ((t: ExecutionContext, ...args: Args) => PromiseLike) | ((t: ExecutionContext, ...args: Args) => Subscribable) | ((t: ExecutionContext, ...args: Args) => void); export type TitleFn = (providedTitle: string | undefined, ...args: Args) => string; /** A reusable test or hook implementation. */ export type Macro = { /** The function that is executed when the macro is used. */ readonly exec: ImplementationFn; /** Generates a test title when this macro is used. */ readonly title?: TitleFn; }; /** A test or hook implementation. */ export type Implementation = ImplementationFn | Macro; export type TestFn = { /** Declare a concurrent test. Additional arguments are passed to the implementation or macro. */ (title: string, implementation: Implementation, ...args: Args): void; /** * Declare a concurrent test that uses a macro. Additional arguments are passed to the macro. * The macro is responsible for generating a unique test title. */ (macro: Macro, ...args: Args): void; after: AfterFn; afterEach: AfterFn; before: BeforeFn; beforeEach: BeforeFn; failing: FailingFn; macro: MacroFn; meta: Meta; only: OnlyFn; serial: SerialFn; skip: SkipFn; todo: TodoFn; }; export type AfterFn = { /** * Declare a hook that is run once, after all tests have passed. * Additional arguments are passed to the implementation or macro. */ (title: string, implementation: Implementation, ...args: Args): void; /** * Declare a hook that is run once, after all tests have passed. * Additional arguments are passed to the implementation or macro. */ (implementation: Implementation, ...args: Args): void; always: AlwaysInterface; skip: HookSkipFn; }; export type AlwaysInterface = { /** * Declare a hook that is run once, after all tests are done. * Additional arguments are passed to the implementation or macro. */ (title: string, implementation: Implementation, ...args: Args): void; /** * Declare a hook that is run once, after all tests are done. * Additional arguments are passed to the implementation or macro. */ (implementation: Implementation, ...args: Args): void; skip: HookSkipFn; }; export type BeforeFn = { /** * Declare a hook that is run once, before all tests. * Additional arguments are passed to the implementation or macro. */ (title: string, implementation: Implementation, ...args: Args): void; /** * Declare a hook that is run once, before all tests. * Additional arguments are passed to the implementation or macro. */ (implementation: Implementation, ...args: Args): void; skip: HookSkipFn; }; export type FailingFn = { /** * Declare a concurrent test that is expected to fail. * Additional arguments are passed to the implementation or macro. */ (title: string, implementation: Implementation, ...args: Args): void; /** * Declare a concurrent test, using a macro, that is expected to fail. * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title. */ (macro: Macro, ...args: Args): void; only: OnlyFn; skip: SkipFn; }; export type HookSkipFn = { /** Skip this hook. */ (title: string, implementation: Implementation, ...args: Args): void; /** Skip this hook. */ (implementation: Implementation, ...args: Args): void; }; export type OnlyFn = { /** * Declare a test. Only this test and others declared with `.only()` are run. * Additional arguments are passed to the implementation or macro. */ (title: string, implementation: Implementation, ...args: Args): void; /** * Declare a test that uses a macro. Only this test and others declared with `.only()` are run. * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title. */ (macro: Macro, ...args: Args): void; }; export type SerialFn = { /** Declare a serial test. Additional arguments are passed to the implementation or macro. */ (title: string, implementation: Implementation, ...args: Args): void; /** * Declare a serial test that uses a macro. The macro is responsible for generating a unique test title. */ (macro: Macro, ...args: Args): void; after: AfterFn; afterEach: AfterFn; before: BeforeFn; beforeEach: BeforeFn; failing: FailingFn; only: OnlyFn; skip: SkipFn; todo: TodoFn; }; export type SkipFn = { /** Skip this test. */ (title: string, implementation: Implementation, ...args: Args): void; /** Skip this test. */ (macro: Macro, ...args: Args): void; }; /** Declare a test that should be implemented later. */ export type TodoFn = (title: string) => void; export type MacroDeclarationOptions = { /** The function that is executed when the macro is used. */ exec: ImplementationFn; /** The function responsible for generating a unique title when the macro is used. */ title: TitleFn; }; export type MacroFn = { /** Declare a reusable test implementation. */ (/** The function that is executed when the macro is used. */ exec: ImplementationFn): Macro; (declaration: MacroDeclarationOptions): Macro; }; export type Meta = { /** Path to the test file being executed. */ file: string; /** Directory where snapshots are stored. */ snapshotDirectory: string; };