vitest 0.20.2 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +29 -0
- package/dist/browser.d.ts +9 -1887
- package/dist/browser.mjs +7 -7
- package/dist/{chunk-api-setup.7c4c8879.mjs → chunk-api-setup.7a6ba7fb.mjs} +5 -5
- package/dist/{chunk-constants.16825f0c.mjs → chunk-constants.26dc9f85.mjs} +1 -1
- package/dist/{chunk-defaults.1c51d585.mjs → chunk-defaults.02abff90.mjs} +2 -2
- package/dist/{chunk-integrations-globals.56a11010.mjs → chunk-integrations-globals.44a8f047.mjs} +6 -6
- package/dist/{chunk-mock-date.9160e13b.mjs → chunk-mock-date.bc81a3ac.mjs} +11 -8
- package/dist/{chunk-node-git.43dbdd42.mjs → chunk-node-git.c2be9c49.mjs} +1 -1
- package/dist/{chunk-runtime-chain.b6c2cdbc.mjs → chunk-runtime-chain.98d42d89.mjs} +30 -21
- package/dist/{chunk-runtime-error.0aa0dc06.mjs → chunk-runtime-error.87a2b5a2.mjs} +12 -11
- package/dist/{chunk-runtime-hooks.3ee34848.mjs → chunk-runtime-hooks.453f8858.mjs} +4 -4
- package/dist/{chunk-runtime-mocker.0a8f7c5e.mjs → chunk-runtime-mocker.23b62bfa.mjs} +34 -12
- package/dist/{chunk-runtime-rpc.dbf0b31d.mjs → chunk-runtime-rpc.b50ab560.mjs} +1 -1
- package/dist/{chunk-utils-source-map.8198ebd9.mjs → chunk-utils-source-map.94107ee8.mjs} +1 -1
- package/dist/{chunk-vite-node-client.a247c2c2.mjs → chunk-vite-node-client.fdd9592c.mjs} +7 -3
- package/dist/{chunk-vite-node-debug.c5887932.mjs → chunk-vite-node-debug.09afb76f.mjs} +1 -1
- package/dist/{chunk-vite-node-externalize.45323563.mjs → chunk-vite-node-externalize.27aee038.mjs} +34 -18
- package/dist/chunk-vite-node-utils.f34df9d3.mjs +6887 -0
- package/dist/cli.mjs +8 -8
- package/dist/config.d.ts +2 -67
- package/dist/entry.mjs +7 -7
- package/dist/global-60f880c6.d.ts +1779 -0
- package/dist/index-4a906fa4.d.ts +164 -0
- package/dist/index.d.ts +29 -1903
- package/dist/index.mjs +5 -5
- package/dist/loader.mjs +73 -17
- package/dist/mocker-5e2a8e41.d.ts +3 -0
- package/dist/node.d.ts +7 -1667
- package/dist/node.mjs +9 -9
- package/dist/suite.mjs +4 -4
- package/dist/{vendor-index.de788b6a.mjs → vendor-index.ae96af6e.mjs} +14 -14
- package/dist/worker.mjs +6 -6
- package/package.json +11 -11
- package/dist/chunk-vite-node-utils.9dfd1e3f.mjs +0 -1114
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { MessagePort } from 'worker_threads';
|
|
2
|
+
import { R as ResolvedConfig, a2 as ViteNodeResolveId, a3 as FetchFunction, a4 as RawSourceMap, a as File, X as UserConsoleLog, T as TaskResultPack, v as SnapshotResult, g as Test, a5 as ModuleCacheMap, k as SuiteAPI, j as TestAPI, m as SuiteHooks, H as HookListener, q as TestContext, S as Suite, l as HookCleanupCallback } from './global-60f880c6.js';
|
|
3
|
+
import { M as MockMap } from './mocker-5e2a8e41.js';
|
|
4
|
+
import { SpyImpl } from 'tinyspy';
|
|
5
|
+
|
|
6
|
+
declare type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
|
|
7
|
+
declare type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
|
|
8
|
+
declare type PromisifyFn<T> = ReturnType$1<T> extends Promise<any> ? T : (...args: ArgumentsType<T>) => Promise<Awaited<ReturnType$1<T>>>;
|
|
9
|
+
declare type BirpcFn<T> = PromisifyFn<T> & {
|
|
10
|
+
/**
|
|
11
|
+
* Send event without asking for response
|
|
12
|
+
*/
|
|
13
|
+
asEvent(...args: ArgumentsType<T>): void;
|
|
14
|
+
};
|
|
15
|
+
declare type BirpcReturn<RemoteFunctions> = {
|
|
16
|
+
[K in keyof RemoteFunctions]: BirpcFn<RemoteFunctions[K]>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface WorkerContext {
|
|
20
|
+
workerId: number;
|
|
21
|
+
port: MessagePort;
|
|
22
|
+
config: ResolvedConfig;
|
|
23
|
+
files: string[];
|
|
24
|
+
invalidates?: string[];
|
|
25
|
+
}
|
|
26
|
+
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
|
|
27
|
+
interface WorkerRPC {
|
|
28
|
+
fetch: FetchFunction;
|
|
29
|
+
resolveId: ResolveIdFunction;
|
|
30
|
+
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
|
|
31
|
+
onFinished: (files: File[], errors?: unknown[]) => void;
|
|
32
|
+
onWorkerExit: (code?: number) => void;
|
|
33
|
+
onPathsCollected: (paths: string[]) => void;
|
|
34
|
+
onUserConsoleLog: (log: UserConsoleLog) => void;
|
|
35
|
+
onUnhandledRejection: (err: unknown) => void;
|
|
36
|
+
onCollected: (files: File[]) => void;
|
|
37
|
+
onTaskUpdate: (pack: TaskResultPack[]) => void;
|
|
38
|
+
snapshotSaved: (snapshot: SnapshotResult) => void;
|
|
39
|
+
resolveSnapshotPath: (testPath: string) => string;
|
|
40
|
+
}
|
|
41
|
+
interface WorkerGlobalState {
|
|
42
|
+
ctx: WorkerContext;
|
|
43
|
+
config: ResolvedConfig;
|
|
44
|
+
rpc: BirpcReturn<WorkerRPC>;
|
|
45
|
+
current?: Test;
|
|
46
|
+
filepath?: string;
|
|
47
|
+
moduleCache: ModuleCacheMap;
|
|
48
|
+
browserHashMap?: Map<string, string>;
|
|
49
|
+
mockMap: MockMap;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface MockResultReturn<T> {
|
|
53
|
+
type: 'return';
|
|
54
|
+
value: T;
|
|
55
|
+
}
|
|
56
|
+
interface MockResultIncomplete {
|
|
57
|
+
type: 'incomplete';
|
|
58
|
+
value: undefined;
|
|
59
|
+
}
|
|
60
|
+
interface MockResultThrow {
|
|
61
|
+
type: 'throw';
|
|
62
|
+
value: any;
|
|
63
|
+
}
|
|
64
|
+
declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
65
|
+
interface MockContext<TArgs, TReturns> {
|
|
66
|
+
calls: TArgs[];
|
|
67
|
+
instances: TReturns[];
|
|
68
|
+
invocationCallOrder: number[];
|
|
69
|
+
results: MockResult<TReturns>[];
|
|
70
|
+
lastCall: TArgs | undefined;
|
|
71
|
+
}
|
|
72
|
+
declare type Procedure = (...args: any[]) => any;
|
|
73
|
+
declare type Methods<T> = {
|
|
74
|
+
[K in keyof T]: T[K] extends Procedure ? K : never;
|
|
75
|
+
}[keyof T] & (string | symbol);
|
|
76
|
+
declare type Properties<T> = {
|
|
77
|
+
[K in keyof T]: T[K] extends Procedure ? never : K;
|
|
78
|
+
}[keyof T] & (string | symbol);
|
|
79
|
+
declare type Classes<T> = {
|
|
80
|
+
[K in keyof T]: T[K] extends new (...args: any[]) => any ? K : never;
|
|
81
|
+
}[keyof T] & (string | symbol);
|
|
82
|
+
interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
|
|
83
|
+
getMockName(): string;
|
|
84
|
+
mockName(n: string): this;
|
|
85
|
+
mock: MockContext<TArgs, TReturns>;
|
|
86
|
+
mockClear(): this;
|
|
87
|
+
mockReset(): this;
|
|
88
|
+
mockRestore(): void;
|
|
89
|
+
getMockImplementation(): ((...args: TArgs) => TReturns) | undefined;
|
|
90
|
+
mockImplementation(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
|
|
91
|
+
mockImplementationOnce(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
|
|
92
|
+
mockReturnThis(): this;
|
|
93
|
+
mockReturnValue(obj: TReturns): this;
|
|
94
|
+
mockReturnValueOnce(obj: TReturns): this;
|
|
95
|
+
mockResolvedValue(obj: Awaited<TReturns>): this;
|
|
96
|
+
mockResolvedValueOnce(obj: Awaited<TReturns>): this;
|
|
97
|
+
mockRejectedValue(obj: any): this;
|
|
98
|
+
mockRejectedValueOnce(obj: any): this;
|
|
99
|
+
}
|
|
100
|
+
interface MockInstance<A extends any[] = any[], R = any> extends SpyInstance<A, R> {
|
|
101
|
+
}
|
|
102
|
+
interface Mock<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, TReturns> {
|
|
103
|
+
new (...args: TArgs): TReturns;
|
|
104
|
+
(...args: TArgs): TReturns;
|
|
105
|
+
}
|
|
106
|
+
interface PartialMock<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, Partial<TReturns>> {
|
|
107
|
+
new (...args: TArgs): TReturns;
|
|
108
|
+
(...args: TArgs): TReturns;
|
|
109
|
+
}
|
|
110
|
+
declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? Mock<ConstructorParameters<T>, R> : T;
|
|
111
|
+
declare type MockedFunction<T extends Procedure> = Mock<Parameters<T>, ReturnType<T>> & {
|
|
112
|
+
[K in keyof T]: T[K];
|
|
113
|
+
};
|
|
114
|
+
declare type PartiallyMockedFunction<T extends Procedure> = PartialMock<Parameters<T>, ReturnType<T>> & {
|
|
115
|
+
[K in keyof T]: T[K];
|
|
116
|
+
};
|
|
117
|
+
declare type MockedFunctionDeep<T extends Procedure> = Mock<Parameters<T>, ReturnType<T>> & MockedObjectDeep<T>;
|
|
118
|
+
declare type PartiallyMockedFunctionDeep<T extends Procedure> = PartialMock<Parameters<T>, ReturnType<T>> & MockedObjectDeep<T>;
|
|
119
|
+
declare type MockedObject<T> = MaybeMockedConstructor<T> & {
|
|
120
|
+
[K in Methods<T>]: T[K] extends Procedure ? MockedFunction<T[K]> : T[K];
|
|
121
|
+
} & {
|
|
122
|
+
[K in Properties<T>]: T[K];
|
|
123
|
+
};
|
|
124
|
+
declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
|
|
125
|
+
[K in Methods<T>]: T[K] extends Procedure ? MockedFunctionDeep<T[K]> : T[K];
|
|
126
|
+
} & {
|
|
127
|
+
[K in Properties<T>]: MaybeMockedDeep<T[K]>;
|
|
128
|
+
};
|
|
129
|
+
declare type MaybeMockedDeep<T> = T extends Procedure ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
|
|
130
|
+
declare type MaybePartiallyMockedDeep<T> = T extends Procedure ? PartiallyMockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
|
|
131
|
+
declare type MaybeMocked<T> = T extends Procedure ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
|
|
132
|
+
declare type MaybePartiallyMocked<T> = T extends Procedure ? PartiallyMockedFunction<T> : T extends object ? MockedObject<T> : T;
|
|
133
|
+
interface Constructable {
|
|
134
|
+
new (...args: any[]): any;
|
|
135
|
+
}
|
|
136
|
+
declare type MockedClass<T extends Constructable> = MockInstance<T extends new (...args: infer P) => any ? P : never, InstanceType<T>> & {
|
|
137
|
+
prototype: T extends {
|
|
138
|
+
prototype: any;
|
|
139
|
+
} ? Mocked<T['prototype']> : never;
|
|
140
|
+
} & T;
|
|
141
|
+
declare type Mocked<T> = {
|
|
142
|
+
[P in keyof T]: T[P] extends (...args: infer Args) => infer Returns ? MockInstance<Args, Returns> : T[P] extends Constructable ? MockedClass<T[P]> : T[P];
|
|
143
|
+
} & T;
|
|
144
|
+
declare type EnhancedSpy<TArgs extends any[] = any[], TReturns = any> = SpyInstance<TArgs, TReturns> & SpyImpl<TArgs, TReturns>;
|
|
145
|
+
declare function spyOn<T, S extends Properties<Required<T>>>(obj: T, methodName: S, accessType: 'get'): SpyInstance<[], T[S]>;
|
|
146
|
+
declare function spyOn<T, G extends Properties<Required<T>>>(obj: T, methodName: G, accessType: 'set'): SpyInstance<[T[G]], void>;
|
|
147
|
+
declare function spyOn<T, M extends (Methods<Required<T>> | Classes<Required<T>>)>(obj: T, methodName: M): Required<T>[M] extends (...args: infer A) => infer R | (new (...args: infer A) => infer R) ? SpyInstance<A, R> : never;
|
|
148
|
+
declare function fn<TArgs extends any[] = any[], R = any>(): Mock<TArgs, R>;
|
|
149
|
+
declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): Mock<TArgs, R>;
|
|
150
|
+
|
|
151
|
+
declare const suite: SuiteAPI<{}>;
|
|
152
|
+
declare const test: TestAPI<{}>;
|
|
153
|
+
declare const describe: SuiteAPI<{}>;
|
|
154
|
+
declare const it: TestAPI<{}>;
|
|
155
|
+
|
|
156
|
+
declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number) => void;
|
|
157
|
+
declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number) => void;
|
|
158
|
+
declare const beforeEach: <ExtraContext = {}>(fn: HookListener<[TestContext & ExtraContext, Suite], HookCleanupCallback>, timeout?: number) => void;
|
|
159
|
+
declare const afterEach: <ExtraContext = {}>(fn: HookListener<[TestContext & ExtraContext, Suite], void>, timeout?: number) => void;
|
|
160
|
+
|
|
161
|
+
declare function createExpect(test?: Test): Vi.ExpectStatic;
|
|
162
|
+
declare const globalExpect: Vi.ExpectStatic;
|
|
163
|
+
|
|
164
|
+
export { EnhancedSpy as E, MaybeMockedDeep as M, ResolveIdFunction as R, SpyInstance as S, WorkerContext as W, MaybeMocked as a, MaybePartiallyMocked as b, MaybePartiallyMockedDeep as c, suite as d, describe as e, fn as f, beforeAll as g, afterAll as h, it as i, beforeEach as j, afterEach as k, globalExpect as l, createExpect as m, MockedFunction as n, MockedObject as o, MockInstance as p, Mock as q, MockContext as r, spyOn as s, test as t, Mocked as u, MockedClass as v, WorkerRPC as w, WorkerGlobalState as x };
|