vitest 0.0.79 → 0.0.83

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,14 +1,16 @@
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-95be5909.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-0e21bf9b.js';
2
2
  import chai, { assert, should, expect } from 'chai';
3
- import sinon from 'sinon';
3
+ import { spyOn, spy } from 'tinyspy';
4
4
 
5
5
  const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
6
6
  const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
7
7
  const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
8
8
  const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
9
9
 
10
- const { mock, spy, stub } = sinon;
11
- sinon.fn = sinon.spy;
10
+ const vitest = {
11
+ spyOn,
12
+ fn: spy
13
+ };
12
14
 
13
15
  var index = /*#__PURE__*/Object.freeze({
14
16
  __proto__: null,
@@ -24,10 +26,9 @@ var index = /*#__PURE__*/Object.freeze({
24
26
  should: should,
25
27
  expect: expect,
26
28
  chai: chai,
27
- sinon: sinon,
28
- mock: mock,
29
29
  spy: spy,
30
- stub: stub
30
+ spyOn: spyOn,
31
+ vitest: vitest
31
32
  });
32
33
 
33
- export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, stub as e, index as i, mock as m, spy as s };
34
+ export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, index as i, vitest as v };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Formatter } from 'picocolors/types';
2
- import { TransformResult, ViteDevServer } from 'vite';
2
+ import { TransformResult } from 'vite';
3
3
  import { OptionsReceived } from 'pretty-format';
4
4
  import { MessagePort } from 'worker_threads';
5
5
  export { assert, default as chai, expect, should } from 'chai';
6
- import sinon from 'sinon';
7
- export { default as sinon } from 'sinon';
6
+ import { spyOn, spy } from 'tinyspy';
7
+ export { spy, spyOn } from 'tinyspy';
8
8
 
9
9
  declare const EXPECTED_COLOR: Formatter;
10
10
  declare const RECEIVED_COLOR: Formatter;
@@ -110,27 +110,10 @@ declare type MatchersObject<T extends MatcherState = MatcherState> = {
110
110
  [id: string]: RawMatcherFn<T>;
111
111
  };
112
112
 
113
- declare class StateManager {
114
- filesMap: Record<string, File>;
115
- idMap: Record<string, Task>;
116
- taskFileMap: WeakMap<Task, File>;
117
- getFiles(keys?: string[]): File[];
118
- collectFiles(files: File[]): void;
119
- updateId(task: Task): void;
120
- updateTasks(packs: TaskResultPack[]): void;
121
- }
122
-
123
- declare class SnapshotManager {
124
- config: ResolvedConfig;
125
- summary: SnapshotSummary;
126
- constructor(config: ResolvedConfig);
127
- clear(): void;
128
- add(result: SnapshotResult): void;
129
- }
130
-
131
113
  declare type Awaitable<T> = T | PromiseLike<T>;
132
114
  declare type Nullable<T> = T | null | undefined;
133
115
  declare type Arrayable<T> = T | Array<T>;
116
+ declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
134
117
  interface ModuleCache {
135
118
  promise?: Promise<any>;
136
119
  exports?: any;
@@ -143,14 +126,6 @@ interface Environment {
143
126
  name: string;
144
127
  setup(global: any): Awaitable<EnvironmentReturn>;
145
128
  }
146
- interface VitestContext {
147
- config: ResolvedConfig;
148
- server: ViteDevServer;
149
- state: StateManager;
150
- snapshot: SnapshotManager;
151
- reporters: Reporter[];
152
- console: Console;
153
- }
154
129
  interface UserConsoleLog {
155
130
  content: string;
156
131
  type: 'stdout' | 'stderr';
@@ -189,7 +164,8 @@ interface Test extends TaskBase {
189
164
  result?: TaskResult;
190
165
  }
191
166
  declare type Task = Test | Suite | File;
192
- declare type TestFunction = () => Awaitable<void>;
167
+ declare type DoneCallback = (error?: any) => void;
168
+ declare type TestFunction = (done: DoneCallback) => Awaitable<void>;
193
169
  declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
194
170
  interface ConcurrentCollector {
195
171
  (name: string, fn: TestFunction, timeout?: number): void;
@@ -294,18 +270,18 @@ interface SnapshotSummary {
294
270
  updated: number;
295
271
  }
296
272
 
297
- interface UserOptions {
273
+ interface InlineConfig {
298
274
  /**
299
275
  * Include globs for test files
300
276
  *
301
277
  * @default ['**\/*.test.ts']
302
278
  */
303
- includes?: string[];
279
+ include?: string[];
304
280
  /**
305
281
  * Exclude globs for test files
306
282
  * @default ['**\/node_modules\/**']
307
283
  */
308
- excludes?: string[];
284
+ exclude?: string[];
309
285
  /**
310
286
  * Handling for dependencies inlining or externalizing
311
287
  */
@@ -313,7 +289,7 @@ interface UserOptions {
313
289
  /**
314
290
  * Externalize means that Vite will bypass the package to native Node.
315
291
  *
316
- * Externaled dependencies will not be applied Vite's transformers and resolvers.
292
+ * Externalized dependencies will not be applied Vite's transformers and resolvers.
317
293
  * And does not support HMR on reload.
318
294
  *
319
295
  * Typically, packages under `node_modules` are externalized.
@@ -397,28 +373,26 @@ interface UserOptions {
397
373
  * @default false
398
374
  */
399
375
  silent?: boolean;
400
- /**
401
- * Open Vitest UI
402
- */
403
- open?: boolean;
404
376
  /**
405
377
  * Path to setup files
406
378
  */
407
379
  setupFiles?: string | string[];
380
+ /**
381
+ * Open Vitest UI
382
+ * @internal WIP
383
+ */
384
+ open?: boolean;
408
385
  /**
409
386
  * Listen to port and serve API
410
387
  *
411
- * When set to try, the default port is 55555
388
+ * When set to true, the default port is 55555
412
389
  *
390
+ * @internal WIP
413
391
  * @default false
414
392
  */
415
393
  api?: boolean | number;
416
394
  }
417
- interface CliOptions extends UserOptions {
418
- /**
419
- * Filters by name
420
- */
421
- cliFilters?: string[];
395
+ interface UserConfig extends InlineConfig {
422
396
  /**
423
397
  * Path to the config file.
424
398
  *
@@ -431,7 +405,7 @@ interface CliOptions extends UserOptions {
431
405
  config?: string | undefined;
432
406
  dom?: boolean;
433
407
  }
434
- interface ResolvedConfig extends Omit<Required<CliOptions>, 'config' | 'filters'> {
408
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'> {
435
409
  config?: string;
436
410
  filters?: string[];
437
411
  depsInline: (string | RegExp)[];
@@ -567,16 +541,17 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
567
541
  declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
568
542
  declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
569
543
 
570
- declare const mock: sinon.SinonMockStatic;
571
- declare const spy: sinon.SinonSpyStatic;
572
- declare const stub: sinon.SinonStubStatic;
544
+ declare const vitest: {
545
+ spyOn: typeof spyOn;
546
+ fn: typeof spy;
547
+ };
573
548
 
574
549
  declare module 'vite' {
575
550
  interface UserConfig {
576
551
  /**
577
552
  * Options for Vitest
578
553
  */
579
- test?: UserOptions;
554
+ test?: InlineConfig;
580
555
  }
581
556
  }
582
557
  declare global {
@@ -636,4 +611,4 @@ declare global {
636
611
  }
637
612
  }
638
613
 
639
- export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConsoleLog, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, mock, spy, stub, suite, test };
614
+ export { ArgumentsType, Arrayable, Awaitable, ComputeMode, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, suite, test, vitest };
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-95be5909.js';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, m as mock, s as spy, e as stub } from './index-6feda5ef.js';
1
+ export { d as describe, i as it, s as suite, t as test } from './suite-0e21bf9b.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-906ac3f9.js';
3
3
  export { assert, default as chai, expect, should } from 'chai';
4
- export { default as sinon } from 'sinon';
4
+ export { spy, spyOn } from 'tinyspy';
5
5
  import './index-9e71c815.js';
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'flatted';
2
- import { A as API_PATH } from './constants-2435fa16.js';
2
+ import { A as API_PATH } from './constants-adef7ffb.js';
3
3
  import 'path';
4
4
  import 'url';
5
5
 
package/dist/node.js ADDED
@@ -0,0 +1,19 @@
1
+ export { c as createVitest } from './index-6c8eed3e.js';
2
+ import 'path';
3
+ import 'vite';
4
+ import 'process';
5
+ import 'fs';
6
+ import './constants-adef7ffb.js';
7
+ import 'url';
8
+ import './utils-9dcc4050.js';
9
+ import 'perf_hooks';
10
+ import './error-a65fcd00.js';
11
+ import 'tty';
12
+ import 'source-map';
13
+ import 'assert';
14
+ import 'events';
15
+ import 'worker_threads';
16
+ import 'piscina';
17
+ import 'fast-glob';
18
+ import 'micromatch';
19
+ import 'readline';
@@ -36,6 +36,17 @@ function withTimeout(fn, _timeout) {
36
36
  })]);
37
37
  };
38
38
  }
39
+ function ensureAsyncTest(fn) {
40
+ if (!fn.length)
41
+ return fn;
42
+ return () => new Promise((resolve, reject) => {
43
+ const done = (...args) => args[0] ? reject(args[0]) : resolve();
44
+ fn(done);
45
+ });
46
+ }
47
+ function normalizeTest(fn, timeout) {
48
+ return withTimeout(ensureAsyncTest(fn), timeout);
49
+ }
39
50
 
40
51
  const fnMap = new WeakMap();
41
52
  const hooksMap = new WeakMap();
@@ -136,24 +147,24 @@ function createSuiteCollector(name, factory = () => {
136
147
  }
137
148
  function createTestCollector(collectTest) {
138
149
  function test2(name, fn, timeout) {
139
- collectTest(name, withTimeout(fn, timeout), "run");
150
+ collectTest(name, normalizeTest(fn, timeout), "run");
140
151
  }
141
152
  test2.concurrent = concurrent;
142
153
  test2.skip = skip;
143
154
  test2.only = only;
144
155
  test2.todo = todo;
145
156
  function concurrent(name, fn, timeout) {
146
- collectTest(name, withTimeout(fn, timeout), "run", "concurrent");
157
+ collectTest(name, normalizeTest(fn, timeout), "run", "concurrent");
147
158
  }
148
- concurrent.skip = (name, fn, timeout) => collectTest(name, withTimeout(fn, timeout), "skip", "concurrent");
149
- concurrent.only = (name, fn, timeout) => collectTest(name, withTimeout(fn, timeout), "only", "concurrent");
159
+ concurrent.skip = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "skip", "concurrent");
160
+ concurrent.only = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "only", "concurrent");
150
161
  concurrent.todo = todo;
151
162
  function skip(name, fn, timeout) {
152
- collectTest(name, withTimeout(fn, timeout), "skip");
163
+ collectTest(name, normalizeTest(fn, timeout), "skip");
153
164
  }
154
165
  skip.concurrent = concurrent.skip;
155
166
  function only(name, fn, timeout) {
156
- collectTest(name, withTimeout(fn, timeout), "only");
167
+ collectTest(name, normalizeTest(fn, timeout), "only");
157
168
  }
158
169
  only.concurrent = concurrent.only;
159
170
  function todo(name) {
package/dist/worker.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve, dirname } from 'path';
2
2
  import { n as nanoid } from './index-9e71c815.js';
3
- import { e as distDir } from './constants-2435fa16.js';
3
+ import { c as distDir } from './constants-adef7ffb.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath } from 'url';
6
6
  import vm from 'vm';
@@ -100,6 +100,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
100
100
  const __filename = fileURLToPath(url);
101
101
  const context = {
102
102
  require: createRequire(url),
103
+ exports,
103
104
  __filename,
104
105
  __dirname: dirname(__filename),
105
106
  __vite_ssr_import__: request,
package/global.d.ts CHANGED
@@ -5,10 +5,9 @@ declare global {
5
5
  const it: typeof import('vitest')['it']
6
6
  const expect: typeof import('vitest')['expect']
7
7
  const assert: typeof import('vitest')['assert']
8
- const sinon: typeof import('vitest')['sinon']
9
8
  const spy: typeof import('vitest')['spy']
10
- const mock: typeof import('vitest')['mock']
11
- const stub: typeof import('vitest')['stub']
9
+ const spyOn: typeof import('vitest')['spyOn']
10
+ const vitest: typeof import('vitest')['vitest']
12
11
  const beforeAll: typeof import('vitest')['beforeAll']
13
12
  const afterAll: typeof import('vitest')['afterAll']
14
13
  const beforeEach: typeof import('vitest')['beforeEach']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.79",
3
+ "version": "0.0.83",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -25,6 +25,13 @@
25
25
  "import": "./dist/index.js",
26
26
  "types": "./dist/index.d.ts"
27
27
  },
28
+ "./node": {
29
+ "import": "./dist/node.js",
30
+ "types": "./dist/node.d.ts"
31
+ },
32
+ "./global": {
33
+ "types": "./global.d.ts"
34
+ },
28
35
  "./*": "./*"
29
36
  },
30
37
  "main": "./dist/index.js",
@@ -41,8 +48,6 @@
41
48
  "dependencies": {
42
49
  "@types/chai": "^4.3.0",
43
50
  "@types/chai-subset": "^1.3.3",
44
- "@types/sinon": "^10.0.6",
45
- "@types/sinon-chai": "^3.2.6",
46
51
  "chai": "^4.3.4",
47
52
  "chai-subset": "^1.6.0",
48
53
  "fast-glob": "^3.2.7",
@@ -50,9 +55,8 @@
50
55
  "local-pkg": "^0.4.0",
51
56
  "micromatch": "^4.0.4",
52
57
  "piscina": "^3.2.0",
53
- "sinon": "^12.0.1",
54
- "sinon-chai": "^3.7.0",
55
- "source-map": "^0.7.3"
58
+ "source-map": "^0.7.3",
59
+ "tinyspy": "^0.0.13"
56
60
  },
57
61
  "devDependencies": {
58
62
  "@types/diff": "^5.0.1",
@@ -72,6 +76,7 @@
72
76
  "natural-compare": "^1.4.0",
73
77
  "picocolors": "^1.0.0",
74
78
  "pretty-format": "^27.4.2",
79
+ "rollup": "^2.61.1",
75
80
  "strip-ansi": "^7.0.1"
76
81
  },
77
82
  "peerDependencies": {