vitest 0.0.68 → 0.0.69

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.
@@ -0,0 +1,16 @@
1
+ import { g as globalApis } from './constants-d4c70610.js';
2
+ import { i as index } from './index-e37648e9.js';
3
+ import 'path';
4
+ import 'url';
5
+ import './suite-819c135e.js';
6
+ import './index-6427e0f2.js';
7
+ import 'chai';
8
+ import 'sinon';
9
+
10
+ function registerApiGlobally() {
11
+ globalApis.forEach((api) => {
12
+ globalThis[api] = index[api];
13
+ });
14
+ }
15
+
16
+ export { registerApiGlobally };
@@ -0,0 +1,12 @@
1
+ let urlAlphabet =
2
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
3
+ let nanoid = (size = 21) => {
4
+ let id = '';
5
+ let i = size;
6
+ while (i--) {
7
+ id += urlAlphabet[(Math.random() * 64) | 0];
8
+ }
9
+ return id
10
+ };
11
+
12
+ export { nanoid as n };
@@ -0,0 +1,31 @@
1
+ import { s as suite, d as defaultSuite, c as createSuiteHooks, t as test, a as describe, i as it, b as beforeAll, e as afterAll, f as beforeEach, g as afterEach, h as clearContext } from './suite-819c135e.js';
2
+ import chai, { assert, should, expect } from 'chai';
3
+ import sinon from 'sinon';
4
+
5
+ const { mock, spy, stub } = sinon;
6
+ sinon.fn = sinon.spy;
7
+
8
+ var index = /*#__PURE__*/Object.freeze({
9
+ __proto__: null,
10
+ suite: suite,
11
+ defaultSuite: defaultSuite,
12
+ createSuiteHooks: createSuiteHooks,
13
+ test: test,
14
+ describe: describe,
15
+ it: it,
16
+ beforeAll: beforeAll,
17
+ afterAll: afterAll,
18
+ beforeEach: beforeEach,
19
+ afterEach: afterEach,
20
+ clearContext: clearContext,
21
+ assert: assert,
22
+ should: should,
23
+ expect: expect,
24
+ chai: chai,
25
+ sinon: sinon,
26
+ mock: mock,
27
+ spy: spy,
28
+ stub: stub
29
+ });
30
+
31
+ export { stub as a, index as i, mock as m, spy as s };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,299 @@
1
- import { R as ResolvedConfig, F as File, T as TaskResultPack, S as SnapshotResult, a as TestFactory, b as SuiteCollector, c as TestFunction, d as SuiteHooks, U as UserOptions } from './options-63a726fa';
2
- export { u as Arrayable, A as Awaitable, C as CliOptions, g as ComputeMode, v as Environment, E as EnvironmentReturn, F as File, G as GlobalContext, H as HookListener, M as ModuleCache, N as Nullable, n as Reporter, R as ResolvedConfig, e as RunMode, o as SnapshotData, r as SnapshotMatchOptions, S as SnapshotResult, q as SnapshotStateOptions, t as SnapshotSummary, p as SnapshotUpdateState, j as Suite, b as SuiteCollector, d as SuiteHooks, l as Task, h as TaskBase, i as TaskResult, T as TaskResultPack, f as TaskState, k as Test, m as TestCollector, a as TestFactory, c as TestFunction, s as UncheckedSnapshot, U as UserOptions, V as VitestContext } from './options-63a726fa';
1
+ import { TransformResult, ViteDevServer } from 'vite';
2
+ import { OptionsReceived } from 'pretty-format';
3
3
  import { MessagePort } from 'worker_threads';
4
- import { TransformResult } from 'vite';
5
4
  export { assert, default as chai, expect, should } from 'chai';
6
5
  import sinon from 'sinon';
7
6
  export { default as sinon } from 'sinon';
8
- import 'pretty-format';
7
+
8
+ declare class StateManager {
9
+ filesMap: Record<string, File>;
10
+ idMap: Record<string, Task>;
11
+ taskFileMap: WeakMap<Task, File>;
12
+ getFiles(keys?: string[]): File[];
13
+ collectFiles(files: File[]): void;
14
+ updateId(task: Task): void;
15
+ updateTasks(packs: TaskResultPack[]): void;
16
+ }
17
+
18
+ declare class SnapshotManager {
19
+ config: ResolvedConfig;
20
+ summary: SnapshotSummary;
21
+ constructor(config: ResolvedConfig);
22
+ clear(): void;
23
+ add(result: SnapshotResult): void;
24
+ }
25
+
26
+ declare type Awaitable<T> = T | PromiseLike<T>;
27
+ declare type Nullable<T> = T | null | undefined;
28
+ declare type Arrayable<T> = T | Array<T>;
29
+ interface ModuleCache {
30
+ promise?: Promise<any>;
31
+ exports?: any;
32
+ transformResult?: TransformResult;
33
+ }
34
+ interface EnvironmentReturn {
35
+ teardown: (global: any) => Awaitable<void>;
36
+ }
37
+ interface Environment {
38
+ name: string;
39
+ setup(global: any): Awaitable<EnvironmentReturn>;
40
+ }
41
+ interface VitestContext {
42
+ config: ResolvedConfig;
43
+ server: ViteDevServer;
44
+ state: StateManager;
45
+ snapshot: SnapshotManager;
46
+ reporter: Reporter;
47
+ }
48
+
49
+ declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
50
+ declare type TaskState = RunMode | 'pass' | 'fail';
51
+ declare type ComputeMode = 'serial' | 'concurrent';
52
+ interface TaskBase {
53
+ id: string;
54
+ name: string;
55
+ mode: RunMode;
56
+ computeMode: ComputeMode;
57
+ suite?: Suite;
58
+ file?: File;
59
+ result?: TaskResult;
60
+ }
61
+ interface TaskResult {
62
+ state: TaskState;
63
+ start: number;
64
+ end?: number;
65
+ error?: unknown;
66
+ }
67
+ declare type TaskResultPack = [id: string, result: TaskResult | undefined];
68
+ interface Suite extends TaskBase {
69
+ type: 'suite';
70
+ tasks: Task[];
71
+ }
72
+ interface File extends Suite {
73
+ filepath: string;
74
+ }
75
+ interface Test extends TaskBase {
76
+ type: 'test';
77
+ suite: Suite;
78
+ result?: TaskResult;
79
+ }
80
+ declare type Task = Test | Suite | File;
81
+ declare type TestFunction = () => Awaitable<void>;
82
+ declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
83
+ interface ConcurrentCollector {
84
+ (name: string, fn: TestFunction, timeout?: number): void;
85
+ only: TestCollectorFn;
86
+ skip: TestCollectorFn;
87
+ todo: (name: string) => void;
88
+ }
89
+ interface OnlyCollector {
90
+ (name: string, fn: TestFunction, timeout?: number): void;
91
+ concurrent: TestCollectorFn;
92
+ }
93
+ interface SkipCollector {
94
+ (name: string, fn: TestFunction, timeout?: number): void;
95
+ concurrent: TestCollectorFn;
96
+ }
97
+ interface TodoCollector {
98
+ (name: string): void;
99
+ concurrent: (name: string) => void;
100
+ }
101
+ interface TestCollector {
102
+ (name: string, fn: TestFunction, timeout?: number): void;
103
+ concurrent: ConcurrentCollector;
104
+ only: OnlyCollector;
105
+ skip: SkipCollector;
106
+ todo: TodoCollector;
107
+ }
108
+ declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
109
+ interface SuiteHooks {
110
+ beforeAll: HookListener<[Suite]>[];
111
+ afterAll: HookListener<[Suite]>[];
112
+ beforeEach: HookListener<[Test, Suite]>[];
113
+ afterEach: HookListener<[Test, Suite]>[];
114
+ }
115
+ interface SuiteCollector {
116
+ readonly name: string;
117
+ readonly mode: RunMode;
118
+ type: 'collector';
119
+ test: TestCollector;
120
+ tasks: (Suite | Test | SuiteCollector)[];
121
+ collect: (file?: File) => Promise<Suite>;
122
+ clear: () => void;
123
+ on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
124
+ }
125
+ declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
126
+ interface GlobalContext {
127
+ tasks: (SuiteCollector | Test)[];
128
+ currentSuite: SuiteCollector | null;
129
+ }
130
+
131
+ interface Reporter {
132
+ onStart?: (files?: string[]) => Awaitable<void>;
133
+ onFinished?: (files?: File[]) => Awaitable<void>;
134
+ onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
135
+ onWatcherStart?: () => Awaitable<void>;
136
+ onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
137
+ }
138
+
139
+ declare type SnapshotData = Record<string, string>;
140
+ declare type SnapshotUpdateState = 'all' | 'new' | 'none';
141
+ declare type SnapshotStateOptions = {
142
+ updateSnapshot: SnapshotUpdateState;
143
+ expand?: boolean;
144
+ snapshotFormat?: OptionsReceived;
145
+ };
146
+ declare type SnapshotMatchOptions = {
147
+ testName: string;
148
+ received: unknown;
149
+ key?: string;
150
+ inlineSnapshot?: string;
151
+ isInline: boolean;
152
+ error?: Error;
153
+ };
154
+ interface SnapshotResult {
155
+ filepath: string;
156
+ added: number;
157
+ fileDeleted: boolean;
158
+ matched: number;
159
+ unchecked: number;
160
+ uncheckedKeys: Array<string>;
161
+ unmatched: number;
162
+ updated: number;
163
+ }
164
+ interface UncheckedSnapshot {
165
+ filePath: string;
166
+ keys: Array<string>;
167
+ }
168
+ interface SnapshotSummary {
169
+ added: number;
170
+ didUpdate: boolean;
171
+ failure: boolean;
172
+ filesAdded: number;
173
+ filesRemoved: number;
174
+ filesRemovedList: Array<string>;
175
+ filesUnmatched: number;
176
+ filesUpdated: number;
177
+ matched: number;
178
+ total: number;
179
+ unchecked: number;
180
+ uncheckedKeysByFile: Array<UncheckedSnapshot>;
181
+ unmatched: number;
182
+ updated: number;
183
+ }
184
+
185
+ interface UserOptions {
186
+ /**
187
+ * Include globs for test files
188
+ *
189
+ * @default ['**\/*.test.ts']
190
+ */
191
+ includes?: string[];
192
+ /**
193
+ * Exclude globs for test files
194
+ * @default ['**\/node_modules\/**']
195
+ */
196
+ excludes?: string[];
197
+ /**
198
+ * Handling for dependencies inlining or externalizing
199
+ */
200
+ deps?: {
201
+ /**
202
+ * Externalize means that Vite will bypass the package to native Node.
203
+ *
204
+ * Externaled dependencies will not be applied Vite's transformers and resolvers.
205
+ * And does not support HMR on reload.
206
+ *
207
+ * Typically, packages under `node_modules` are externalized.
208
+ */
209
+ external?: (string | RegExp)[];
210
+ /**
211
+ * Vite will process inlined modules.
212
+ *
213
+ * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
214
+ */
215
+ inline?: (string | RegExp)[];
216
+ };
217
+ /**
218
+ * Register apis globally
219
+ *
220
+ * @default false
221
+ */
222
+ global?: boolean;
223
+ /**
224
+ * Running environment
225
+ *
226
+ * Supports 'node', 'jsdom', 'happy-dom'
227
+ *
228
+ * @default 'node'
229
+ */
230
+ environment?: 'node' | 'jsdom' | 'happy-dom';
231
+ /**
232
+ * Update snapshot files
233
+ *
234
+ * @default false
235
+ */
236
+ update?: boolean;
237
+ /**
238
+ * Watch mode
239
+ *
240
+ * @default false
241
+ */
242
+ watch?: boolean;
243
+ /**
244
+ * Project root
245
+ */
246
+ root?: string;
247
+ /**
248
+ * Custom reporter for output
249
+ */
250
+ reporter?: Reporter;
251
+ /**
252
+ * Enable multi-threading
253
+ *
254
+ * @default true
255
+ */
256
+ threads?: boolean;
257
+ /**
258
+ * Maximum number of threads
259
+ *
260
+ * @default available CPUs
261
+ */
262
+ maxThreads?: number;
263
+ /**
264
+ * Minimum number of threads
265
+ *
266
+ * @default available CPUs
267
+ */
268
+ minThreads?: number;
269
+ interpretDefault?: boolean;
270
+ testTimeout?: number;
271
+ hookTimeout?: number;
272
+ }
273
+ interface CliOptions extends UserOptions {
274
+ /**
275
+ * Filters by name
276
+ */
277
+ cliFilters?: string[];
278
+ /**
279
+ * Path to the config file.
280
+ *
281
+ * Default resolving to one of:
282
+ * - `vitest.config.js`
283
+ * - `vitest.config.ts`
284
+ * - `vite.config.js`
285
+ * - `vite.config.ts`
286
+ */
287
+ config?: string | undefined;
288
+ dom?: boolean;
289
+ }
290
+ interface ResolvedConfig extends Omit<Required<CliOptions>, 'config' | 'filters'> {
291
+ config?: string;
292
+ filters?: string[];
293
+ depsInline: (string | RegExp)[];
294
+ depsExternal: (string | RegExp)[];
295
+ snapshotOptions: SnapshotStateOptions;
296
+ }
9
297
 
10
298
  interface WorkerContext {
11
299
  port: MessagePort;
@@ -127,6 +415,17 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
127
415
  declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
128
416
  declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
129
417
  declare function clearContext(): void;
418
+ declare global {
419
+ namespace NodeJS {
420
+ interface Process {
421
+ __vitest_worker__: {
422
+ config: ResolvedConfig;
423
+ rpc: RpcCall;
424
+ send: RpcSend;
425
+ };
426
+ }
427
+ }
428
+ }
130
429
 
131
430
  declare const mock: sinon.SinonMockStatic;
132
431
  declare const spy: sinon.SinonSpyStatic;
@@ -192,4 +491,4 @@ declare global {
192
491
  }
193
492
  }
194
493
 
195
- export { RpcCall, RpcMap, RpcPayload, RpcSend, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, clearContext, createSuiteHooks, defaultSuite, describe, it, mock, spy, stub, suite, test };
494
+ export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, GlobalContext, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, clearContext, createSuiteHooks, defaultSuite, describe, it, mock, spy, stub, suite, test };
package/dist/index.js CHANGED
@@ -1,46 +1,5 @@
1
- import {
2
- assert,
3
- chai,
4
- expect,
5
- mock,
6
- should,
7
- sinon,
8
- spy,
9
- stub
10
- } from "./chunk-YPKHVZRP.js";
11
- import {
12
- afterAll,
13
- afterEach,
14
- beforeAll,
15
- beforeEach,
16
- clearContext,
17
- createSuiteHooks,
18
- defaultSuite,
19
- describe,
20
- it,
21
- suite,
22
- test
23
- } from "./chunk-ANPMHBIF.js";
24
- import "./chunk-APGELTDH.js";
25
- import "./chunk-R2SMNEBL.js";
26
- export {
27
- afterAll,
28
- afterEach,
29
- assert,
30
- beforeAll,
31
- beforeEach,
32
- chai,
33
- clearContext,
34
- createSuiteHooks,
35
- defaultSuite,
36
- describe,
37
- expect,
38
- it,
39
- mock,
40
- should,
41
- sinon,
42
- spy,
43
- stub,
44
- suite,
45
- test
46
- };
1
+ export { e as afterAll, g as afterEach, b as beforeAll, f as beforeEach, h as clearContext, c as createSuiteHooks, d as defaultSuite, a as describe, i as it, s as suite, t as test } from './suite-819c135e.js';
2
+ export { assert, default as chai, expect, should } from 'chai';
3
+ export { m as mock, s as spy, a as stub } from './index-e37648e9.js';
4
+ export { default as sinon } from 'sinon';
5
+ import './index-6427e0f2.js';
@@ -1,24 +1,12 @@
1
- import {
2
- nanoid
3
- } from "./chunk-APGELTDH.js";
4
- import {
5
- init_esm_shims
6
- } from "./chunk-R2SMNEBL.js";
1
+ import { n as nanoid } from './index-6427e0f2.js';
7
2
 
8
- // src/runtime/suite.ts
9
- init_esm_shims();
10
-
11
- // src/runtime/context.ts
12
- init_esm_shims();
13
- var context = {
3
+ const context = {
14
4
  tasks: [],
15
5
  currentSuite: null
16
6
  };
17
7
 
18
- // src/runtime/map.ts
19
- init_esm_shims();
20
- var fnMap = new WeakMap();
21
- var hooksMap = new WeakMap();
8
+ const fnMap = new WeakMap();
9
+ const hooksMap = new WeakMap();
22
10
  function setFn(key, fn) {
23
11
  fnMap.set(key, fn);
24
12
  }
@@ -32,17 +20,16 @@ function getHooks(key) {
32
20
  return hooksMap.get(key);
33
21
  }
34
22
 
35
- // src/runtime/suite.ts
36
- var suite = createSuite();
37
- var defaultSuite = suite("");
23
+ const suite = createSuite();
24
+ const defaultSuite = suite("");
38
25
  function getCurrentSuite() {
39
26
  return context.currentSuite || defaultSuite;
40
27
  }
41
- var getDefaultTestTimeout = () => {
28
+ const getDefaultTestTimeout = () => {
42
29
  var _a, _b;
43
30
  return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.testTimeout) ?? 5e3;
44
31
  };
45
- var getDefaultHookTimeout = () => {
32
+ const getDefaultHookTimeout = () => {
46
33
  var _a, _b;
47
34
  return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.hookTimeout) ?? 5e3;
48
35
  };
@@ -152,7 +139,7 @@ function createTestCollector(collectTest) {
152
139
  todo.concurrent = todo;
153
140
  return test2;
154
141
  }
155
- var test = function() {
142
+ const test = function() {
156
143
  function test2(name, fn, timeout) {
157
144
  return getCurrentSuite().test(name, fn, timeout);
158
145
  }
@@ -208,12 +195,12 @@ function createSuite() {
208
195
  suite2.todo = todo;
209
196
  return suite2;
210
197
  }
211
- var describe = suite;
212
- var it = test;
213
- var beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
214
- var afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
215
- var beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
216
- var afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
198
+ const describe = suite;
199
+ const it = test;
200
+ const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
201
+ const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
202
+ const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
203
+ const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
217
204
  function clearContext() {
218
205
  context.tasks.length = 0;
219
206
  defaultSuite.clear();
@@ -234,20 +221,4 @@ function withTimeout(fn, _timeout) {
234
221
  };
235
222
  }
236
223
 
237
- export {
238
- context,
239
- getFn,
240
- setHooks,
241
- getHooks,
242
- suite,
243
- defaultSuite,
244
- createSuiteHooks,
245
- test,
246
- describe,
247
- it,
248
- beforeAll,
249
- afterAll,
250
- beforeEach,
251
- afterEach,
252
- clearContext
253
- };
224
+ export { describe as a, beforeAll as b, createSuiteHooks as c, defaultSuite as d, afterAll as e, beforeEach as f, afterEach as g, clearContext as h, it as i, setHooks as j, context as k, getHooks as l, getFn as m, suite as s, test as t };
@@ -1,9 +1,3 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-R2SMNEBL.js";
4
-
5
- // src/utils.ts
6
- init_esm_shims();
7
1
  function toArray(array) {
8
2
  array = array || [];
9
3
  if (Array.isArray(array))
@@ -67,15 +61,4 @@ function getNames(task) {
67
61
  return names;
68
62
  }
69
63
 
70
- export {
71
- toArray,
72
- notNullish,
73
- slash,
74
- partitionSuiteChildren,
75
- interpretOnlyMode,
76
- getTests,
77
- getSuites,
78
- hasTests,
79
- hasFailed,
80
- getNames
81
- };
64
+ export { getTests as a, getSuites as b, hasTests as c, getNames as g, hasFailed as h, interpretOnlyMode as i, notNullish as n, partitionSuiteChildren as p, slash as s, toArray as t };