vitest 0.0.98 → 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.
@@ -1,8 +1,7 @@
1
+ import { c as commonjsGlobal } from './_commonjsHelpers-bdec4bbd.js';
1
2
  import assert$1 from 'assert';
2
3
  import require$$2 from 'events';
3
4
 
4
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
5
-
6
5
  var onetime$2 = {exports: {}};
7
6
 
8
7
  var mimicFn$2 = {exports: {}};
@@ -328,4 +327,4 @@ if (!processOk(process$1)) {
328
327
 
329
328
  var signalExit = signalExit$1.exports;
330
329
 
331
- export { signalExit$1 as a, onetime$2 as b, commonjsGlobal as c, onetime$1 as o, signalExit as s };
330
+ export { signalExit$1 as a, onetime$2 as b, onetime$1 as o, signalExit as s };
@@ -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-b8c6cb53.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.d.ts CHANGED
@@ -173,6 +173,12 @@ interface UserConsoleLog {
173
173
  taskId?: string;
174
174
  }
175
175
 
176
+ declare type ChainableFunction<T extends string, Args extends any[], R = any> = {
177
+ (...args: Args): R;
178
+ } & {
179
+ [x in T]: ChainableFunction<T, Args, R>;
180
+ };
181
+
176
182
  declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
177
183
  declare type TaskState = RunMode | 'pass' | 'fail';
178
184
  declare type ComputeMode = 'serial' | 'concurrent';
@@ -203,36 +209,16 @@ interface Test extends TaskBase {
203
209
  type: 'test';
204
210
  suite: Suite;
205
211
  result?: TaskResult;
212
+ fails?: boolean;
206
213
  }
207
214
  declare type Task = Test | Suite | File;
208
215
  declare type DoneCallback = (error?: any) => void;
209
216
  declare type TestFunction = (done: DoneCallback) => Awaitable<void>;
210
- declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
211
- interface ConcurrentCollector {
212
- (name: string, fn: TestFunction, timeout?: number): void;
213
- only: TestCollectorFn;
214
- skip: TestCollectorFn;
215
- todo: (name: string) => void;
216
- }
217
- interface OnlyCollector {
218
- (name: string, fn: TestFunction, timeout?: number): void;
219
- concurrent: TestCollectorFn;
220
- }
221
- interface SkipCollector {
222
- (name: string, fn: TestFunction, timeout?: number): void;
223
- concurrent: TestCollectorFn;
224
- }
225
- interface TodoCollector {
226
- (name: string): void;
227
- concurrent: (name: string) => void;
228
- }
229
- interface TestCollector {
230
- (name: string, fn: TestFunction, timeout?: number): void;
231
- concurrent: ConcurrentCollector;
232
- only: OnlyCollector;
233
- skip: SkipCollector;
234
- todo: TodoCollector;
235
- }
217
+ declare type TestCollector = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
218
+ name: string,
219
+ fn?: TestFunction,
220
+ timeout?: number
221
+ ], void>;
236
222
  declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
237
223
  interface SuiteHooks {
238
224
  beforeAll: HookListener<[Suite]>[];
@@ -452,7 +438,14 @@ interface UserConfig extends InlineConfig {
452
438
  * - `vite.config.ts`
453
439
  */
454
440
  config?: string | undefined;
441
+ /**
442
+ * Use happy-dom
443
+ */
455
444
  dom?: boolean;
445
+ /**
446
+ * Do not watch
447
+ */
448
+ run?: boolean;
456
449
  }
457
450
  interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'> {
458
451
  config?: string;
@@ -485,90 +478,10 @@ declare type RpcPayload<T extends keyof RpcMap = keyof RpcMap> = {
485
478
  args: RpcMap[T][0];
486
479
  };
487
480
 
488
- declare const suite: {
489
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
490
- concurrent: {
491
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
492
- skip(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
493
- only(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
494
- todo(suiteName: string): SuiteCollector;
495
- };
496
- skip: {
497
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
498
- concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
499
- };
500
- only: {
501
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
502
- concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
503
- };
504
- todo: {
505
- (suiteName: string): SuiteCollector;
506
- concurrent: (suiteName: string) => SuiteCollector;
507
- };
508
- };
509
- declare const test: {
510
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
511
- concurrent: {
512
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
513
- skip(name: string, fn: TestFunction, timeout?: number | undefined): void;
514
- only(name: string, fn: TestFunction, timeout?: number | undefined): void;
515
- todo(name: string): void;
516
- };
517
- skip: {
518
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
519
- concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
520
- };
521
- only: {
522
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
523
- concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
524
- };
525
- todo: {
526
- (name: string): void;
527
- concurrent(name: string): void;
528
- };
529
- };
530
- declare const describe: {
531
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
532
- concurrent: {
533
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
534
- skip(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
535
- only(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
536
- todo(suiteName: string): SuiteCollector;
537
- };
538
- skip: {
539
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
540
- concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
541
- };
542
- only: {
543
- (suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
544
- concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
545
- };
546
- todo: {
547
- (suiteName: string): SuiteCollector;
548
- concurrent: (suiteName: string) => SuiteCollector;
549
- };
550
- };
551
- declare const it: {
552
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
553
- concurrent: {
554
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
555
- skip(name: string, fn: TestFunction, timeout?: number | undefined): void;
556
- only(name: string, fn: TestFunction, timeout?: number | undefined): void;
557
- todo(name: string): void;
558
- };
559
- skip: {
560
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
561
- concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
562
- };
563
- only: {
564
- (name: string, fn: TestFunction, timeout?: number | undefined): void;
565
- concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
566
- };
567
- todo: {
568
- (name: string): void;
569
- concurrent(name: string): void;
570
- };
571
- };
481
+ declare const suite: ChainableFunction<"skip" | "only" | "todo" | "concurrent", [name: string, factory?: TestFactory | undefined], SuiteCollector>;
482
+ declare const test: TestCollector;
483
+ declare const describe: ChainableFunction<"skip" | "only" | "todo" | "concurrent", [name: string, factory?: TestFactory | undefined], SuiteCollector>;
484
+ declare const it: TestCollector;
572
485
  declare global {
573
486
  namespace NodeJS {
574
487
  interface Process {
@@ -657,12 +570,14 @@ declare class VitestUtils {
657
570
  declare const vitest: VitestUtils;
658
571
  declare const vi: VitestUtils;
659
572
 
573
+ declare type VitestInlineConfig = InlineConfig;
574
+
660
575
  declare module 'vite' {
661
576
  interface UserConfig {
662
577
  /**
663
578
  * Options for Vitest
664
579
  */
665
- test?: InlineConfig;
580
+ test?: VitestInlineConfig;
666
581
  }
667
582
  }
668
583
  declare global {
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
- export { d as describe, i as it, s as suite, t as test } from './suite-b8c6cb53.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-368448f4.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
+ import './utils-c8e62373.js';
6
+ import 'tty';
7
+ import 'local-pkg';
8
+ import 'path';
5
9
  import 'tinyspy';
@@ -1,6 +1,8 @@
1
- import { A as API_PATH } from './constants-e78c749a.js';
1
+ import { A as API_PATH } from './constants-a1417084.js';
2
2
  import 'url';
3
- import './index-1488b423.js';
3
+ import './utils-c8e62373.js';
4
+ import 'tty';
5
+ import 'local-pkg';
4
6
  import 'path';
5
7
 
6
8
  /*! (c) 2020 Andrea Giammarchi */
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 };
package/dist/node.js CHANGED
@@ -1,21 +1,21 @@
1
- export { c as createVitest } from './index-0697046c.js';
2
- import './index-1488b423.js';
1
+ export { c as createVitest } from './index-37755855.js';
2
+ import './utils-c8e62373.js';
3
+ import 'tty';
4
+ import 'local-pkg';
3
5
  import 'path';
4
6
  import 'vite';
5
7
  import 'process';
6
8
  import 'fs';
7
- import 'fast-glob';
9
+ import 'os';
8
10
  import 'util';
9
- import './constants-e78c749a.js';
11
+ import 'stream';
12
+ import 'events';
13
+ import './constants-a1417084.js';
10
14
  import 'url';
11
- import './utils-70b78878.js';
12
- import 'tty';
13
- import 'local-pkg';
14
15
  import 'perf_hooks';
15
- import './error-2437ee7f.js';
16
- import 'source-map';
17
- import './index-5cc247ff.js';
16
+ import './error-d97062cd.js';
17
+ import './index-825cb54c.js';
18
+ import './_commonjsHelpers-bdec4bbd.js';
18
19
  import 'assert';
19
- import 'events';
20
20
  import 'worker_threads';
21
21
  import 'tinypool';