版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

356 líneas
17 KiB

  1. import { Test } from '@vitest/runner';
  2. export { SequenceHooks, SequenceSetupFiles, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
  3. import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, A as AfterSuiteRunMeta, U as UserConsoleLog, a as ResolvedConfig, b as ModuleGraphData, S as SnapshotResult, c as Reporter } from './types-94cfe4b4.js';
  4. export { A as AfterSuiteRunMeta, k as ApiConfig, H as ArgumentsType, G as Arrayable, D as Awaitable, a2 as BaseCoverageOptions, a9 as BenchFunction, a7 as Benchmark, B as BenchmarkAPI, a8 as BenchmarkResult, a6 as BenchmarkUserOptions, h as BuiltinEnvironment, j as CSSModuleScopeStrategy, C as CollectLineNumbers, e as CollectLines, L as Constructable, g as Context, q as ContextRPC, p as ContextTestEnvironment, a4 as CoverageC8Options, a3 as CoverageIstanbulOptions, a0 as CoverageOptions, Y as CoverageProvider, _ as CoverageProviderModule, $ as CoverageReporter, a5 as CustomProviderOptions, Q as Environment, E as EnvironmentOptions, P as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, O as ModuleCache, b as ModuleGraphData, K as MutableArray, N as Nullable, X as OnServerRestartHandler, d as RawErrsMap, Z as ReportContext, c as Reporter, y as ResolveIdFunction, a as ResolvedConfig, a1 as ResolvedCoverageOptions, f as RootAndTarget, R as RuntimeConfig, o as RuntimeRPC, s as SnapshotData, v as SnapshotMatchOptions, S as SnapshotResult, u as SnapshotStateOptions, x as SnapshotSummary, t as SnapshotUpdateState, T as TscErrorInfo, m as TypecheckConfig, w as UncheckedSnapshot, n as UserConfig, U as UserConsoleLog, r as Vitest, V as VitestEnvironment, i as VitestPool, l as VitestRunMode, W as WorkerContext, z as WorkerGlobalState } from './types-94cfe4b4.js';
  5. import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, EnhancedSpy } from '@vitest/spy';
  6. export { EnhancedSpy, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, SpyInstance } from '@vitest/spy';
  7. export { S as SnapshotEnvironment } from './env-afee91f0.js';
  8. import { File, TaskResultPack } from '@vitest/runner/types';
  9. export { DoneCallback, File, HookCleanupCallback, HookListener, OnTestFailedHandler, RunMode, RuntimeContext, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TestOptions } from '@vitest/runner/types';
  10. import { TransformResult } from 'vite';
  11. import * as chai from 'chai';
  12. export { chai };
  13. export { assert, should } from 'chai';
  14. export { ErrorWithDiff, ParsedStack } from '@vitest/runner/utils';
  15. export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
  16. import '@vitest/expect';
  17. import '@vitest/utils';
  18. import 'vite-node/client';
  19. import 'node:worker_threads';
  20. import 'vite-node';
  21. import 'source-map';
  22. import 'node:fs';
  23. import 'vite-node/server';
  24. declare type Not<T extends boolean> = T extends true ? false : true;
  25. declare type And<Types extends boolean[]> = Types[number] extends true ? true : false;
  26. declare type Eq<Left extends boolean, Right extends boolean> = Left extends true ? Right : Not<Right>;
  27. declare const secret: unique symbol;
  28. declare type Secret = typeof secret;
  29. declare type IsNever<T> = [T] extends [never] ? true : false;
  30. declare type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
  31. declare type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
  32. /**
  33. * Recursively walk a type and replace it with a branded type related to the original. This is useful for
  34. * equality-checking stricter than `A extends B ? B extends A ? true : false : false`, because it detects
  35. * the difference between a few edge-case types that vanilla typescript doesn't by default:
  36. * - `any` vs `unknown`
  37. * - `{ readonly a: string }` vs `{ a: string }`
  38. * - `{ a?: string }` vs `{ a: string | undefined }`
  39. */
  40. declare type DeepBrand<T> = IsNever<T> extends true ? {
  41. type: 'never';
  42. } : IsAny<T> extends true ? {
  43. type: 'any';
  44. } : IsUnknown<T> extends true ? {
  45. type: 'unknown';
  46. } : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
  47. type: 'primitive';
  48. value: T;
  49. } : T extends new (...args: any[]) => any ? {
  50. type: 'constructor';
  51. params: ConstructorParams<T>;
  52. instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
  53. } : T extends (...args: infer P) => infer R ? {
  54. type: 'function';
  55. params: DeepBrand<P>;
  56. return: DeepBrand<R>;
  57. } : T extends any[] ? {
  58. type: 'array';
  59. items: {
  60. [K in keyof T]: T[K];
  61. };
  62. } : {
  63. type: 'object';
  64. properties: {
  65. [K in keyof T]: DeepBrand<T[K]>;
  66. };
  67. readonly: ReadonlyKeys<T>;
  68. required: RequiredKeys<T>;
  69. optional: OptionalKeys<T>;
  70. constructorParams: DeepBrand<ConstructorParams<T>>;
  71. };
  72. declare type RequiredKeys<T> = Extract<{
  73. [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
  74. }[keyof T], keyof T>;
  75. declare type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
  76. declare type ReadonlyKeys<T> = Extract<{
  77. [K in keyof T]-?: ReadonlyEquivalent<{
  78. [_K in K]: T[K];
  79. }, {
  80. -readonly [_K in K]: T[K];
  81. }> extends true ? never : K;
  82. }[keyof T], keyof T>;
  83. declare type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
  84. declare type Extends<L, R> = IsNever<L> extends true ? IsNever<R> : [L] extends [R] ? true : false;
  85. declare type StrictExtends<L, R> = Extends<DeepBrand<L>, DeepBrand<R>>;
  86. declare type Equal<Left, Right> = And<[StrictExtends<Left, Right>, StrictExtends<Right, Left>]>;
  87. declare type Params<Actual> = Actual extends (...args: infer P) => any ? P : never;
  88. declare type ConstructorParams<Actual> = Actual extends new (...args: infer P) => any ? Actual extends new () => any ? P | [] : P : never;
  89. declare type MismatchArgs<B extends boolean, C extends boolean> = Eq<B, C> extends true ? [] : [never];
  90. interface ExpectTypeOf<Actual, B extends boolean> {
  91. toBeAny: (...MISMATCH: MismatchArgs<IsAny<Actual>, B>) => true;
  92. toBeUnknown: (...MISMATCH: MismatchArgs<IsUnknown<Actual>, B>) => true;
  93. toBeNever: (...MISMATCH: MismatchArgs<IsNever<Actual>, B>) => true;
  94. toBeFunction: (...MISMATCH: MismatchArgs<Extends<Actual, (...args: any[]) => any>, B>) => true;
  95. toBeObject: (...MISMATCH: MismatchArgs<Extends<Actual, object>, B>) => true;
  96. toBeArray: (...MISMATCH: MismatchArgs<Extends<Actual, any[]>, B>) => true;
  97. toBeNumber: (...MISMATCH: MismatchArgs<Extends<Actual, number>, B>) => true;
  98. toBeString: (...MISMATCH: MismatchArgs<Extends<Actual, string>, B>) => true;
  99. toBeBoolean: (...MISMATCH: MismatchArgs<Extends<Actual, boolean>, B>) => true;
  100. toBeVoid: (...MISMATCH: MismatchArgs<Extends<Actual, void>, B>) => true;
  101. toBeSymbol: (...MISMATCH: MismatchArgs<Extends<Actual, symbol>, B>) => true;
  102. toBeNull: (...MISMATCH: MismatchArgs<Extends<Actual, null>, B>) => true;
  103. toBeUndefined: (...MISMATCH: MismatchArgs<Extends<Actual, undefined>, B>) => true;
  104. toBeNullable: (...MISMATCH: MismatchArgs<Not<Equal<Actual, NonNullable<Actual>>>, B>) => true;
  105. toMatchTypeOf: {
  106. <Expected>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, B>): true;
  107. <Expected>(expected: Expected, ...MISMATCH: MismatchArgs<Extends<Actual, Expected>, B>): true;
  108. };
  109. toEqualTypeOf: {
  110. <Expected>(...MISMATCH: MismatchArgs<Equal<Actual, Expected>, B>): true;
  111. <Expected>(expected: Expected, ...MISMATCH: MismatchArgs<Equal<Actual, Expected>, B>): true;
  112. };
  113. toBeCallableWith: B extends true ? (...args: Params<Actual>) => true : never;
  114. toBeConstructibleWith: B extends true ? (...args: ConstructorParams<Actual>) => true : never;
  115. toHaveProperty: <K extends string>(key: K, ...MISMATCH: MismatchArgs<Extends<K, keyof Actual>, B>) => K extends keyof Actual ? ExpectTypeOf<Actual[K], B> : true;
  116. extract: <V>(v?: V) => ExpectTypeOf<Extract<Actual, V>, B>;
  117. exclude: <V>(v?: V) => ExpectTypeOf<Exclude<Actual, V>, B>;
  118. parameter: <K extends keyof Params<Actual>>(number: K) => ExpectTypeOf<Params<Actual>[K], B>;
  119. parameters: ExpectTypeOf<Params<Actual>, B>;
  120. constructorParameters: ExpectTypeOf<ConstructorParams<Actual>, B>;
  121. instance: Actual extends new (...args: any[]) => infer I ? ExpectTypeOf<I, B> : never;
  122. returns: Actual extends (...args: any[]) => infer R ? ExpectTypeOf<R, B> : never;
  123. resolves: Actual extends PromiseLike<infer R> ? ExpectTypeOf<R, B> : never;
  124. items: Actual extends ArrayLike<infer R> ? ExpectTypeOf<R, B> : never;
  125. guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf<T, B> : never;
  126. asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T ? unknown extends T ? never : ExpectTypeOf<T, B> : never;
  127. not: ExpectTypeOf<Actual, Not<B>>;
  128. }
  129. declare type _ExpectTypeOf = {
  130. <Actual>(actual: Actual): ExpectTypeOf<Actual, true>;
  131. <Actual>(): ExpectTypeOf<Actual, true>;
  132. };
  133. /**
  134. * Similar to Jest's `expect`, but with type-awareness.
  135. * Gives you access to a number of type-matchers that let you make assertions about the
  136. * form of a reference or generic type parameter.
  137. *
  138. * @example
  139. * import {foo, bar} from '../foo'
  140. * import {expectTypeOf} from 'expect-type'
  141. *
  142. * test('foo types', () => {
  143. * // make sure `foo` has type {a: number}
  144. * expectTypeOf(foo).toMatchTypeOf({a: 1})
  145. * expectTypeOf(foo).toHaveProperty('a').toBeNumber()
  146. *
  147. * // make sure `bar` is a function taking a string:
  148. * expectTypeOf(bar).parameter(0).toBeString()
  149. * expectTypeOf(bar).returns.not.toBeAny()
  150. * })
  151. *
  152. * @description
  153. * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
  154. */
  155. declare const expectTypeOf: _ExpectTypeOf;
  156. interface AssertType {
  157. <T>(value: T): void;
  158. }
  159. declare const assertType: AssertType;
  160. declare const bench: BenchmarkAPI;
  161. /**
  162. * This utils allows computational intensive tasks to only be ran once
  163. * across test reruns to improve the watch mode performance.
  164. *
  165. * Currently only works with `isolate: false`
  166. *
  167. * @experimental
  168. */
  169. declare function runOnce<T>(fn: (() => T), key?: string): T;
  170. /**
  171. * Get a boolean indicates whether the task is running in the first time.
  172. * Could only be `false` in watch mode.
  173. *
  174. * Currently only works with `isolate: false`
  175. *
  176. * @experimental
  177. */
  178. declare function isFirstRun(): boolean;
  179. declare function createExpect(test?: Test): Vi.ExpectStatic;
  180. declare const globalExpect: Vi.ExpectStatic;
  181. interface VitestUtils {
  182. useFakeTimers(config?: FakeTimerInstallOpts): this;
  183. useRealTimers(): this;
  184. runOnlyPendingTimers(): this;
  185. runOnlyPendingTimersAsync(): Promise<this>;
  186. runAllTimers(): this;
  187. runAllTimersAsync(): Promise<this>;
  188. runAllTicks(): this;
  189. advanceTimersByTime(ms: number): this;
  190. advanceTimersByTimeAsync(ms: number): Promise<this>;
  191. advanceTimersToNextTimer(): this;
  192. advanceTimersToNextTimerAsync(): Promise<this>;
  193. getTimerCount(): number;
  194. setSystemTime(time: number | string | Date): this;
  195. getMockedSystemTime(): Date | null;
  196. getRealSystemTime(): number;
  197. clearAllTimers(): this;
  198. spyOn: typeof spyOn;
  199. fn: typeof fn;
  200. /**
  201. * Makes all `imports` to passed module to be mocked.
  202. * - If there is a factory, will return it's result. The call to `vi.mock` is hoisted to the top of the file,
  203. * so you don't have access to variables declared in the global file scope, if you didn't put them before imports!
  204. * - If `__mocks__` folder with file of the same name exist, all imports will
  205. * return it.
  206. * - If there is no `__mocks__` folder or a file with the same name inside, will call original
  207. * module and mock it.
  208. * @param path Path to the module. Can be aliased, if your config supports it
  209. * @param factory Factory for the mocked module. Has the highest priority.
  210. */
  211. mock(path: string, factory?: MockFactoryWithHelper): void;
  212. /**
  213. * Removes module from mocked registry. All subsequent calls to import will
  214. * return original module even if it was mocked.
  215. * @param path Path to the module. Can be aliased, if your config supports it
  216. */
  217. unmock(path: string): void;
  218. doMock(path: string, factory?: () => any): void;
  219. doUnmock(path: string): void;
  220. /**
  221. * Imports module, bypassing all checks if it should be mocked.
  222. * Can be useful if you want to mock module partially.
  223. * @example
  224. * vi.mock('./example', async () => {
  225. * const axios = await vi.importActual('./example')
  226. *
  227. * return { ...axios, get: vi.fn() }
  228. * })
  229. * @param path Path to the module. Can be aliased, if your config supports it
  230. * @returns Actual module without spies
  231. */
  232. importActual<T = unknown>(path: string): Promise<T>;
  233. /**
  234. * Imports a module with all of its properties and nested properties mocked.
  235. * For the rules applied, see docs.
  236. * @param path Path to the module. Can be aliased, if your config supports it
  237. * @returns Fully mocked module
  238. */
  239. importMock<T>(path: string): Promise<MaybeMockedDeep<T>>;
  240. /**
  241. * Type helpers for TypeScript. In reality just returns the object that was passed.
  242. *
  243. * When `partial` is `true` it will expect a `Partial<T>` as a return value.
  244. * @example
  245. * import example from './example'
  246. * vi.mock('./example')
  247. *
  248. * test('1+1 equals 2' async () => {
  249. * vi.mocked(example.calc).mockRestore()
  250. *
  251. * const res = example.calc(1, '+', 1)
  252. *
  253. * expect(res).toBe(2)
  254. * })
  255. * @param item Anything that can be mocked
  256. * @param deep If the object is deeply mocked
  257. * @param options If the object is partially or deeply mocked
  258. */
  259. mocked<T>(item: T, deep?: false): MaybeMocked<T>;
  260. mocked<T>(item: T, deep: true): MaybeMockedDeep<T>;
  261. mocked<T>(item: T, options: {
  262. partial?: false;
  263. deep?: false;
  264. }): MaybeMocked<T>;
  265. mocked<T>(item: T, options: {
  266. partial?: false;
  267. deep: true;
  268. }): MaybeMockedDeep<T>;
  269. mocked<T>(item: T, options: {
  270. partial: true;
  271. deep?: false;
  272. }): MaybePartiallyMocked<T>;
  273. mocked<T>(item: T, options: {
  274. partial: true;
  275. deep: true;
  276. }): MaybePartiallyMockedDeep<T>;
  277. mocked<T>(item: T): MaybeMocked<T>;
  278. isMockFunction(fn: any): fn is EnhancedSpy;
  279. clearAllMocks(): this;
  280. resetAllMocks(): this;
  281. restoreAllMocks(): this;
  282. /**
  283. * Makes value available on global namespace.
  284. * Useful, if you want to have global variables available, like `IntersectionObserver`.
  285. * You can return it back to original value with `vi.unstubGlobals`, or by enabling `unstubGlobals` config option.
  286. */
  287. stubGlobal(name: string | symbol | number, value: unknown): this;
  288. /**
  289. * Changes the value of `import.meta.env` and `process.env`.
  290. * You can return it back to original value with `vi.unstubEnvs`, or by enabling `unstubEnvs` config option.
  291. */
  292. stubEnv(name: string, value: string): this;
  293. /**
  294. * Reset the value to original value that was available before first `vi.stubGlobal` was called.
  295. */
  296. unstubAllGlobals(): this;
  297. /**
  298. * Reset environmental variables to the ones that were available before first `vi.stubEnv` was called.
  299. */
  300. unstubAllEnvs(): this;
  301. resetModules(): this;
  302. /**
  303. * Wait for all imports to load. Useful, if you have a synchronous call that starts
  304. * importing a module that you cannot await otherwise.
  305. * Will also wait for new imports, started during the wait.
  306. */
  307. dynamicImportSettled(): Promise<void>;
  308. /**
  309. * Updates runtime config. You can only change values that are used when executing tests.
  310. */
  311. setConfig(config: RuntimeConfig): void;
  312. /**
  313. * If config was changed with `vi.setConfig`, this will reset it to the original state.
  314. */
  315. resetConfig(): void;
  316. }
  317. declare const vitest: VitestUtils;
  318. declare const vi: VitestUtils;
  319. declare function getRunningMode(): "run" | "watch";
  320. declare function isWatchMode(): boolean;
  321. interface TransformResultWithSource extends TransformResult {
  322. source?: string;
  323. }
  324. interface WebSocketHandlers {
  325. onCollected(files?: File[]): Promise<void>;
  326. onTaskUpdate(packs: TaskResultPack[]): void;
  327. onAfterSuiteRun(meta: AfterSuiteRunMeta): void;
  328. onDone(name: string): void;
  329. sendLog(log: UserConsoleLog): void;
  330. getFiles(): File[];
  331. getPaths(): string[];
  332. getConfig(): ResolvedConfig;
  333. resolveSnapshotPath(testPath: string): string;
  334. getModuleGraph(id: string): Promise<ModuleGraphData>;
  335. getTransformResult(id: string): Promise<TransformResultWithSource | undefined>;
  336. readFile(id: string): Promise<string | null>;
  337. writeFile(id: string, content: string): Promise<void>;
  338. removeFile(id: string): Promise<void>;
  339. createDirectory(id: string): Promise<string | undefined>;
  340. snapshotSaved(snapshot: SnapshotResult): void;
  341. rerun(files: string[]): Promise<void>;
  342. updateSnapshot(file?: File): Promise<void>;
  343. }
  344. interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' | 'onTaskUpdate' | 'onUserConsoleLog' | 'onPathsCollected'> {
  345. }
  346. export { AssertType, ExpectTypeOf, TransformResultWithSource, WebSocketEvents, WebSocketHandlers, assertType, bench, createExpect, globalExpect as expect, expectTypeOf, getRunningMode, isFirstRun, isWatchMode, runOnce, vi, vitest };