import { ErrorWithDiff, Awaitable } from '@vitest/utils'; type ChainableFunction = { (...args: Args): R; } & { [x in T]: ChainableFunction; } & { fn: (this: Record, ...args: Args) => R; } & E; declare function createChainable(keys: T[], fn: (this: Record, ...args: Args) => R): ChainableFunction; interface FixtureItem { prop: string; value: any; index: number; /** * Indicates whether the fixture is a function */ isFn: boolean; /** * The dependencies(fixtures) of current fixture function. */ deps?: FixtureItem[]; } type RunMode = 'run' | 'skip' | 'only' | 'todo'; type TaskState = RunMode | 'pass' | 'fail'; interface TaskBase { id: string; name: string; mode: RunMode; meta: TaskMeta; each?: boolean; concurrent?: boolean; shuffle?: boolean; suite?: Suite; file?: File; result?: TaskResult; retry?: number; repeats?: number; } interface TaskPopulated extends TaskBase { suite: Suite; pending?: boolean; result?: TaskResult; fails?: boolean; onFailed?: OnTestFailedHandler[]; /** * Store promises (from async expects) to wait for them before finishing the test */ promises?: Promise[]; } interface TaskMeta { } interface TaskResult { state: TaskState; duration?: number; startTime?: number; heap?: number; errors?: ErrorWithDiff[]; htmlError?: string; hooks?: Partial>; retryCount?: number; repeatCount?: number; } type TaskResultPack = [id: string, result: TaskResult | undefined, meta: TaskMeta]; interface Suite extends TaskBase { type: 'suite'; tasks: Task[]; filepath?: string; projectName: string; } interface File extends Suite { filepath: string; collectDuration?: number; setupDuration?: number; } interface Test extends TaskPopulated { type: 'test'; context: TaskContext & ExtraContext & TestContext; } interface Custom extends TaskPopulated { type: 'custom'; context: TaskContext & ExtraContext & TestContext; } type Task = Test | Suite | Custom | File; type DoneCallback = (error?: any) => void; type TestFunction = (context: ExtendedContext & ExtraContext) => Awaitable | void; type ExtractEachCallbackArgs> = { 1: [T[0]]; 2: [T[0], T[1]]; 3: [T[0], T[1], T[2]]; 4: [T[0], T[1], T[2], T[3]]; 5: [T[0], T[1], T[2], T[3], T[4]]; 6: [T[0], T[1], T[2], T[3], T[4], T[5]]; 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]]; 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]]; 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]]; 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]]; fallback: Array ? U : any>; }[T extends Readonly<[any]> ? 1 : T extends Readonly<[any, any]> ? 2 : T extends Readonly<[any, any, any]> ? 3 : T extends Readonly<[any, any, any, any]> ? 4 : T extends Readonly<[any, any, any, any, any]> ? 5 : T extends Readonly<[any, any, any, any, any, any]> ? 6 : T extends Readonly<[any, any, any, any, any, any, any]> ? 7 : T extends Readonly<[any, any, any, any, any, any, any, any]> ? 8 : T extends Readonly<[any, any, any, any, any, any, any, any, any]> ? 9 : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]> ? 10 : 'fallback']; interface SuiteEachFunction { (cases: ReadonlyArray): (name: string | Function, fn: (...args: T) => Awaitable) => void; >(cases: ReadonlyArray): (name: string | Function, fn: (...args: ExtractEachCallbackArgs) => Awaitable) => void; (cases: ReadonlyArray): (name: string | Function, fn: (...args: T[]) => Awaitable) => void; } interface TestEachFunction { (cases: ReadonlyArray): (name: string | Function, fn: (...args: T) => Awaitable, options?: number | TestOptions) => void; >(cases: ReadonlyArray): (name: string | Function, fn: (...args: ExtractEachCallbackArgs) => Awaitable, options?: number | TestOptions) => void; (cases: ReadonlyArray): (name: string | Function, fn: (...args: T[]) => Awaitable, options?: number | TestOptions) => void; (...args: [TemplateStringsArray, ...any]): (name: string | Function, fn: (...args: any[]) => Awaitable, options?: number | TestOptions) => void; } type ChainableTestAPI = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'fails', [ name: string | Function, fn?: TestFunction, options?: number | TestOptions ], void, { each: TestEachFunction; (name: string | Function, fn?: TestFunction, options?: number | TestOptions): void; }>; interface TestOptions { /** * Test timeout. */ timeout?: number; /** * Times to retry the test if fails. Useful for making flaky tests more stable. * When retries is up, the last test error will be thrown. * * @default 0 */ retry?: number; /** * How many times the test will run. * Only inner tests will repeat if set on `describe()`, nested `describe()` will inherit parent's repeat by default. * * @default 0 */ repeats?: number; /** * Whether tests run concurrently. * Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`. */ concurrent?: boolean; /** * Whether tests run sequentially. * Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`. */ sequential?: boolean; } interface ExtendedAPI { each: TestEachFunction; skipIf(condition: any): ChainableTestAPI; runIf(condition: any): ChainableTestAPI; } type CustomAPI = ChainableTestAPI & ExtendedAPI & { extend = {}>(fixtures: Fixtures): CustomAPI<{ [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never; }>; }; type TestAPI = ChainableTestAPI & ExtendedAPI & { extend = {}>(fixtures: Fixtures): TestAPI<{ [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never; }>; }; type Use = (value: T) => Promise; type FixtureFn = (context: Omit & ExtraContext, use: Use) => Promise; type Fixture = ((...args: any) => any) extends T[K] ? (T[K] extends any ? FixtureFn>> : never) : T[K] | (T[K] extends any ? FixtureFn>> : never); type Fixtures, ExtraContext = {}> = { [K in keyof T]: Fixture>; }; type InferFixturesTypes = T extends TestAPI ? C : T; type ChainableSuiteAPI = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', [ name: string | Function, factory?: SuiteFactory, options?: number | TestOptions ], SuiteCollector, { each: TestEachFunction; (name: string | Function, factory?: SuiteFactory): SuiteCollector; }>; type SuiteAPI = ChainableSuiteAPI & { each: SuiteEachFunction; skipIf(condition: any): ChainableSuiteAPI; runIf(condition: any): ChainableSuiteAPI; }; type HookListener = (...args: T) => Awaitable; type HookCleanupCallback = (() => Awaitable) | void; interface SuiteHooks { beforeAll: HookListener<[Readonly], HookCleanupCallback>[]; afterAll: HookListener<[Readonly]>[]; beforeEach: HookListener<[ExtendedContext & ExtraContext, Readonly], HookCleanupCallback>[]; afterEach: HookListener<[ExtendedContext & ExtraContext, Readonly]>[]; } interface TaskCustomOptions extends TestOptions { concurrent?: boolean; sequential?: boolean; skip?: boolean; only?: boolean; todo?: boolean; fails?: boolean; each?: boolean; meta?: Record; fixtures?: FixtureItem[]; handler?: (context: TaskContext) => Awaitable; } interface SuiteCollector { readonly name: string; readonly mode: RunMode; options?: TestOptions; type: 'collector'; test: TestAPI; tasks: (Suite | Custom | Test | SuiteCollector)[]; task: (name: string, options?: TaskCustomOptions) => Custom; collect: (file?: File) => Promise; clear: () => void; on: >(name: T, ...fn: SuiteHooks[T]) => void; } type SuiteFactory = (test: (name: string | Function, fn: TestFunction) => void) => Awaitable; interface RuntimeContext { tasks: (SuiteCollector | Test)[]; currentSuite: SuiteCollector | null; } interface TestContext { } interface TaskContext { /** * Metadata of the current test */ task: Readonly; /** * Extract hooks on test failed */ onTestFailed: (fn: OnTestFailedHandler) => void; /** * Mark tests as skipped. All execution after this call will be skipped. */ skip: () => void; } type ExtendedContext = TaskContext & TestContext; type OnTestFailedHandler = (result: TaskResult) => Awaitable; type SequenceHooks = 'stack' | 'list' | 'parallel'; type SequenceSetupFiles = 'list' | 'parallel'; export { type SequenceSetupFiles as A, type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type TaskState as i, type TaskBase as j, type TaskPopulated as k, type TaskMeta as l, type TaskResult as m, type TaskResultPack as n, type TestFunction as o, type TestOptions as p, type FixtureFn as q, type Fixture as r, type Fixtures as s, type HookCleanupCallback as t, type TaskCustomOptions as u, type SuiteFactory as v, type RuntimeContext as w, type TestContext as x, type TaskContext as y, type SequenceHooks as z };