import './chunks/vite.8fk186v-.js'; import { Plugin } from '@vitest/pretty-format'; import { SnapshotState } from '@vitest/snapshot'; export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotSerializer, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot'; import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect'; export { Assertion, AsymmetricMatchersContaining, ExpectPollOptions, ExpectStatic, JestAssertion } from '@vitest/expect'; import { e as VitestEnvironment$1, S as SerializedTestSpecification, f as RawErrsMap$1, T as TscErrorInfo$1, g as CollectLineNumbers$1, h as CollectLines$1, i as RootAndTarget$1, j as Context$1, C as CoverageProvider$1, k as ReportContext$1, a as CoverageProviderModule$1, l as CoverageReporter$1, m as CoverageProviderName, n as CoverageOptions$1, R as ResolvedCoverageOptions$1, B as BaseCoverageOptions$1, o as CoverageIstanbulOptions$1, b as CoverageV8Options$1, p as CustomProviderOptions$1, q as Reporter$1, V as Vitest$1, r as BrowserScript$1, s as BrowserConfigOptions$1, t as BuiltinEnvironment$1, P as Pool$1, u as PoolOptions$1, v as CSSModuleScopeStrategy$1, A as ApiConfig$1, w as VitestRunMode$1, D as DepsOptimizationOptions$1, x as TransformModePatterns$1, I as InlineConfig$1, y as TypecheckConfig$1, z as UserConfig$1, E as ResolvedConfig$1, F as ProjectConfig$1, U as UserWorkspaceConfig$1, G as BenchmarkUserOptions$1 } from './chunks/reporters.DAfKSDh5.js'; import { B as BenchmarkResult } from './chunks/benchmark.JVlTzojj.js'; export { b as BenchFunction, a as Benchmark, c as BenchmarkAPI } from './chunks/benchmark.JVlTzojj.js'; import { U as UserConsoleLog, P as ProvidedContext, M as ModuleGraphData, b as Awaitable$1, N as Nullable$1, c as Arrayable$1, d as ArgumentsType$1, e as MutableArray$1, C as Constructable$1, O as OnServerRestartHandler$1, a as EnvironmentReturn$1, V as VmEnvironmentReturn$1, E as Environment$1, R as ResolvedTestEnvironment$1, J as JSDOMOptions$1, H as HappyDOMOptions$1, f as EnvironmentOptions$1 } from './chunks/environment.CzISCQ7o.js'; export { A as AfterSuiteRunMeta, g as ModuleCache } from './chunks/environment.CzISCQ7o.js'; import { TaskPopulated, TaskResultPack, File as File$1, Suite as Suite$1, Test as Test$1, Custom as Custom$1, Task as Task$1, SequenceHooks as SequenceHooks$1, SequenceSetupFiles as SequenceSetupFiles$1 } from '@vitest/runner'; export { CancelReason, DoneCallback, ExtendedContext, HookCleanupCallback, HookListener, OnTestFailedHandler, RunMode, Custom as RunnerCustomCase, Task as RunnerTask, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, RuntimeContext, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, TaskBase, TaskContext, TaskCustomOptions, TaskMeta, TaskResult, TaskResultPack, TaskState, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner'; export { b as bench } from './chunks/suite.BMWOKiTe.js'; import { F as FakeTimerInstallOpts, R as RuntimeOptions, S as SerializedConfig } from './chunks/config.Crbj2GAb.js'; export { b as RuntimeConfig, a as SerializedCoverageConfig } from './chunks/config.Crbj2GAb.js'; import { M as MockFactoryWithHelper, a as MockOptions } from './chunks/mocker.cRtM890J.js'; import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy'; export { Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject } from '@vitest/spy'; import { a as BirpcReturn } from './chunks/worker.Chrs-_NL.js'; export { C as ContextRPC, e as ContextTestEnvironment, c as ResolveIdFunction, b as RunnerRPC, R as RuntimeRPC, W as WorkerGlobalState, d as WorkerRPC } from './chunks/worker.Chrs-_NL.js'; export { W as WorkerContext } from './chunks/worker.Qtv8v5nL.js'; export { ErrorWithDiff, ParsedStack, SerializedError, TestError } from '@vitest/utils'; export { DiffOptions } from '@vitest/utils/diff'; import * as chai from 'chai'; export { chai }; export { assert, should } from 'chai'; export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench'; import 'vite'; import 'vite-node'; import 'node:stream'; import 'vite-node/client'; import '@vitest/snapshot/manager'; import 'vite-node/server'; import '@vitest/utils/source-map'; import 'node:fs'; import '@vitest/runner/utils'; import '@vitest/snapshot/environment'; import '@vitest/mocker'; import 'node:worker_threads'; declare global { namespace Chai { interface Assertion { containSubset: (expected: any) => Assertion; } interface Assert { containSubset: (val: any, exp: any, msg?: string) => void; } } } interface SnapshotMatcher { (snapshot: Partial, message?: string): void; (message?: string): void; } interface InlineSnapshotMatcher { (properties: Partial, snapshot?: string, message?: string): void; (message?: string): void; } declare module '@vitest/expect' { interface MatcherState { environment: VitestEnvironment$1; snapshotState: SnapshotState; } interface ExpectPollOptions { interval?: number; timeout?: number; message?: string; } interface ExpectStatic { unreachable: (message?: string) => never; soft: (actual: T, message?: string) => Assertion; poll: (actual: () => T, options?: ExpectPollOptions) => PromisifyAssertion>; addEqualityTesters: (testers: Array) => void; assertions: (expected: number) => void; hasAssertions: () => void; addSnapshotSerializer: (plugin: Plugin) => void; } interface Assertion { matchSnapshot: SnapshotMatcher; toMatchSnapshot: SnapshotMatcher; toMatchInlineSnapshot: InlineSnapshotMatcher; toThrowErrorMatchingSnapshot: (message?: string) => void; toThrowErrorMatchingInlineSnapshot: (snapshot?: string, message?: string) => void; toMatchFileSnapshot: (filepath: string, message?: string) => Promise; } } declare module '@vitest/runner' { interface TestContext { expect: ExpectStatic; } interface TaskMeta { typecheck?: boolean; benchmark?: boolean; failScreenshotPath?: string; } interface File { prepareDuration?: number; environmentLoad?: number; } interface TaskBase { logs?: UserConsoleLog[]; } interface TaskResult { benchmark?: BenchmarkResult; } } /** * Negates a boolean type. */ declare type Not = T extends true ? false : true; /** * Checks if all the boolean types in the {@linkcode Types} array are `true`. */ declare type And = Types[number] extends true ? true : false; /** * Represents an equality type that returns {@linkcode Right} if * {@linkcode Left} is `true`, * otherwise returns the negation of {@linkcode Right}. */ declare type Eq = Left extends true ? Right : Not; declare const secret: unique symbol; declare type Secret = typeof secret; /** * Checks if the given type is `never`. */ declare type IsNever = [T] extends [never] ? true : false; /** * Checks if the given type is `any`. */ declare type IsAny = [T] extends [Secret] ? Not> : false; /** * Determines if the given type is `unknown`. */ declare type IsUnknown = [unknown] extends [T] ? Not> : false; /** * Determines the printable type representation for a given type. */ declare type PrintType = IsUnknown extends true ? 'unknown' : IsNever extends true ? 'never' : IsAny extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends (...args: any[]) => any ? 'function' : '...'; /** * Subjective "useful" keys from a type. For objects it's just `keyof` but for * tuples/arrays it's the number keys. * * @example * ```ts * UsefulKeys<{a: 1; b: 2}> // 'a' | 'b' * * UsefulKeys<['a', 'b']> // '0' | '1' * * UsefulKeys // number * ``` */ declare type UsefulKeys = T extends any[] ? { [K in keyof T]: K; }[number] : keyof T; declare type MismatchInfo = And<[Extends, '...'>, Not>]> extends true ? And<[Extends, Extends]> extends true ? Array[number], Extract[number]>> : { [K in UsefulKeys | UsefulKeys]: MismatchInfo; } : StrictEqualUsingBranding extends true ? Actual : `Expected: ${PrintType}, Actual: ${PrintType>}`; /** * Represents a deeply branded type. * * Recursively walk a type and replace it with a branded type related to the * original. This is useful for equality-checking stricter than * `A extends B ? B extends A ? true : false : false`, because it detects the * difference between a few edge-case types that vanilla typescript * doesn't by default: * - `any` vs `unknown` * - `{ readonly a: string }` vs `{ a: string }` * - `{ a?: string }` vs `{ a: string | undefined }` * * __Note__: not very performant for complex types - this should only be used * when you know you need it. If doing an equality check, it's almost always * better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}. */ declare type DeepBrand = IsNever extends true ? { type: 'never'; } : IsAny extends true ? { type: 'any'; } : IsUnknown extends true ? { type: 'unknown'; } : T extends string | number | boolean | symbol | bigint | null | undefined | void ? { type: 'primitive'; value: T; } : T extends new (...args: any[]) => any ? { type: 'constructor'; params: ConstructorParams; instance: DeepBrand any>>>; } : T extends (...args: infer P) => infer R ? { type: 'function'; params: DeepBrand

; return: DeepBrand; this: DeepBrand>; props: DeepBrand>; } : T extends any[] ? { type: 'array'; items: { [K in keyof T]: T[K]; }; } : { type: 'object'; properties: { [K in keyof T]: DeepBrand; }; readonly: ReadonlyKeys; required: RequiredKeys; optional: OptionalKeys; constructorParams: DeepBrand>; }; /** * Extracts the keys from a type that are required (not optional). */ declare type RequiredKeys = Extract<{ [K in keyof T]-?: {} extends Pick ? never : K; }[keyof T], keyof T>; /** * Gets the keys of an object type that are optional. */ declare type OptionalKeys = Exclude>; /** * Extracts the keys from a type that are not readonly. */ declare type ReadonlyKeys = Extract<{ [K in keyof T]-?: ReadonlyEquivalent<{ [_K in K]: T[K]; }, { -readonly [_K in K]: T[K]; }> extends true ? never : K; }[keyof T], keyof T>; /** * Determines if two types, are equivalent in a `readonly` manner. */ declare type ReadonlyEquivalent = Extends<(() => T extends X ? true : false), (() => T extends Y ? true : false)>; /** * Checks if one type extends another. */ declare type Extends = IsNever extends true ? IsNever : [L] extends [R] ? true : false; declare type ExtendsUsingBranding = Extends, DeepBrand>; declare type ExtendsExcludingAnyOrNever = IsAny extends true ? IsAny : Extends; /** * Checks if two types are strictly equal using * the TypeScript internal identical-to operator. * * @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 much history} */ declare type StrictEqualUsingTSInternalIdenticalToOperator = (() => T extends (L & T) | T ? true : false) extends () => T extends (R & T) | T ? true : false ? IsNever extends IsNever ? true : false : false; /** * Checks if two types are strictly equal using branding. */ declare type StrictEqualUsingBranding = And<[ ExtendsUsingBranding, ExtendsUsingBranding ]>; /** * Extracts the parameter types from a function type. */ declare type Params = Actual extends (...args: infer ParameterTypes) => any ? ParameterTypes : never; /** * Represents the constructor parameters of a class or constructor function. * If the constructor takes no arguments, an empty array is returned. */ declare type ConstructorParams = Actual extends new (...args: infer P) => any ? Actual extends new () => any ? P | [] : P : never; declare const mismatch: unique symbol; declare type Mismatch = { [mismatch]: 'mismatch'; }; /** * A type which should match anything passed as a value but *doesn't* * match {@linkcode Mismatch}. It helps TypeScript select the right overload * for {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`} and * {@linkcode PositiveExpectTypeOf.toMatchTypeOf `.toMatchTypeOf()`}. */ declare const avalue: unique symbol; /** * Represents a value that can be of various types. */ declare type AValue = { [avalue]?: undefined; } | string | number | boolean | symbol | bigint | null | undefined | void; /** * Represents the type of mismatched arguments between * the actual result and the expected result. * * If {@linkcode ActualResult} and {@linkcode ExpectedResult} are equivalent, * the type resolves to an empty tuple `[]`, indicating no mismatch. * If they are not equivalent, it resolves to a tuple containing the element * {@linkcode Mismatch}, signifying a discrepancy between * the expected and actual results. */ declare type MismatchArgs = Eq extends true ? [] : [Mismatch]; declare const inverted: unique symbol; declare type Inverted = { [inverted]: T; }; declare const expectNull: unique symbol; declare type ExpectNull = { [expectNull]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectUndefined: unique symbol; declare type ExpectUndefined = { [expectUndefined]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectNumber: unique symbol; declare type ExpectNumber = { [expectNumber]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectString: unique symbol; declare type ExpectString = { [expectString]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectBoolean: unique symbol; declare type ExpectBoolean = { [expectBoolean]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectVoid: unique symbol; declare type ExpectVoid = { [expectVoid]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectFunction: unique symbol; declare type ExpectFunction = { [expectFunction]: T; result: ExtendsExcludingAnyOrNever any>; }; declare const expectObject: unique symbol; declare type ExpectObject = { [expectObject]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectArray: unique symbol; declare type ExpectArray = { [expectArray]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectSymbol: unique symbol; declare type ExpectSymbol = { [expectSymbol]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectAny: unique symbol; declare type ExpectAny = { [expectAny]: T; result: IsAny; }; declare const expectUnknown: unique symbol; declare type ExpectUnknown = { [expectUnknown]: T; result: IsUnknown; }; declare const expectNever: unique symbol; declare type ExpectNever = { [expectNever]: T; result: IsNever; }; declare const expectNullable: unique symbol; declare type ExpectNullable = { [expectNullable]: T; result: Not>>; }; /** * Represents a scolder function that checks if the result of an expecter * matches the specified options. */ declare type Scolder = Expecter['result'] extends Options['positive'] ? () => true : Options['positive'] extends true ? Expecter : Inverted; /** * Represents the positive assertion methods available for type checking in the * {@linkcode expectTypeOf()} utility. */ interface PositiveExpectTypeOf extends BaseExpectTypeOf { toEqualTypeOf: { /** * Uses TypeScript's internal technique to check for type "identicalness". * * It will check if the types are fully equal to each other. * It will not fail if two objects have different values, but the same type. * It will fail however if an object is missing a property. * * **_Unexpected failure_**? For a more permissive but less performant * check that accommodates for equivalent intersection types, * use {@linkcode branded `.branded.toEqualTypeOf()`}. * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>() * * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }) * * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }) * ``` * * @param value - The value to compare against the expected type. * @param MISMATCH - The mismatch arguments. * @returns `true`. */ extends true ? unknown : MismatchInfo>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`. ...MISMATCH: MismatchArgs, true>): true; /** * Uses TypeScript's internal technique to check for type "identicalness". * * It will check if the types are fully equal to each other. * It will not fail if two objects have different values, but the same type. * It will fail however if an object is missing a property. * * **_Unexpected failure_**? For a more permissive but less performant * check that accommodates for equivalent intersection types, * use {@linkcode branded `.branded.toEqualTypeOf()`}. * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>() * * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }) * * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }) * ``` * * @param MISMATCH - The mismatch arguments. * @returns `true`. */ extends true ? unknown : MismatchInfo>(...MISMATCH: MismatchArgs, true>): true; }; toMatchTypeOf: { /** * A less strict version of {@linkcode toEqualTypeOf `.toEqualTypeOf()`} * that allows for extra properties. * This is roughly equivalent to an `extends` constraint * in a function type argument. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 }) * ``` * * @param value - The value to compare against the expected type. * @param MISMATCH - The mismatch arguments. * @returns `true`. */ extends true ? unknown : MismatchInfo>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`. ...MISMATCH: MismatchArgs, true>): true; /** * A less strict version of {@linkcode toEqualTypeOf `.toEqualTypeOf()`} * that allows for extra properties. * This is roughly equivalent to an `extends` constraint * in a function type argument. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 }) * ``` * * @param MISMATCH - The mismatch arguments. * @returns `true`. */ extends true ? unknown : MismatchInfo>(...MISMATCH: MismatchArgs, true>): true; }; /** * Checks whether an object has a given property. * * @example * check that properties exist * ```ts * const obj = {a: 1, b: ''} * * expectTypeOf(obj).toHaveProperty('a') * * expectTypeOf(obj).not.toHaveProperty('c') * ``` * * @param key - The property key to check for. * @param MISMATCH - The mismatch arguments. * @returns `true`. */ toHaveProperty: (key: KeyType, ...MISMATCH: MismatchArgs, true>) => KeyType extends keyof Actual ? PositiveExpectTypeOf : true; /** * Inverts the result of the following assertions. * * @example * ```ts * expectTypeOf({ a: 1 }).not.toMatchTypeOf({ b: 1 }) * ``` */ not: NegativeExpectTypeOf; /** * Intersection types can cause issues with * {@linkcode toEqualTypeOf `.toEqualTypeOf()`}: * ```ts * // ❌ The following line doesn't compile, even though the types are arguably the same. * expectTypeOf<{ a: 1 } & { b: 2 }>().toEqualTypeOf<{ a: 1; b: 2 }>() * ``` * This helper works around this problem by using * a more permissive but less performant check. * * __Note__: This comes at a performance cost, and can cause the compiler * to 'give up' if used with excessively deep types, so use sparingly. * * @see {@link https://github.com/mmkal/expect-type/pull/21 Reference} */ branded: { /** * Uses TypeScript's internal technique to check for type "identicalness". * * It will check if the types are fully equal to each other. * It will not fail if two objects have different values, but the same type. * It will fail however if an object is missing a property. * * **_Unexpected failure_**? For a more permissive but less performant * check that accommodates for equivalent intersection types, * use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}. * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>() * * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }) * * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }) * ``` * * @param MISMATCH - The mismatch arguments. * @returns `true`. */ toEqualTypeOf: extends true ? unknown : MismatchInfo>(...MISMATCH: MismatchArgs, true>) => true; }; } /** * Represents the negative expectation type for the {@linkcode Actual} type. */ interface NegativeExpectTypeOf extends BaseExpectTypeOf { toEqualTypeOf: { /** * Uses TypeScript's internal technique to check for type "identicalness". * * It will check if the types are fully equal to each other. * It will not fail if two objects have different values, but the same type. * It will fail however if an object is missing a property. * * **_Unexpected failure_**? For a more permissive but less performant * check that accommodates for equivalent intersection types, * use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}. * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>() * * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }) * * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }) * ``` * * @param value - The value to compare against the expected type. * @param MISMATCH - The mismatch arguments. * @returns `true`. */ (value: Expected & AValue, ...MISMATCH: MismatchArgs, false>): true; /** * Uses TypeScript's internal technique to check for type "identicalness". * * It will check if the types are fully equal to each other. * It will not fail if two objects have different values, but the same type. * It will fail however if an object is missing a property. * * **_Unexpected failure_**? For a more permissive but less performant * check that accommodates for equivalent intersection types, * use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}. * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>() * * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }) * * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }) * ``` * * @param MISMATCH - The mismatch arguments. * @returns `true`. */ (...MISMATCH: MismatchArgs, false>): true; }; toMatchTypeOf: { /** * A less strict version of * {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`} * that allows for extra properties. * This is roughly equivalent to an `extends` constraint * in a function type argument. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 }) * ``` * * @param value - The value to compare against the expected type. * @param MISMATCH - The mismatch arguments. * @returns `true`. */ (value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`. ...MISMATCH: MismatchArgs, false>): true; /** * A less strict version of * {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`} * that allows for extra properties. * This is roughly equivalent to an `extends` constraint * in a function type argument. * * @example * Using generic type argument syntax * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>() * ``` * * @example * Using inferred type syntax by passing a value * ```ts * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 }) * ``` * * @param MISMATCH - The mismatch arguments. * @returns `true`. */ (...MISMATCH: MismatchArgs, false>): true; }; /** * Checks whether an object has a given property. * * @example * check that properties exist * ```ts * const obj = {a: 1, b: ''} * * expectTypeOf(obj).toHaveProperty('a') * * expectTypeOf(obj).not.toHaveProperty('c') * ``` * * @param key - The property key to check for. * @param MISMATCH - The mismatch arguments. * @returns `true`. */ toHaveProperty: (key: KeyType, ...MISMATCH: MismatchArgs, false>) => true; } /** * Represents a conditional type that selects either * {@linkcode PositiveExpectTypeOf} or {@linkcode NegativeExpectTypeOf} based * on the value of the `positive` property in the {@linkcode Options} type. */ declare type ExpectTypeOf = Options['positive'] extends true ? PositiveExpectTypeOf : NegativeExpectTypeOf; /** * Represents the base interface for the * {@linkcode expectTypeOf()} function. * Provides a set of assertion methods to perform type checks on a value. */ interface BaseExpectTypeOf { /** * Checks whether the type of the value is `any`. */ toBeAny: Scolder, Options>; /** * Checks whether the type of the value is `unknown`. */ toBeUnknown: Scolder, Options>; /** * Checks whether the type of the value is `never`. */ toBeNever: Scolder, Options>; /** * Checks whether the type of the value is `function`. */ toBeFunction: Scolder, Options>; /** * Checks whether the type of the value is `object`. */ toBeObject: Scolder, Options>; /** * Checks whether the type of the value is an {@linkcode Array}. */ toBeArray: Scolder, Options>; /** * Checks whether the type of the value is `number`. */ toBeNumber: Scolder, Options>; /** * Checks whether the type of the value is `string`. */ toBeString: Scolder, Options>; /** * Checks whether the type of the value is `boolean`. */ toBeBoolean: Scolder, Options>; /** * Checks whether the type of the value is `void`. */ toBeVoid: Scolder, Options>; /** * Checks whether the type of the value is `symbol`. */ toBeSymbol: Scolder, Options>; /** * Checks whether the type of the value is `null`. */ toBeNull: Scolder, Options>; /** * Checks whether the type of the value is `undefined`. */ toBeUndefined: Scolder, Options>; /** * Checks whether the type of the value is `null` or `undefined`. */ toBeNullable: Scolder, Options>; /** * Checks whether a function is callable with the given parameters. * * __Note__: You cannot negate this assertion with * {@linkcode PositiveExpectTypeOf.not `.not`} you need to use * `ts-expect-error` instead. * * @example * ```ts * const f = (a: number) => [a, a] * * expectTypeOf(f).toBeCallableWith(1) * ``` * * __Known Limitation__: This assertion will likely fail if you try to use it * with a generic function or an overload. * @see {@link https://github.com/mmkal/expect-type/issues/50 This issue} for an example and a workaround. * * @param args - The arguments to check for callability. * @returns `true`. */ toBeCallableWith: Options['positive'] extends true ? (...args: Params) => true : never; /** * Checks whether a class is constructible with the given parameters. * * @example * ```ts * expectTypeOf(Date).toBeConstructibleWith('1970') * * expectTypeOf(Date).toBeConstructibleWith(0) * * expectTypeOf(Date).toBeConstructibleWith(new Date()) * * expectTypeOf(Date).toBeConstructibleWith() * ``` * * @param args - The arguments to check for constructibility. * @returns `true`. */ toBeConstructibleWith: Options['positive'] extends true ? (...args: ConstructorParams) => true : never; /** * Equivalent to the {@linkcode Extract} utility type. * Helps narrow down complex union types. * * @example * ```ts * type ResponsiveProp = T | T[] | { xs?: T; sm?: T; md?: T } * * interface CSSProperties { * margin?: string * padding?: string * } * * function getResponsiveProp(_props: T): ResponsiveProp { * return {} * } * * const cssProperties: CSSProperties = { margin: '1px', padding: '2px' } * * expectTypeOf(getResponsiveProp(cssProperties)) * .extract<{ xs?: any }>() // extracts the last type from a union * .toEqualTypeOf<{ * xs?: CSSProperties * sm?: CSSProperties * md?: CSSProperties * }>() * * expectTypeOf(getResponsiveProp(cssProperties)) * .extract() // extracts an array from a union * .toEqualTypeOf() * ``` * * __Note__: If no type is found in the union, it will return `never`. * * @param v - The type to extract from the union. * @returns The type after extracting the type from the union. */ extract: (v?: V) => ExpectTypeOf, Options>; /** * Equivalent to the {@linkcode Exclude} utility type. * Removes types from a union. * * @example * ```ts * type ResponsiveProp = T | T[] | { xs?: T; sm?: T; md?: T } * * interface CSSProperties { * margin?: string * padding?: string * } * * function getResponsiveProp(_props: T): ResponsiveProp { * return {} * } * * const cssProperties: CSSProperties = { margin: '1px', padding: '2px' } * * expectTypeOf(getResponsiveProp(cssProperties)) * .exclude() * .exclude<{ xs?: unknown }>() // or just `.exclude()` * .toEqualTypeOf() * ``` */ exclude: (v?: V) => ExpectTypeOf, Options>; /** * Equivalent to the {@linkcode Pick} utility type. * Helps select a subset of properties from an object type. * * @example * ```ts * interface Person { * name: string * age: number * } * * expectTypeOf() * .pick<'name'>() * .toEqualTypeOf<{ name: string }>() * ``` * * @param keyToPick - The property key to pick. * @returns The type after picking the property. */ pick: (keyToPick?: KeyToPick) => ExpectTypeOf, Options>; /** * Equivalent to the {@linkcode Omit} utility type. * Helps remove a subset of properties from an object type. * * @example * ```ts * interface Person { * name: string * age: number * } * * expectTypeOf().omit<'name'>().toEqualTypeOf<{ age: number }>() * ``` * * @param keyToOmit - The property key to omit. * @returns The type after omitting the property. */ omit: )>(keyToOmit?: KeyToOmit) => ExpectTypeOf, Options>; /** * Extracts a certain function argument with `.parameter(number)` call to * perform other assertions on it. * * @example * ```ts * function foo(a: number, b: string) { * return [a, b] * } * * expectTypeOf(foo).parameter(0).toBeNumber() * * expectTypeOf(foo).parameter(1).toBeString() * ``` * * @param index - The index of the parameter to extract. * @returns The extracted parameter type. */ parameter: >(index: Index) => ExpectTypeOf[Index], Options>; /** * Equivalent to the {@linkcode Parameters} utility type. * Extracts function parameters to perform assertions on its value. * Parameters are returned as an array. * * @example * ```ts * function noParam() {} * * function hasParam(s: string) {} * * expectTypeOf(noParam).parameters.toEqualTypeOf<[]>() * * expectTypeOf(hasParam).parameters.toEqualTypeOf<[string]>() * ``` */ parameters: ExpectTypeOf, Options>; /** * Equivalent to the {@linkcode ConstructorParameters} utility type. * Extracts constructor parameters as an array of values and * perform assertions on them with this method. * * @example * ```ts * expectTypeOf(Date).constructorParameters.toEqualTypeOf< * [] | [string | number | Date] * >() * ``` */ constructorParameters: ExpectTypeOf, Options>; /** * Equivalent to the {@linkcode ThisParameterType} utility type. * Extracts the `this` parameter of a function to * perform assertions on its value. * * @example * ```ts * function greet(this: { name: string }, message: string) { * return `Hello ${this.name}, here's your message: ${message}` * } * * expectTypeOf(greet).thisParameter.toEqualTypeOf<{ name: string }>() * ``` */ thisParameter: ExpectTypeOf, Options>; /** * Equivalent to the {@linkcode InstanceType} utility type. * Extracts the instance type of a class to perform assertions on. * * @example * ```ts * expectTypeOf(Date).instance.toHaveProperty('toISOString') * ``` */ instance: Actual extends new (...args: any[]) => infer I ? ExpectTypeOf : never; /** * Equivalent to the {@linkcode ReturnType} utility type. * Extracts the return type of a function. * * @example * ```ts * expectTypeOf(() => {}).returns.toBeVoid() * * expectTypeOf((a: number) => [a, a]).returns.toEqualTypeOf([1, 2]) * ``` */ returns: Actual extends (...args: any[]) => infer R ? ExpectTypeOf : never; /** * Extracts resolved value of a Promise, * so you can perform other assertions on it. * * @example * ```ts * async function asyncFunc() { * return 123 * } * * expectTypeOf(asyncFunc).returns.resolves.toBeNumber() * * expectTypeOf(Promise.resolve('string')).resolves.toBeString() * ``` * * Type Equivalent: * ```ts * type Resolves = PromiseType extends PromiseLike * ? ResolvedType * : never * ``` */ resolves: Actual extends PromiseLike ? ExpectTypeOf : never; /** * Extracts array item type to perform assertions on. * * @example * ```ts * expectTypeOf([1, 2, 3]).items.toEqualTypeOf() * * expectTypeOf([1, 2, 3]).items.not.toEqualTypeOf() * ``` * * __Type Equivalent__: * ```ts * type Items = ArrayType extends ArrayLike * ? ItemType * : never * ``` */ items: Actual extends ArrayLike ? ExpectTypeOf : never; /** * Extracts the type guarded by a function to perform assertions on. * * @example * ```ts * function isString(v: any): v is string { * return typeof v === 'string' * } * * expectTypeOf(isString).guards.toBeString() * ``` */ guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf : never; /** * Extracts the type asserted by a function to perform assertions on. * * @example * ```ts * function assertNumber(v: any): asserts v is number { * if (typeof v !== 'number') * throw new TypeError('Nope !') * } * * expectTypeOf(assertNumber).asserts.toBeNumber() * ``` */ asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T ? unknown extends T ? never : ExpectTypeOf : never; } /** * Represents a function that allows asserting the expected type of a value. */ declare type _ExpectTypeOf = { /** * Asserts the expected type of a value. * * @param actual - The actual value being asserted. * @returns An object representing the expected type assertion. */ (actual: Actual): ExpectTypeOf; /** * Asserts the expected type of a value without providing an actual value. * * @returns An object representing the expected type assertion. */ (): ExpectTypeOf; }; /** * Similar to Jest's `expect`, but with type-awareness. * Gives you access to a number of type-matchers that let you make assertions about the * form of a reference or generic type parameter. * * @example * import {foo, bar} from '../foo' * import {expectTypeOf} from 'expect-type' * * test('foo types', () => { * // make sure `foo` has type {a: number} * expectTypeOf(foo).toMatchTypeOf({a: 1}) * expectTypeOf(foo).toHaveProperty('a').toBeNumber() * * // make sure `bar` is a function taking a string: * expectTypeOf(bar).parameter(0).toBeString() * expectTypeOf(bar).returns.not.toBeAny() * }) * * @description * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. */ declare const expectTypeOf: _ExpectTypeOf; interface AssertType { (value: T): void; } declare const assertType: AssertType; /** * This utils allows computational intensive tasks to only be ran once * across test reruns to improve the watch mode performance. * * Currently only works with `poolOptions..isolate: false` * * @experimental */ declare function runOnce(fn: () => T, key?: string): T; /** * Get a boolean indicates whether the task is running in the first time. * Could only be `false` in watch mode. * * Currently only works with `isolate: false` * * @experimental */ declare function isFirstRun(): boolean; declare function createExpect(test?: TaskPopulated): ExpectStatic; declare const globalExpect: ExpectStatic; type WaitForCallback = () => T | Promise; interface WaitForOptions { /** * @description Time in ms between each check callback * @default 50ms */ interval?: number; /** * @description Time in ms after which the throw a timeout error * @default 1000ms */ timeout?: number; } declare function waitFor(callback: WaitForCallback, options?: number | WaitForOptions): Promise; type WaitUntilCallback = () => T | Promise; interface WaitUntilOptions extends Pick { } type Truthy = T extends false | '' | 0 | null | undefined ? never : T; declare function waitUntil(callback: WaitUntilCallback, options?: number | WaitUntilOptions): Promise>; type ESModuleExports = Record; interface VitestUtils { /** * Checks if fake timers are enabled. */ isFakeTimers: () => boolean; /** * This method wraps all further calls to timers until [`vi.useRealTimers()`](https://vitest.dev/api/vi#vi-userealtimers) is called. */ useFakeTimers: (config?: FakeTimerInstallOpts) => VitestUtils; /** * Restores mocked timers to their original implementations. All timers that were scheduled before will be discarded. */ useRealTimers: () => VitestUtils; /** * This method will call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call. * It will not fire any timer that was initiated during its call. */ runOnlyPendingTimers: () => VitestUtils; /** * This method will asynchronously call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call, even asynchronous ones. * It will not fire any timer that was initiated during its call. */ runOnlyPendingTimersAsync: () => Promise; /** * This method will invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimers` will be fired. * If you have an infinite interval, it will throw after 10,000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)). */ runAllTimers: () => VitestUtils; /** * This method will asynchronously invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimersAsync` will be fired even asynchronous timers. * If you have an infinite interval, it will throw after 10 000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)). */ runAllTimersAsync: () => Promise; /** * Calls every microtask that was queued by `process.nextTick`. This will also run all microtasks scheduled by themselves. */ runAllTicks: () => VitestUtils; /** * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first. */ advanceTimersByTime: (ms: number) => VitestUtils; /** * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first. This will include and await asynchronously set timers. */ advanceTimersByTimeAsync: (ms: number) => Promise; /** * Will call next available timer. Useful to make assertions between each timer call. You can chain call it to manage timers by yourself. */ advanceTimersToNextTimer: () => VitestUtils; /** * Will call next available timer and wait until it's resolved if it was set asynchronously. Useful to make assertions between each timer call. */ advanceTimersToNextTimerAsync: () => Promise; /** * Similar to [`vi.advanceTimersByTime`](https://vitest.dev/api/vi#vi-advancetimersbytime), but will advance timers by the milliseconds needed to execute callbacks currently scheduled with `requestAnimationFrame`. */ advanceTimersToNextFrame: () => VitestUtils; /** * Get the number of waiting timers. */ getTimerCount: () => number; /** * If fake timers are enabled, this method simulates a user changing the system clock (will affect date related API like `hrtime`, `performance.now` or `new Date()`) - however, it will not fire any timers. * If fake timers are not enabled, this method will only mock `Date.*` and `new Date()` calls. */ setSystemTime: (time: number | string | Date) => VitestUtils; /** * Returns mocked current date that was set using `setSystemTime`. If date is not mocked the method will return `null`. */ getMockedSystemTime: () => Date | null; /** * When using `vi.useFakeTimers`, `Date.now` calls are mocked. If you need to get real time in milliseconds, you can call this function. */ getRealSystemTime: () => number; /** * Removes all timers that are scheduled to run. These timers will never run in the future. */ clearAllTimers: () => VitestUtils; /** * Creates a spy on a method or getter/setter of an object similar to [`vi.fn()`](https://vitest.dev/api/vi#vi-fn). It returns a [mock function](https://vitest.dev/api/mock). * @example * ```ts * const cart = { * getApples: () => 42 * } * * const spy = vi.spyOn(cart, 'getApples').mockReturnValue(10) * * expect(cart.getApples()).toBe(10) * expect(spy).toHaveBeenCalled() * expect(spy).toHaveReturnedWith(10) * ``` */ spyOn: typeof spyOn; /** * Creates a spy on a function, though can be initiated without one. Every time a function is invoked, it stores its call arguments, returns, and instances. Also, you can manipulate its behavior with [methods](https://vitest.dev/api/mock). * * If no function is given, mock will return `undefined`, when invoked. * @example * ```ts * const getApples = vi.fn(() => 0) * * getApples() * * expect(getApples).toHaveBeenCalled() * expect(getApples).toHaveReturnedWith(0) * * getApples.mockReturnValueOnce(5) * * expect(getApples()).toBe(5) * expect(getApples).toHaveNthReturnedWith(2, 5) * ``` */ fn: typeof fn; /** * Wait for the callback to execute successfully. If the callback throws an error or returns a rejected promise it will continue to wait until it succeeds or times out. * * This is very useful when you need to wait for some asynchronous action to complete, for example, when you start a server and need to wait for it to start. * @example * ```ts * const server = createServer() * * await vi.waitFor( * () => { * if (!server.isReady) * throw new Error('Server not started') * * console.log('Server started') * }, { * timeout: 500, // default is 1000 * interval: 20, // default is 50 * } * ) * ``` */ waitFor: typeof waitFor; /** * This is similar to [`vi.waitFor`](https://vitest.dev/api/vi#vi-waitfor), but if the callback throws any errors, execution is immediately interrupted and an error message is received. * * If the callback returns a falsy value, the next check will continue until a truthy value is returned. This is useful when you need to wait for something to exist before taking the next step. * @example * ```ts * const element = await vi.waitUntil( * () => document.querySelector('.element'), * { * timeout: 500, // default is 1000 * interval: 20, // default is 50 * } * ) * * // do something with the element * expect(element.querySelector('.element-child')).toBeTruthy() * ``` */ waitUntil: typeof waitUntil; /** * Run the factory before imports are evaluated. You can return a value from the factory * to reuse it inside your [`vi.mock`](https://vitest.dev/api/vi#vi-mock) factory and tests. * * If used with [`vi.mock`](https://vitest.dev/api/vi#vi-mock), both will be hoisted in the order they are defined in. */ hoisted: (factory: () => T) => T; /** * Mocks every import call to the module even if it was already statically imported. * * The call to `vi.mock` is hoisted to the top of the file, so you don't have access to variables declared in the global file scope * unless they are defined with [`vi.hoisted`](https://vitest.dev/api/vi#vi-hoisted) before this call. * * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules). * @param path Path to the module. Can be aliased, if your Vitest config supports it * @param factory Mocked module factory. The result of this function will be an exports object */ mock(path: string, factory?: MockFactoryWithHelper | MockOptions): void; mock(module: Promise, factory?: MockFactoryWithHelper | MockOptions): void; /** * Removes module from mocked registry. All calls to import will return the original module even if it was mocked before. * * This call is hoisted to the top of the file, so it will only unmock modules that were defined in `setupFiles`, for example. * @param path Path to the module. Can be aliased, if your Vitest config supports it */ unmock(path: string): void; unmock(module: Promise): void; /** * Mocks every subsequent [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) call. * * Unlike [`vi.mock`](https://vitest.dev/api/vi#vi-mock), this method will not mock statically imported modules because it is not hoisted to the top of the file. * * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules). * @param path Path to the module. Can be aliased, if your Vitest config supports it * @param factory Mocked module factory. The result of this function will be an exports object */ doMock(path: string, factory?: MockFactoryWithHelper | MockOptions): void; doMock(module: Promise, factory?: MockFactoryWithHelper | MockOptions): void; /** * Removes module from mocked registry. All subsequent calls to import will return original module. * * Unlike [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock), this method is not hoisted to the top of the file. * @param path Path to the module. Can be aliased, if your Vitest config supports it */ doUnmock(path: string): void; doUnmock(module: Promise): void; /** * Imports module, bypassing all checks if it should be mocked. * Can be useful if you want to mock module partially. * @example * ```ts * vi.mock('./example.js', async () => { * const axios = await vi.importActual('./example.js') * * return { ...axios, get: vi.fn() } * }) * ``` * @param path Path to the module. Can be aliased, if your config supports it */ importActual: (path: string) => Promise; /** * Imports a module with all of its properties and nested properties mocked. * * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules). * @example * ```ts * const example = await vi.importMock('./example.js') * example.calc.mockReturnValue(10) * expect(example.calc()).toBe(10) * ``` * @param path Path to the module. Can be aliased, if your config supports it * @returns Fully mocked module */ importMock: (path: string) => Promise>; /** * Type helper for TypeScript. Just returns the object that was passed. * * When `partial` is `true` it will expect a `Partial` as a return value. By default, this will only make TypeScript believe that * the first level values are mocked. You can pass down `{ deep: true }` as a second argument to tell TypeScript that the whole object is mocked, if it actually is. * @example * ```ts * import example from './example.js' * vi.mock('./example.js') * * test('1 + 1 equals 10' async () => { * vi.mocked(example.calc).mockReturnValue(10) * expect(example.calc(1, '+', 1)).toBe(10) * }) * ``` * @param item Anything that can be mocked * @param deep If the object is deeply mocked * @param options If the object is partially or deeply mocked */ mocked: ((item: T, deep?: false) => MaybeMocked) & ((item: T, deep: true) => MaybeMockedDeep) & ((item: T, options: { partial?: false; deep?: false; }) => MaybeMocked) & ((item: T, options: { partial?: false; deep: true; }) => MaybeMockedDeep) & ((item: T, options: { partial: true; deep?: false; }) => MaybePartiallyMocked) & ((item: T, options: { partial: true; deep: true; }) => MaybePartiallyMockedDeep) & ((item: T) => MaybeMocked); /** * Checks that a given parameter is a mock function. If you are using TypeScript, it will also narrow down its type. */ isMockFunction: (fn: any) => fn is MockInstance; /** * Calls [`.mockClear()`](https://vitest.dev/api/mock#mockclear) on every mocked function. This will only empty `.mock` state, it will not reset implementation. * * It is useful if you need to clean up mock between different assertions. */ clearAllMocks: () => VitestUtils; /** * Calls [`.mockReset()`](https://vitest.dev/api/mock#mockreset) on every mocked function. This will empty `.mock` state, reset "once" implementations and force the base implementation to return `undefined` when invoked. * * This is useful when you want to completely reset a mock to the default state. */ resetAllMocks: () => VitestUtils; /** * Calls [`.mockRestore()`](https://vitest.dev/api/mock#mockrestore) on every mocked function. This will restore all original implementations. */ restoreAllMocks: () => VitestUtils; /** * Makes value available on global namespace. * Useful, if you want to have global variables available, like `IntersectionObserver`. * You can return it back to original value with `vi.unstubAllGlobals`, or by enabling `unstubGlobals` config option. */ stubGlobal: (name: string | symbol | number, value: unknown) => VitestUtils; /** * Changes the value of `import.meta.env` and `process.env`. * You can return it back to original value with `vi.unstubAllEnvs`, or by enabling `unstubEnvs` config option. */ stubEnv: (name: T, value: T extends 'PROD' | 'DEV' | 'SSR' ? boolean : string | undefined) => VitestUtils; /** * Reset the value to original value that was available before first `vi.stubGlobal` was called. */ unstubAllGlobals: () => VitestUtils; /** * Reset environmental variables to the ones that were available before first `vi.stubEnv` was called. */ unstubAllEnvs: () => VitestUtils; /** * Resets modules registry by clearing the cache of all modules. This allows modules to be reevaluated when reimported. * Top-level imports cannot be re-evaluated. Might be useful to isolate modules where local state conflicts between tests. * * This method does not reset mocks registry. To clear mocks registry, use [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock) or [`vi.doUnmock`](https://vitest.dev/api/vi#vi-dounmock). */ resetModules: () => VitestUtils; /** * Wait for all imports to load. Useful, if you have a synchronous call that starts * importing a module that you cannot await otherwise. * Will also wait for new imports, started during the wait. */ dynamicImportSettled: () => Promise; /** * Updates runtime config. You can only change values that are used when executing tests. */ setConfig: (config: RuntimeOptions) => void; /** * If config was changed with `vi.setConfig`, this will reset it to the original state. */ resetConfig: () => void; } declare const vitest: VitestUtils; declare const vi: VitestUtils; declare function getRunningMode(): "run" | "watch"; declare function isWatchMode(): boolean; /** * Gives access to injected context provided from the main thread. * This usually returns a value provided by `globalSetup` or an external library. */ declare function inject(key: T): ProvidedContext[T]; interface BrowserUI { setCurrentFileId: (fileId: string) => void; setIframeViewport: (width: number, height: number) => Promise; } interface SourceMap { file: string; mappings: string; names: string[]; sources: string[]; sourcesContent?: string[]; version: number; toString: () => string; toUrl: () => string; } interface TransformResultWithSource { code: string; map: SourceMap | { mappings: ''; } | null; etag?: string; deps?: string[]; dynamicDeps?: string[]; source?: string; } interface WebSocketHandlers { onTaskUpdate: (packs: TaskResultPack[]) => void; getFiles: () => File$1[]; getTestFiles: () => Promise; getPaths: () => string[]; getConfig: () => SerializedConfig; getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise; getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise; readTestFile: (id: string) => Promise; saveTestFile: (id: string, content: string) => Promise; rerun: (files: string[]) => Promise; updateSnapshot: (file?: File$1) => Promise; getUnhandledErrors: () => unknown[]; } interface WebSocketEvents { onCollected?: (files?: File$1[]) => Awaitable$1; onFinished?: (files: File$1[], errors: unknown[], coverage?: unknown) => Awaitable$1; onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable$1; onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1; onPathsCollected?: (paths?: string[]) => Awaitable$1; onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1; onFinishedReportCoverage: () => void; } type WebSocketRPC = BirpcReturn; /** @deprecated import `TypeCheckRawErrorsMap` from `vitest/node` instead */ type RawErrsMap = RawErrsMap$1; /** @deprecated import `TypeCheckErrorInfo` from `vitest/node` instead */ type TscErrorInfo = TscErrorInfo$1; /** @deprecated import `TypeCheckCollectLineNumbers` from `vitest/node` instead */ type CollectLineNumbers = CollectLineNumbers$1; /** @deprecated import `TypeCheckCollectLines` from `vitest/node` instead */ type CollectLines = CollectLines$1; /** @deprecated import `TypeCheckRootAndTarget` from `vitest/node` instead */ type RootAndTarget = RootAndTarget$1; /** @deprecated import `TypeCheckContext` from `vitest/node` instead */ type Context = Context$1; /** @deprecated use `RunnerTestSuite` instead */ type Suite = Suite$1; /** @deprecated use `RunnerTestFile` instead */ type File = File$1; /** @deprecated use `RunnerTestCase` instead */ type Test = Test$1; /** @deprecated use `RunnerCustomCase` instead */ type Custom = Custom$1; /** @deprecated use `RunnerTask` instead */ type Task = Task$1; /** @deprecated do not use, internal helper */ type Awaitable = Awaitable$1; /** @deprecated do not use, internal helper */ type Nullable = Nullable$1; /** @deprecated do not use, internal helper */ type Arrayable = Arrayable$1; /** @deprecated do not use, internal helper */ type ArgumentsType = ArgumentsType$1; /** @deprecated do not use, internal helper */ type MutableArray = MutableArray$1; /** @deprecated do not use, internal helper */ type Constructable = Constructable$1; /** @deprecated import from `vitest/node` instead */ type OnServerRestartHandler = OnServerRestartHandler$1; /** @deprecated import from `vitest/environments` instead */ type EnvironmentReturn = EnvironmentReturn$1; /** @deprecated import from `vitest/environments` instead */ type VmEnvironmentReturn = VmEnvironmentReturn$1; /** @deprecated import from `vitest/environments` instead */ type Environment = Environment$1; /** @deprecated do not use it */ type ResolvedTestEnvironment = ResolvedTestEnvironment$1; /** @deprecated import from `vitest/node` instead */ type CoverageProvider = CoverageProvider$1; /** @deprecated import from `vitest/node` instead */ type ReportContext = ReportContext$1; /** @deprecated import from `vitest/node` instead */ type CoverageProviderModule = CoverageProviderModule$1; /** @deprecated import from `vitest/node` instead */ type CoverageReporter = CoverageReporter$1; /** @deprecated import from `vitest/node` instead */ type CoverageOptions = CoverageOptions$1; /** @deprecated import from `vitest/node` instead */ type ResolvedCoverageOptions = ResolvedCoverageOptions$1; /** @deprecated import from `vitest/node` instead */ type BaseCoverageOptions = BaseCoverageOptions$1; /** @deprecated import from `vitest/node` instead */ type CoverageIstanbulOptions = CoverageIstanbulOptions$1; /** @deprecated import from `vitest/node` instead */ type CoverageV8Options = CoverageV8Options$1; /** @deprecated import from `vitest/node` instead */ type CustomProviderOptions = CustomProviderOptions$1; /** @deprecated import from `vitest/reporter` instead */ type Reporter = Reporter$1; /** @deprecated import from `vitest/node` instead */ type Vitest = Vitest$1; /** @deprecated import from `vitest/node` instead */ type BrowserScript = BrowserScript$1; /** @deprecated import from `vitest/node` instead */ type BrowserConfigOptions = BrowserConfigOptions$1; /** @deprecated import from `vitest/node` instead */ type SequenceHooks = SequenceHooks$1; /** @deprecated import from `vitest/node` instead */ type SequenceSetupFiles = SequenceSetupFiles$1; /** @deprecated import from `vitest/node` instead */ type BuiltinEnvironment = BuiltinEnvironment$1; /** @deprecated import from `vitest/node` instead */ type VitestEnvironment = VitestEnvironment$1; /** @deprecated import from `vitest/node` instead */ type Pool = Pool$1; /** @deprecated import from `vitest/node` instead */ type PoolOptions = PoolOptions$1; /** @deprecated import from `vitest/node` instead */ type CSSModuleScopeStrategy = CSSModuleScopeStrategy$1; /** @deprecated import from `vitest/node` instead */ type ApiConfig = ApiConfig$1; /** @deprecated import from `vitest/node` instead */ type JSDOMOptions = JSDOMOptions$1; /** @deprecated import from `vitest/node` instead */ type HappyDOMOptions = HappyDOMOptions$1; /** @deprecated import from `vitest/node` instead */ type EnvironmentOptions = EnvironmentOptions$1; /** @deprecated import from `vitest/node` instead */ type VitestRunMode = VitestRunMode$1; /** @deprecated import from `vitest/node` instead */ type DepsOptimizationOptions = DepsOptimizationOptions$1; /** @deprecated import from `vitest/node` instead */ type TransformModePatterns = TransformModePatterns$1; /** @deprecated import from `vitest/node` instead */ type InlineConfig = InlineConfig$1; /** @deprecated import from `vitest/node` instead */ type TypecheckConfig = TypecheckConfig$1; /** @deprecated import from `vitest/node` instead */ type UserConfig = UserConfig$1; /** @deprecated import from `vitest/node` instead */ type ResolvedConfig = ResolvedConfig$1; /** @deprecated import from `vitest/node` instead */ type ProjectConfig = ProjectConfig$1; /** @deprecated import from `vitest/node` instead */ type UserWorkspaceConfig = UserWorkspaceConfig$1; /** @deprecated use `SerializedTestSpecification` instead */ type SerializableSpec = SerializedTestSpecification; /** @deprecated import from `vitest/node` instead */ type BenchmarkUserOptions = BenchmarkUserOptions$1; export { type ApiConfig, type ArgumentsType, type Arrayable, type AssertType, type Awaitable, type BaseCoverageOptions, BenchmarkResult, type BenchmarkUserOptions, type BrowserConfigOptions, type BrowserScript, type BrowserUI, type BuiltinEnvironment, type CSSModuleScopeStrategy, type CollectLineNumbers, type CollectLines, type Constructable, type Context, type CoverageIstanbulOptions, type CoverageOptions, type CoverageProvider, type CoverageProviderModule, type CoverageReporter, type CoverageV8Options, type Custom, type CustomProviderOptions, type DepsOptimizationOptions, type Environment, type EnvironmentOptions, type EnvironmentReturn, type ExpectTypeOf, type File, type HappyDOMOptions, type InlineConfig, type JSDOMOptions, ModuleGraphData, type MutableArray, type Nullable, type OnServerRestartHandler, type Pool, type PoolOptions, type ProjectConfig, ProvidedContext, type RawErrsMap, type ReportContext, type Reporter, type ResolvedConfig, type ResolvedCoverageOptions, type ResolvedTestEnvironment, type RootAndTarget, type SequenceHooks, type SequenceSetupFiles, type SerializableSpec, SerializedConfig, SerializedTestSpecification, type Suite, type Task, type Test, type TransformModePatterns, type TransformResultWithSource, type TscErrorInfo, type TypecheckConfig, type UserConfig, UserConsoleLog, type UserWorkspaceConfig, type Vitest, type VitestEnvironment, type VitestRunMode, type VitestUtils, type VmEnvironmentReturn, type WebSocketEvents, type WebSocketHandlers, type WebSocketRPC, assertType, createExpect, globalExpect as expect, expectTypeOf, getRunningMode, inject, isFirstRun, isWatchMode, runOnce, vi, vitest };