vitest 0.0.101 → 0.0.102

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/dist/cli.js CHANGED
@@ -634,7 +634,7 @@ class CAC extends EventEmitter {
634
634
 
635
635
  const cac = (name = "") => new CAC(name);
636
636
 
637
- var version = "0.0.101";
637
+ var version = "0.0.102";
638
638
 
639
639
  const cli = cac("vitest");
640
640
  cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open Vitest UI").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", {
package/dist/entry.js CHANGED
@@ -8,7 +8,7 @@ import { l as index, g as getNames, c as c$1, t as toArray, b as basename, m as
8
8
  import { r as rpc, s as send } from './rpc-7de86f29.js';
9
9
  import { u as unifiedDiff } from './error-d97062cd.js';
10
10
  import { performance } from 'perf_hooks';
11
- import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-4f3fb0b5.js';
11
+ import { c as clearContext, b as defaultSuite, e as setHooks, f as getHooks, h as context, j as getFn } from './suite-64b3e636.js';
12
12
  import { n as nanoid } from './index-9e71c815.js';
13
13
  import { format as format$1 } from 'util';
14
14
  import 'tty';
@@ -3887,7 +3887,7 @@ async function setupGlobalEnv(config) {
3887
3887
  setupConsoleLogSpy();
3888
3888
  await setupChai();
3889
3889
  if (config.global)
3890
- (await import('./global-5b58e48f.js')).registerApiGlobally();
3890
+ (await import('./global-12f52a87.js')).registerApiGlobally();
3891
3891
  }
3892
3892
  function setupConsoleLogSpy() {
3893
3893
  const stdout = new Writable({
@@ -3976,12 +3976,12 @@ async function collectTests(paths, config) {
3976
3976
  filepath,
3977
3977
  tasks: []
3978
3978
  };
3979
- setHooks(file, createSuiteHooks());
3980
3979
  clearContext();
3981
3980
  try {
3982
3981
  await runSetupFiles(config);
3983
3982
  await import(filepath);
3984
3983
  const defaultTasks = await defaultSuite.collect(file);
3984
+ setHooks(file, getHooks(defaultTasks));
3985
3985
  for (const c of [...defaultTasks.tasks, ...context.tasks]) {
3986
3986
  if (c.type === "test") {
3987
3987
  file.tasks.push(c);
@@ -1,11 +1,11 @@
1
1
  import { g as globalApis } from './constants-a1417084.js';
2
- import { i as index } from './index-f580d714.js';
2
+ import { i as index } from './index-a190f5a1.js';
3
3
  import 'url';
4
4
  import './utils-c8e62373.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
- import './suite-4f3fb0b5.js';
8
+ import './suite-64b3e636.js';
9
9
  import './index-9e71c815.js';
10
10
  import 'chai';
11
11
  import 'tinyspy';
@@ -1,4 +1,4 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-4f3fb0b5.js';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-64b3e636.js';
2
2
  import chai, { util, assert, should, expect } from 'chai';
3
3
  import * as tinyspy from 'tinyspy';
4
4
  import { spies } from 'tinyspy';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { d as describe, i as it, s as suite, t as test } from './suite-4f3fb0b5.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, f as fn, s as spyOn, e as vi, v as vitest } from './index-f580d714.js';
1
+ export { d as describe, i as it, s as suite, t as test } from './suite-64b3e636.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, f as fn, s as spyOn, e as vi, v as vitest } from './index-a190f5a1.js';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
4
  import './index-9e71c815.js';
5
5
  import './utils-c8e62373.js';
package/dist/node.d.ts ADDED
@@ -0,0 +1,309 @@
1
+ import { ViteDevServer, UserConfig as UserConfig$1 } from 'vite';
2
+ import { OptionsReceived } from 'pretty-format';
3
+
4
+ declare type Awaitable<T> = T | PromiseLike<T>;
5
+ declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
6
+ interface UserConsoleLog {
7
+ content: string;
8
+ type: 'stdout' | 'stderr';
9
+ taskId?: string;
10
+ }
11
+
12
+ declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
13
+ declare type TaskState = RunMode | 'pass' | 'fail';
14
+ declare type ComputeMode = 'serial' | 'concurrent';
15
+ interface TaskBase {
16
+ id: string;
17
+ name: string;
18
+ mode: RunMode;
19
+ computeMode: ComputeMode;
20
+ suite?: Suite;
21
+ file?: File;
22
+ result?: TaskResult;
23
+ }
24
+ interface TaskResult {
25
+ state: TaskState;
26
+ start: number;
27
+ end?: number;
28
+ error?: unknown;
29
+ }
30
+ declare type TaskResultPack = [id: string, result: TaskResult | undefined];
31
+ interface Suite extends TaskBase {
32
+ type: 'suite';
33
+ tasks: Task[];
34
+ }
35
+ interface File extends Suite {
36
+ filepath: string;
37
+ }
38
+ interface Test extends TaskBase {
39
+ type: 'test';
40
+ suite: Suite;
41
+ result?: TaskResult;
42
+ fails?: boolean;
43
+ }
44
+ declare type Task = Test | Suite | File;
45
+
46
+ interface Reporter {
47
+ onStart?: (files?: string[]) => Awaitable<void>;
48
+ onFinished?: (files?: File[]) => Awaitable<void>;
49
+ onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
50
+ onWatcherStart?: () => Awaitable<void>;
51
+ onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
52
+ onServerRestart?: () => Awaitable<void>;
53
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
54
+ }
55
+
56
+ declare type SnapshotUpdateState = 'all' | 'new' | 'none';
57
+ declare type SnapshotStateOptions = {
58
+ updateSnapshot: SnapshotUpdateState;
59
+ expand?: boolean;
60
+ snapshotFormat?: OptionsReceived;
61
+ };
62
+ interface SnapshotResult {
63
+ filepath: string;
64
+ added: number;
65
+ fileDeleted: boolean;
66
+ matched: number;
67
+ unchecked: number;
68
+ uncheckedKeys: Array<string>;
69
+ unmatched: number;
70
+ updated: number;
71
+ }
72
+ interface UncheckedSnapshot {
73
+ filePath: string;
74
+ keys: Array<string>;
75
+ }
76
+ interface SnapshotSummary {
77
+ added: number;
78
+ didUpdate: boolean;
79
+ failure: boolean;
80
+ filesAdded: number;
81
+ filesRemoved: number;
82
+ filesRemovedList: Array<string>;
83
+ filesUnmatched: number;
84
+ filesUpdated: number;
85
+ matched: number;
86
+ total: number;
87
+ unchecked: number;
88
+ uncheckedKeysByFile: Array<UncheckedSnapshot>;
89
+ unmatched: number;
90
+ updated: number;
91
+ }
92
+
93
+ declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom';
94
+ interface InlineConfig {
95
+ /**
96
+ * Include globs for test files
97
+ *
98
+ * @default ['**\/*.test.ts']
99
+ */
100
+ include?: string[];
101
+ /**
102
+ * Exclude globs for test files
103
+ * @default ['**\/node_modules\/**']
104
+ */
105
+ exclude?: string[];
106
+ /**
107
+ * Handling for dependencies inlining or externalizing
108
+ */
109
+ deps?: {
110
+ /**
111
+ * Externalize means that Vite will bypass the package to native Node.
112
+ *
113
+ * Externalized dependencies will not be applied Vite's transformers and resolvers.
114
+ * And does not support HMR on reload.
115
+ *
116
+ * Typically, packages under `node_modules` are externalized.
117
+ */
118
+ external?: (string | RegExp)[];
119
+ /**
120
+ * Vite will process inlined modules.
121
+ *
122
+ * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
123
+ */
124
+ inline?: (string | RegExp)[];
125
+ };
126
+ /**
127
+ * Register apis globally
128
+ *
129
+ * @default false
130
+ */
131
+ global?: boolean;
132
+ /**
133
+ * Running environment
134
+ *
135
+ * Supports 'node', 'jsdom', 'happy-dom'
136
+ *
137
+ * @default 'node'
138
+ */
139
+ environment?: BuiltinEnvironment;
140
+ /**
141
+ * Update snapshot files
142
+ *
143
+ * @default false
144
+ */
145
+ update?: boolean;
146
+ /**
147
+ * Watch mode
148
+ *
149
+ * @default false
150
+ */
151
+ watch?: boolean;
152
+ /**
153
+ * Project root
154
+ */
155
+ root?: string;
156
+ /**
157
+ * Custom reporter for output
158
+ */
159
+ reporters?: Reporter | Reporter[];
160
+ /**
161
+ * Enable multi-threading
162
+ *
163
+ * @default true
164
+ */
165
+ threads?: boolean;
166
+ /**
167
+ * Maximum number of threads
168
+ *
169
+ * @default available CPUs
170
+ */
171
+ maxThreads?: number;
172
+ /**
173
+ * Minimum number of threads
174
+ *
175
+ * @default available CPUs
176
+ */
177
+ minThreads?: number;
178
+ interpretDefault?: boolean;
179
+ /**
180
+ * Default timeout of a test in milliseconds
181
+ *
182
+ * @default 5000
183
+ */
184
+ testTimeout?: number;
185
+ /**
186
+ * Default timeout of a hook in milliseconds
187
+ *
188
+ * @default 5000
189
+ */
190
+ hookTimeout?: number;
191
+ /**
192
+ * Silent mode
193
+ *
194
+ * @default false
195
+ */
196
+ silent?: boolean;
197
+ /**
198
+ * Path to setup files
199
+ */
200
+ setupFiles?: string | string[];
201
+ /**
202
+ * Pattern of file paths to be ignore from triggering watch rerun
203
+ *
204
+ * @default ['**\/node_modules\/**', '**\/dist/**']
205
+ */
206
+ watchIgnore?: (string | RegExp)[];
207
+ /**
208
+ * Open Vitest UI
209
+ * @internal WIP
210
+ */
211
+ open?: boolean;
212
+ /**
213
+ * Listen to port and serve API
214
+ *
215
+ * When set to true, the default port is 55555
216
+ *
217
+ * @internal WIP
218
+ * @default false
219
+ */
220
+ api?: boolean | number;
221
+ }
222
+ interface UserConfig extends InlineConfig {
223
+ /**
224
+ * Path to the config file.
225
+ *
226
+ * Default resolving to one of:
227
+ * - `vitest.config.js`
228
+ * - `vitest.config.ts`
229
+ * - `vite.config.js`
230
+ * - `vite.config.ts`
231
+ */
232
+ config?: string | undefined;
233
+ /**
234
+ * Use happy-dom
235
+ */
236
+ dom?: boolean;
237
+ /**
238
+ * Do not watch
239
+ */
240
+ run?: boolean;
241
+ }
242
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'> {
243
+ config?: string;
244
+ filters?: string[];
245
+ depsInline: (string | RegExp)[];
246
+ depsExternal: (string | RegExp)[];
247
+ snapshotOptions: SnapshotStateOptions;
248
+ }
249
+
250
+ declare class SnapshotManager {
251
+ config: ResolvedConfig;
252
+ summary: SnapshotSummary;
253
+ constructor(config: ResolvedConfig);
254
+ clear(): void;
255
+ add(result: SnapshotResult): void;
256
+ }
257
+
258
+ declare type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
259
+ interface WorkerPool {
260
+ runTests: RunWithFiles;
261
+ collectTests: RunWithFiles;
262
+ close: () => Promise<void>;
263
+ }
264
+
265
+ declare class StateManager {
266
+ filesMap: Record<string, File>;
267
+ idMap: Record<string, Task>;
268
+ taskFileMap: WeakMap<Task, File>;
269
+ getFiles(keys?: string[]): File[];
270
+ collectFiles(files: File[]): void;
271
+ updateId(task: Task): void;
272
+ updateTasks(packs: TaskResultPack[]): void;
273
+ }
274
+
275
+ declare class Vitest {
276
+ config: ResolvedConfig;
277
+ server: ViteDevServer;
278
+ state: StateManager;
279
+ snapshot: SnapshotManager;
280
+ reporters: Reporter[];
281
+ console: Console;
282
+ pool: WorkerPool | undefined;
283
+ invalidates: Set<string>;
284
+ changedTests: Set<string>;
285
+ runningPromise?: Promise<void>;
286
+ isFirstRun: boolean;
287
+ restartsCount: number;
288
+ private _onRestartListeners;
289
+ constructor();
290
+ setServer(options: UserConfig, server: ViteDevServer): void;
291
+ start(filters?: string[]): Promise<void>;
292
+ runFiles(files: string[]): Promise<void>;
293
+ log(...args: any[]): void;
294
+ error(...args: any[]): void;
295
+ private _rerunTimer;
296
+ private scheduleRerun;
297
+ private unregisterWatcher;
298
+ private registerWatcher;
299
+ private handleFileChanged;
300
+ close(): Promise<void>;
301
+ report<T extends keyof Reporter>(name: T, ...args: ArgumentsType<Reporter[T]>): Promise<void>;
302
+ globTestFiles(filters?: string[]): Promise<string[]>;
303
+ isTargetFile(id: string): boolean;
304
+ onServerRestarted(fn: () => void): void;
305
+ }
306
+
307
+ declare function createVitest(options: UserConfig, viteOverrides?: UserConfig$1): Promise<Vitest>;
308
+
309
+ export { Vitest, createVitest };
@@ -198,4 +198,4 @@ function createSuite() {
198
198
  });
199
199
  }
200
200
 
201
- export { getDefaultHookTimeout as a, setHooks as b, createSuiteHooks as c, describe as d, clearContext as e, defaultSuite as f, getCurrentSuite as g, context as h, it as i, getHooks as j, getFn as k, suite as s, test as t, withTimeout as w };
201
+ export { getDefaultHookTimeout as a, defaultSuite as b, clearContext as c, describe as d, setHooks as e, getHooks as f, getCurrentSuite as g, context as h, it as i, getFn as j, suite as s, test as t, withTimeout as w };
package/node.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/node'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.101",
3
+ "version": "0.0.102",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",