import { 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 ParsedStack { method: string; file: string; line: number; column: number; } interface ErrorWithDiff extends Error { name: string; nameStr?: string; stack?: string; stackStr?: string; stacks?: ParsedStack[]; showDiff?: boolean; actual?: any; expected?: any; operator?: string; type?: string; frame?: string; } declare function serializeError(val: any, seen?: WeakMap): any; interface ProcessErrorOptions { outputDiffMaxSize?: number; } declare function processError(err: any, options?: ProcessErrorOptions): any; declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet, expectedReplaced?: WeakSet): { replacedActual: any; replacedExpected: any; }; type RunMode = 'run' | 'skip' | 'only' | 'todo'; type TaskState = RunMode | 'pass' | 'fail'; interface TaskBase { id: string; name: string; mode: RunMode; concurrent?: boolean; shuffle?: boolean; suite?: Suite; file?: File; result?: TaskResult; retry?: number; meta?: any; } interface TaskCustom extends TaskBase { type: 'custom'; } interface TaskResult { state: TaskState; duration?: number; startTime?: number; heap?: number; /** * @deprecated Use "errors" instead */ error?: ErrorWithDiff; errors?: ErrorWithDiff[]; htmlError?: string; hooks?: Partial>; retryCount?: number; } type TaskResultPack = [id: string, result: TaskResult | undefined]; 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 TaskBase { type: 'test'; suite: Suite; result?: TaskResult; fails?: boolean; context: TestContext & ExtraContext; onFailed?: OnTestFailedHandler[]; } type Task = Test | Suite | TaskCustom | File; type DoneCallback = (error?: any) => void; type TestFunction = (context: TestContext & 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, fn: (...args: T) => Awaitable) => void; >(cases: ReadonlyArray): (name: string, fn: (...args: ExtractEachCallbackArgs) => Awaitable) => void; (cases: ReadonlyArray): (name: string, fn: (...args: T[]) => Awaitable) => void; } interface TestEachFunction { (cases: ReadonlyArray): (name: string, fn: (...args: T) => Awaitable, options?: number | TestOptions) => void; >(cases: ReadonlyArray): (name: string, fn: (...args: ExtractEachCallbackArgs) => Awaitable, options?: number | TestOptions) => void; (cases: ReadonlyArray): (name: string, fn: (...args: T[]) => Awaitable, options?: number | TestOptions) => void; (...args: [TemplateStringsArray, ...any]): (name: string, fn: (...args: any[]) => Awaitable, options?: number | TestOptions) => void; } type ChainableTestAPI = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [ name: string, fn?: TestFunction, options?: number | TestOptions ], void, { each: TestEachFunction; (name: string, 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 1 */ retry?: number; } type TestAPI = ChainableTestAPI & { each: TestEachFunction; skipIf(condition: any): ChainableTestAPI; runIf(condition: any): ChainableTestAPI; }; type ChainableSuiteAPI = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [ name: string, factory?: SuiteFactory, options?: number | TestOptions ], SuiteCollector, { each: TestEachFunction; (name: string, 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<[Suite | File], HookCleanupCallback>[]; afterAll: HookListener<[Suite | File]>[]; beforeEach: HookListener<[TestContext & ExtraContext, Suite], HookCleanupCallback>[]; afterEach: HookListener<[TestContext & ExtraContext, Suite]>[]; } interface SuiteCollector { readonly name: string; readonly mode: RunMode; type: 'collector'; test: TestAPI; tasks: (Suite | TaskCustom | Test | SuiteCollector)[]; custom: (name: string) => TaskCustom; collect: (file?: File) => Promise; clear: () => void; on: >(name: T, ...fn: SuiteHooks[T]) => void; } type SuiteFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable; interface RuntimeContext { tasks: (SuiteCollector | Test)[]; currentSuite: SuiteCollector | null; } interface TestContext { /** * Metadata of the current test */ meta: Readonly; /** * Extract hooks on test failed */ onTestFailed: (fn: OnTestFailedHandler) => void; } type OnTestFailedHandler = (result: TaskResult) => Awaitable; type SequenceHooks = 'stack' | 'list' | 'parallel'; type SequenceSetupFiles = 'list' | 'parallel'; export { ChainableFunction as C, DoneCallback as D, ErrorWithDiff as E, File as F, HookListener as H, OnTestFailedHandler as O, ParsedStack as P, RunMode as R, SuiteAPI as S, Task as T, TestAPI as a, SuiteCollector as b, SuiteHooks as c, TestContext as d, Suite as e, HookCleanupCallback as f, Test as g, TaskState as h, TaskBase as i, TaskCustom as j, TaskResult as k, TaskResultPack as l, TestFunction as m, TestOptions as n, SuiteFactory as o, RuntimeContext as p, SequenceHooks as q, SequenceSetupFiles as r, createChainable as s, serializeError as t, processError as u, replaceAsymmetricMatcher as v };