vitest 0.0.61 → 0.0.65

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.
@@ -1,7 +1,5 @@
1
- import { MessagePort } from 'worker_threads';
2
- import { Awaitable } from '@antfu/utils';
3
1
  import { TransformResult, ViteDevServer } from 'vite';
4
- import { SnapshotStateOptions } from 'jest-snapshot/build/State';
2
+ import { OptionsReceived } from 'pretty-format';
5
3
 
6
4
  declare class StateManager {
7
5
  filesMap: Record<string, File>;
@@ -13,6 +11,142 @@ declare class StateManager {
13
11
  updateTasks(packs: TaskResultPack[]): void;
14
12
  }
15
13
 
14
+ declare class SnapshotManager {
15
+ config: ResolvedConfig;
16
+ summary: SnapshotSummary;
17
+ constructor(config: ResolvedConfig);
18
+ clear(): void;
19
+ add(result: SnapshotResult): void;
20
+ }
21
+
22
+ declare type Awaitable<T> = T | PromiseLike<T>;
23
+ declare type Nullable<T> = T | null | undefined;
24
+ declare type Arrayable<T> = T | Array<T>;
25
+ interface ModuleCache {
26
+ promise?: Promise<any>;
27
+ exports?: any;
28
+ transformResult?: TransformResult;
29
+ }
30
+ interface EnvironmentReturn {
31
+ teardown: (global: any) => Awaitable<void>;
32
+ }
33
+ interface Environment {
34
+ name: string;
35
+ setup(global: any): Awaitable<EnvironmentReturn>;
36
+ }
37
+ interface VitestContext {
38
+ config: ResolvedConfig;
39
+ server: ViteDevServer;
40
+ state: StateManager;
41
+ snapshot: SnapshotManager;
42
+ reporter: Reporter;
43
+ }
44
+
45
+ declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
46
+ declare type TaskState = RunMode | 'pass' | 'fail';
47
+ declare type ComputeMode = 'serial' | 'concurrent';
48
+ interface TaskBase {
49
+ id: string;
50
+ name: string;
51
+ mode: RunMode;
52
+ computeMode: ComputeMode;
53
+ suite?: Suite;
54
+ file?: File;
55
+ result?: TaskResult;
56
+ }
57
+ interface TaskResult {
58
+ state: TaskState;
59
+ start: number;
60
+ end?: number;
61
+ error?: unknown;
62
+ }
63
+ declare type TaskResultPack = [id: string, result: TaskResult | undefined];
64
+ interface Suite extends TaskBase {
65
+ type: 'suite';
66
+ tasks: Task[];
67
+ }
68
+ interface File extends Suite {
69
+ filepath: string;
70
+ }
71
+ interface Test extends TaskBase {
72
+ type: 'test';
73
+ suite: Suite;
74
+ result?: TaskResult;
75
+ }
76
+ declare type Task = Test | Suite | File;
77
+ declare type TestFunction = () => Awaitable<void>;
78
+ declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
79
+ interface ConcurrentCollector {
80
+ (name: string, fn: TestFunction, timeout?: number): void;
81
+ only: TestCollectorFn;
82
+ skip: TestCollectorFn;
83
+ todo: (name: string) => void;
84
+ }
85
+ interface OnlyCollector {
86
+ (name: string, fn: TestFunction, timeout?: number): void;
87
+ concurrent: TestCollectorFn;
88
+ }
89
+ interface SkipCollector {
90
+ (name: string, fn: TestFunction, timeout?: number): void;
91
+ concurrent: TestCollectorFn;
92
+ }
93
+ interface TodoCollector {
94
+ (name: string): void;
95
+ concurrent: (name: string) => void;
96
+ }
97
+ interface TestCollector {
98
+ (name: string, fn: TestFunction, timeout?: number): void;
99
+ concurrent: ConcurrentCollector;
100
+ only: OnlyCollector;
101
+ skip: SkipCollector;
102
+ todo: TodoCollector;
103
+ }
104
+ declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
105
+ interface SuiteHooks {
106
+ beforeAll: HookListener<[Suite]>[];
107
+ afterAll: HookListener<[Suite]>[];
108
+ beforeEach: HookListener<[Test, Suite]>[];
109
+ afterEach: HookListener<[Test, Suite]>[];
110
+ }
111
+ interface SuiteCollector {
112
+ readonly name: string;
113
+ readonly mode: RunMode;
114
+ type: 'collector';
115
+ test: TestCollector;
116
+ tasks: (Suite | Test | SuiteCollector)[];
117
+ collect: (file?: File) => Promise<Suite>;
118
+ clear: () => void;
119
+ on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
120
+ }
121
+ declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
122
+ interface GlobalContext {
123
+ tasks: (SuiteCollector | Test)[];
124
+ currentSuite: SuiteCollector | null;
125
+ }
126
+
127
+ interface Reporter {
128
+ onStart?: (files?: string[]) => Awaitable<void>;
129
+ onFinished?: (files?: File[]) => Awaitable<void>;
130
+ onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
131
+ onWatcherStart?: () => Awaitable<void>;
132
+ onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
133
+ }
134
+
135
+ declare type SnapshotData = Record<string, string>;
136
+ declare type SnapshotUpdateState = 'all' | 'new' | 'none';
137
+ declare type SnapshotStateOptions = {
138
+ updateSnapshot: SnapshotUpdateState;
139
+ expand?: boolean;
140
+ snapshotFormat?: OptionsReceived;
141
+ };
142
+ declare type SnapshotMatchOptions = {
143
+ testName: string;
144
+ received: unknown;
145
+ key?: string;
146
+ inlineSnapshot?: string;
147
+ isInline: boolean;
148
+ error?: Error;
149
+ };
16
150
  interface SnapshotResult {
17
151
  filepath: string;
18
152
  added: number;
@@ -44,14 +178,6 @@ interface SnapshotSummary {
44
178
  updated: number;
45
179
  }
46
180
 
47
- declare class SnapshotManager {
48
- config: ResolvedConfig;
49
- summary: SnapshotSummary;
50
- constructor(config: ResolvedConfig);
51
- clear(): void;
52
- add(result: SnapshotResult): void;
53
- }
54
-
55
181
  interface UserOptions {
56
182
  /**
57
183
  * Include globs for test files
@@ -91,11 +217,13 @@ interface UserOptions {
91
217
  */
92
218
  global?: boolean;
93
219
  /**
94
- * Use `jsdom` or `happy-dom` to mock browser APIs
220
+ * Running environment
95
221
  *
96
- * @default false
222
+ * Supports 'node', 'jsdom', 'happy-dom'
223
+ *
224
+ * @default 'node'
97
225
  */
98
- dom?: boolean | 'jsdom' | 'happy-dom';
226
+ environment?: 'node' | 'jsdom' | 'happy-dom';
99
227
  /**
100
228
  * Update snapshot files
101
229
  *
@@ -117,10 +245,23 @@ interface UserOptions {
117
245
  */
118
246
  reporter?: Reporter;
119
247
  /**
120
- * Interpret CJS module's default as named exports
248
+ * Enable multi-threading
121
249
  *
122
250
  * @default true
123
251
  */
252
+ threads?: boolean;
253
+ /**
254
+ * Maximum number of threads
255
+ *
256
+ * @default available CPUs
257
+ */
258
+ maxThreads?: number;
259
+ /**
260
+ * Minimum number of threads
261
+ *
262
+ * @default available CPUs
263
+ */
264
+ minThreads?: number;
124
265
  interpretDefault?: boolean;
125
266
  }
126
267
  interface CliOptions extends UserOptions {
@@ -146,128 +287,5 @@ interface ResolvedConfig extends Omit<Required<CliOptions>, 'config' | 'filters'
146
287
  depsExternal: (string | RegExp)[];
147
288
  snapshotOptions: SnapshotStateOptions;
148
289
  }
149
- declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
150
- declare type TaskState = RunMode | 'pass' | 'fail';
151
- declare type ComputeMode = 'serial' | 'concurrent';
152
- interface TaskBase {
153
- id: string;
154
- name: string;
155
- mode: RunMode;
156
- computeMode: ComputeMode;
157
- suite?: Suite;
158
- file?: File;
159
- result?: TaskResult;
160
- }
161
- interface TaskResult {
162
- state: TaskState;
163
- start: number;
164
- end?: number;
165
- error?: unknown;
166
- }
167
- declare type TaskResultPack = [id: string, result: TaskResult | undefined];
168
- interface Suite extends TaskBase {
169
- type: 'suite';
170
- tasks: Task[];
171
- }
172
- interface File extends Suite {
173
- filepath: string;
174
- }
175
- interface Test extends TaskBase {
176
- type: 'test';
177
- suite: Suite;
178
- result?: TaskResult;
179
- }
180
- declare type Task = Test | Suite | File;
181
- declare type TestFunction = () => Awaitable<void>;
182
- declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
183
- interface ConcurrentCollector {
184
- (name: string, fn: TestFunction, timeout?: number): void;
185
- only: TestCollectorFn;
186
- skip: TestCollectorFn;
187
- todo: (name: string) => void;
188
- }
189
- interface OnlyCollector {
190
- (name: string, fn: TestFunction, timeout?: number): void;
191
- concurrent: TestCollectorFn;
192
- }
193
- interface SkipCollector {
194
- (name: string, fn: TestFunction, timeout?: number): void;
195
- concurrent: TestCollectorFn;
196
- }
197
- interface TodoCollector {
198
- (name: string): void;
199
- concurrent: (name: string) => void;
200
- }
201
- interface TestCollector {
202
- (name: string, fn: TestFunction, timeout?: number): void;
203
- concurrent: ConcurrentCollector;
204
- only: OnlyCollector;
205
- skip: SkipCollector;
206
- todo: TodoCollector;
207
- }
208
- declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
209
- interface SuiteHooks {
210
- beforeAll: HookListener<[Suite]>[];
211
- afterAll: HookListener<[Suite]>[];
212
- beforeEach: HookListener<[Test, Suite]>[];
213
- afterEach: HookListener<[Test, Suite]>[];
214
- }
215
- interface SuiteCollector {
216
- readonly name: string;
217
- readonly mode: RunMode;
218
- type: 'collector';
219
- test: TestCollector;
220
- tasks: (Suite | Test | SuiteCollector)[];
221
- collect: (file?: File) => Promise<Suite>;
222
- clear: () => void;
223
- on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
224
- }
225
- declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
226
- interface GlobalContext {
227
- tasks: (SuiteCollector | Test)[];
228
- currentSuite: SuiteCollector | null;
229
- }
230
- interface Reporter {
231
- onStart?: (files?: string[]) => Awaitable<void>;
232
- onFinished?: (files?: File[]) => Awaitable<void>;
233
- onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
234
- onWatcherStart?: () => Awaitable<void>;
235
- onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
236
- }
237
- interface ModuleCache {
238
- promise?: Promise<any>;
239
- exports?: any;
240
- transformResult?: TransformResult;
241
- }
242
- interface WorkerContext {
243
- port: MessagePort;
244
- config: ResolvedConfig;
245
- files: string[];
246
- invalidates?: string[];
247
- }
248
- interface RpcMap {
249
- workerReady: [[], void];
250
- fetch: [[id: string], TransformResult | null | undefined];
251
- onCollected: [[files: File[]], void];
252
- onFinished: [[], void];
253
- onTaskUpdate: [[pack: TaskResultPack], void];
254
- onWatcherStart: [[], void];
255
- onWatcherRerun: [[files: string[], trigger: string], void];
256
- snapshotSaved: [[snapshot: SnapshotResult], void];
257
- }
258
- declare type RpcCall = <T extends keyof RpcMap>(method: T, ...args: RpcMap[T][0]) => Promise<RpcMap[T][1]>;
259
- declare type RpcSend = <T extends keyof RpcMap>(method: T, ...args: RpcMap[T][0]) => void;
260
- declare type RpcPayload<T extends keyof RpcMap = keyof RpcMap> = {
261
- id: string;
262
- method: T;
263
- args: RpcMap[T][0];
264
- };
265
- interface VitestContext {
266
- config: ResolvedConfig;
267
- server: ViteDevServer;
268
- state: StateManager;
269
- snapshot: SnapshotManager;
270
- reporter: Reporter;
271
- }
272
290
 
273
- export { CliOptions as C, File as F, GlobalContext as G, HookListener as H, ModuleCache as M, ResolvedConfig as R, SuiteCollector as S, TestFactory as T, UserOptions as U, VitestContext as V, WorkerContext as W, TestFunction as a, SuiteHooks as b, RunMode as c, TaskState as d, ComputeMode as e, TaskBase as f, TaskResult as g, TaskResultPack as h, Suite as i, Test as j, Task as k, TestCollector as l, Reporter as m, RpcMap as n, RpcCall as o, RpcSend as p, RpcPayload as q };
291
+ export { Awaitable as A, CliOptions as C, EnvironmentReturn as E, File as F, GlobalContext as G, HookListener as H, ModuleCache as M, Nullable as N, ResolvedConfig as R, SnapshotResult as S, TaskResultPack as T, UserOptions as U, VitestContext as V, TestFactory as a, SuiteCollector as b, TestFunction as c, SuiteHooks as d, RunMode as e, TaskState as f, ComputeMode as g, TaskBase as h, TaskResult as i, Suite as j, Test as k, Task as l, TestCollector as m, Reporter as n, SnapshotData as o, SnapshotUpdateState as p, SnapshotStateOptions as q, SnapshotMatchOptions as r, UncheckedSnapshot as s, SnapshotSummary as t, Arrayable as u, Environment as v };
@@ -1,8 +1,6 @@
1
- import { R as ResolvedConfig } from '../types-31dc4f04';
2
- import 'worker_threads';
3
- import '@antfu/utils';
1
+ import { R as ResolvedConfig } from '../options-652352ad';
4
2
  import 'vite';
5
- import 'jest-snapshot/build/State';
3
+ import 'pretty-format';
6
4
 
7
5
  declare function run(files: string[], config: ResolvedConfig): Promise<void>;
8
6