vitest 0.0.78 → 0.0.82

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/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
- reporter: Reporter;
152
- console: Console;
153
- }
154
129
  interface UserConsoleLog {
155
130
  content: string;
156
131
  type: 'stdout' | 'stderr';
@@ -294,18 +269,18 @@ interface SnapshotSummary {
294
269
  updated: number;
295
270
  }
296
271
 
297
- interface UserOptions {
272
+ interface InlineConfig$1 {
298
273
  /**
299
274
  * Include globs for test files
300
275
  *
301
276
  * @default ['**\/*.test.ts']
302
277
  */
303
- includes?: string[];
278
+ include?: string[];
304
279
  /**
305
280
  * Exclude globs for test files
306
281
  * @default ['**\/node_modules\/**']
307
282
  */
308
- excludes?: string[];
283
+ exclude?: string[];
309
284
  /**
310
285
  * Handling for dependencies inlining or externalizing
311
286
  */
@@ -313,7 +288,7 @@ interface UserOptions {
313
288
  /**
314
289
  * Externalize means that Vite will bypass the package to native Node.
315
290
  *
316
- * Externaled dependencies will not be applied Vite's transformers and resolvers.
291
+ * Externalized dependencies will not be applied Vite's transformers and resolvers.
317
292
  * And does not support HMR on reload.
318
293
  *
319
294
  * Typically, packages under `node_modules` are externalized.
@@ -359,7 +334,7 @@ interface UserOptions {
359
334
  /**
360
335
  * Custom reporter for output
361
336
  */
362
- reporter?: Reporter;
337
+ reporters?: Reporter | Reporter[];
363
338
  /**
364
339
  * Enable multi-threading
365
340
  *
@@ -397,28 +372,26 @@ interface UserOptions {
397
372
  * @default false
398
373
  */
399
374
  silent?: boolean;
400
- /**
401
- * Open Vitest UI
402
- */
403
- open?: boolean;
404
375
  /**
405
376
  * Path to setup files
406
377
  */
407
378
  setupFiles?: string | string[];
379
+ /**
380
+ * Open Vitest UI
381
+ * @internal WIP
382
+ */
383
+ open?: boolean;
408
384
  /**
409
385
  * Listen to port and serve API
410
386
  *
411
- * When set to try, the default port is 55555
387
+ * When set to true, the default port is 55555
412
388
  *
389
+ * @internal WIP
413
390
  * @default false
414
391
  */
415
392
  api?: boolean | number;
416
393
  }
417
- interface CliOptions extends UserOptions {
418
- /**
419
- * Filters by name
420
- */
421
- cliFilters?: string[];
394
+ interface UserConfig extends InlineConfig$1 {
422
395
  /**
423
396
  * Path to the config file.
424
397
  *
@@ -431,7 +404,7 @@ interface CliOptions extends UserOptions {
431
404
  config?: string | undefined;
432
405
  dom?: boolean;
433
406
  }
434
- interface ResolvedConfig extends Omit<Required<CliOptions>, 'config' | 'filters'> {
407
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'> {
435
408
  config?: string;
436
409
  filters?: string[];
437
410
  depsInline: (string | RegExp)[];
@@ -448,6 +421,7 @@ interface WorkerContext {
448
421
  interface RpcMap {
449
422
  fetch: [[id: string], TransformResult | null | undefined];
450
423
  log: [[UserConsoleLog], void];
424
+ processExit: [[code?: number], void];
451
425
  onCollected: [[files: File[]], void];
452
426
  onFinished: [[], void];
453
427
  onTaskUpdate: [[pack: TaskResultPack], void];
@@ -566,16 +540,17 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
566
540
  declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
567
541
  declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
568
542
 
569
- declare const mock: sinon.SinonMockStatic;
570
- declare const spy: sinon.SinonSpyStatic;
571
- declare const stub: sinon.SinonStubStatic;
543
+ declare const vitest: {
544
+ spyOn: typeof spyOn;
545
+ fn: typeof spy;
546
+ };
572
547
 
573
548
  declare module 'vite' {
574
549
  interface UserConfig {
575
550
  /**
576
551
  * Options for Vitest
577
552
  */
578
- test?: UserOptions;
553
+ test?: InlineConfig;
579
554
  }
580
555
  }
581
556
  declare global {
@@ -635,4 +610,4 @@ declare global {
635
610
  }
636
611
  }
637
612
 
638
- 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 };
613
+ export { ArgumentsType, Arrayable, Awaitable, ComputeMode, Environment, EnvironmentReturn, File, HookListener, InlineConfig$1 as 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
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';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-16a06164.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-9a2ee1fc.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-dd23da12.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';
@@ -0,0 +1,10 @@
1
+ const rpc = async (method, ...args) => {
2
+ var _a;
3
+ return (_a = process.__vitest_worker__) == null ? void 0 : _a.rpc(method, ...args);
4
+ };
5
+ const send = async (method, ...args) => {
6
+ var _a;
7
+ return (_a = process.__vitest_worker__) == null ? void 0 : _a.send(method, ...args);
8
+ };
9
+
10
+ export { rpc as r, send as s };
package/dist/worker.js CHANGED
@@ -1,10 +1,11 @@
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';
7
7
  import { s as slash } from './utils-9dcc4050.js';
8
+ import { s as send } from './rpc-7de86f29.js';
8
9
 
9
10
  const defaultInline = [
10
11
  "vitest/dist",
@@ -208,6 +209,14 @@ const moduleCache = new Map();
208
209
  async function init(ctx) {
209
210
  if (_run)
210
211
  return _run;
212
+ const processExit = process.exit;
213
+ process.on("beforeExit", (code) => {
214
+ send("processExit", code);
215
+ });
216
+ process.exit = (code = process.exitCode || 0) => {
217
+ send("processExit", code);
218
+ return processExit(code);
219
+ };
211
220
  const { config } = ctx;
212
221
  _run = (await executeInViteNode({
213
222
  root: config.root,
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.78",
3
+ "version": "0.0.82",
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",