vitest 0.15.2 → 0.16.0

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,5 +1,5 @@
1
1
  import { promises } from 'fs';
2
- import { c as createBirpc } from './chunk-vite-node-utils.1bbdb2c1.mjs';
2
+ import { c as createBirpc } from './chunk-vite-node-utils.7450fc0c.mjs';
3
3
  import require$$0$1 from 'stream';
4
4
  import require$$0 from 'zlib';
5
5
  import require$$3 from 'net';
@@ -1,4 +1,4 @@
1
- import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.1bbdb2c1.mjs';
1
+ import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.7450fc0c.mjs';
2
2
  import { normalizePath } from 'vite';
3
3
  import { a as getWorkerState, J as isWindows, K as mergeSlashes, d as dirname, m as resolve, l as basename, L as getType, M as getAllProperties, s as slash } from './chunk-utils-global.79a8b1cc.mjs';
4
4
  import { existsSync, readdirSync } from 'fs';
@@ -12,7 +12,7 @@ import require$$0$1 from 'util';
12
12
  import require$$0$2 from 'stream';
13
13
  import require$$2 from 'events';
14
14
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
15
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.1bbdb2c1.mjs';
15
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.7450fc0c.mjs';
16
16
  import createDebug from 'debug';
17
17
  import { MessageChannel } from 'worker_threads';
18
18
  import { createHash } from 'crypto';
@@ -26,7 +26,7 @@ import childProcess from 'child_process';
26
26
  import MagicString from './chunk-magic-string.efe26975.mjs';
27
27
  import { p as prompts } from './vendor-index.98e769c1.mjs';
28
28
 
29
- var version = "0.15.2";
29
+ var version = "0.16.0";
30
30
 
31
31
  class EndError extends Error {
32
32
  constructor(value) {
@@ -7054,8 +7054,7 @@ function createPool(ctx) {
7054
7054
  config,
7055
7055
  files,
7056
7056
  invalidates,
7057
- workerId,
7058
- poolId: !ctx.config.threads ? 1 : (workerId - 1) % maxThreads + 1
7057
+ workerId
7059
7058
  };
7060
7059
  try {
7061
7060
  await pool.run(data, { transferList: [workerPort], name });
@@ -10937,7 +10936,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10937
10936
  await ctx.setServer(options, server);
10938
10937
  haveStarted = true;
10939
10938
  if (options.api && options.watch)
10940
- (await import('./chunk-api-setup.8cd5e92a.mjs')).setup(ctx);
10939
+ (await import('./chunk-api-setup.f43cd039.mjs')).setup(ctx);
10941
10940
  } catch (err) {
10942
10941
  ctx.printError(err, true);
10943
10942
  process.exit(1);
@@ -8851,7 +8851,7 @@ function mergeSlashes(str) {
8851
8851
  function normalizeRequestId(id, base) {
8852
8852
  if (base && id.startsWith(base))
8853
8853
  id = `/${id.slice(base.length)}`;
8854
- return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?+$/, "");
8854
+ return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
8855
8855
  }
8856
8856
  function normalizeModuleId(id) {
8857
8857
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
@@ -8860,7 +8860,7 @@ function isPrimitive(v) {
8860
8860
  return v !== Object(v);
8861
8861
  }
8862
8862
  function toFilePath(id, root) {
8863
- let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$2(root)) && dirname$2(root) !== "/" ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
8863
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(root) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
8864
8864
  if (absolute.startsWith("//"))
8865
8865
  absolute = absolute.slice(1);
8866
8866
  return isWindows && absolute.startsWith("/") ? fileURLToPath$2(pathToFileURL(absolute.slice(1)).href) : absolute;
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { p as picocolors } from './chunk-utils-global.79a8b1cc.mjs';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.0ec89ad1.mjs';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.58e10976.mjs';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
@@ -16,7 +16,7 @@ import 'os';
16
16
  import 'util';
17
17
  import 'stream';
18
18
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
19
- import './chunk-vite-node-utils.1bbdb2c1.mjs';
19
+ import './chunk-vite-node-utils.7450fc0c.mjs';
20
20
  import 'vm';
21
21
  import 'assert';
22
22
  import 'debug';
package/dist/index.d.ts CHANGED
@@ -496,7 +496,7 @@ declare type DeepMerge<F, S> = MergeInsertions<{
496
496
  declare type MutableArray<T extends readonly any[]> = {
497
497
  -readonly [k in keyof T]: T[k];
498
498
  };
499
- interface Constructable {
499
+ interface Constructable$1 {
500
500
  new (...args: any[]): any;
501
501
  }
502
502
  interface ModuleCache {
@@ -768,14 +768,14 @@ declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'onl
768
768
  skipIf(condition: any): SuiteAPI<ExtraContext>;
769
769
  runIf(condition: any): SuiteAPI<ExtraContext>;
770
770
  };
771
- declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
771
+ declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
772
+ declare type HookCleanupCallback = (() => Awaitable<unknown>) | void;
772
773
  interface SuiteHooks {
773
- beforeAll: HookListener<[Suite | File], () => Awaitable<void>>[];
774
+ beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
774
775
  afterAll: HookListener<[Suite | File]>[];
775
- beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
776
+ beforeEach: HookListener<[TestContext, Suite], HookCleanupCallback>[];
776
777
  afterEach: HookListener<[TestContext, Suite]>[];
777
778
  }
778
- declare type HookCleanupCallback = (() => Awaitable<void>) | void;
779
779
  interface SuiteCollector<ExtraContext = {}> {
780
780
  readonly name: string;
781
781
  readonly mode: RunMode;
@@ -1460,8 +1460,8 @@ declare global {
1460
1460
  nthCalledWith<E extends any[]>(nthCall: number, ...args: E): void;
1461
1461
  toHaveBeenLastCalledWith<E extends any[]>(...args: E): void;
1462
1462
  lastCalledWith<E extends any[]>(...args: E): void;
1463
- toThrow(expected?: string | Constructable | RegExp | Error): void;
1464
- toThrowError(expected?: string | Constructable | RegExp | Error): void;
1463
+ toThrow(expected?: string | Constructable$1 | RegExp | Error): void;
1464
+ toThrowError(expected?: string | Constructable$1 | RegExp | Error): void;
1465
1465
  toReturn(): void;
1466
1466
  toHaveReturned(): void;
1467
1467
  toReturnTimes(times: number): void;
@@ -1499,7 +1499,6 @@ declare type BirpcReturn<RemoteFunctions> = {
1499
1499
 
1500
1500
  interface WorkerContext {
1501
1501
  workerId: number;
1502
- poolId: number;
1503
1502
  port: MessagePort;
1504
1503
  config: ResolvedConfig;
1505
1504
  files: string[];
@@ -1542,7 +1541,7 @@ interface MockResultThrow {
1542
1541
  value: any;
1543
1542
  }
1544
1543
  declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
1545
- interface SpyContext<TArgs, TReturns> {
1544
+ interface MockContext<TArgs, TReturns> {
1546
1545
  calls: TArgs[];
1547
1546
  instances: TReturns[];
1548
1547
  invocationCallOrder: number[];
@@ -1560,10 +1559,9 @@ declare type Classes<T> = {
1560
1559
  [K in keyof T]: T[K] extends new (...args: any[]) => any ? K : never;
1561
1560
  }[keyof T] & (string | symbol);
1562
1561
  interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
1563
- (...args: TArgs): TReturns;
1564
1562
  getMockName(): string;
1565
1563
  mockName(n: string): this;
1566
- mock: SpyContext<TArgs, TReturns>;
1564
+ mock: MockContext<TArgs, TReturns>;
1567
1565
  mockClear(): this;
1568
1566
  mockReset(): this;
1569
1567
  mockRestore(): void;
@@ -1578,15 +1576,17 @@ interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
1578
1576
  mockRejectedValue(obj: any): this;
1579
1577
  mockRejectedValueOnce(obj: any): this;
1580
1578
  }
1581
- interface SpyInstanceFn<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, TReturns> {
1582
- (...args: TArgs): TReturns;
1579
+ interface MockInstance<A extends any[] = any[], R = any> extends SpyInstance<A, R> {
1580
+ }
1581
+ interface Mock<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, TReturns> {
1583
1582
  new (...args: TArgs): TReturns;
1583
+ (...args: TArgs): TReturns;
1584
1584
  }
1585
- declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? SpyInstanceFn<ConstructorParameters<T>, R> : T;
1586
- declare type MockedFunction<T extends Procedure> = SpyInstanceFn<Parameters<T>, ReturnType<T>> & {
1585
+ declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? Mock<ConstructorParameters<T>, R> : T;
1586
+ declare type MockedFunction<T extends Procedure> = Mock<Parameters<T>, ReturnType<T>> & {
1587
1587
  [K in keyof T]: T[K];
1588
1588
  };
1589
- declare type MockedFunctionDeep<T extends Procedure> = SpyInstanceFn<Parameters<T>, ReturnType<T>> & MockedObjectDeep<T>;
1589
+ declare type MockedFunctionDeep<T extends Procedure> = Mock<Parameters<T>, ReturnType<T>> & MockedObjectDeep<T>;
1590
1590
  declare type MockedObject<T> = MaybeMockedConstructor<T> & {
1591
1591
  [K in Methods<T>]: T[K] extends Procedure ? MockedFunction<T[K]> : T[K];
1592
1592
  } & {
@@ -1599,12 +1599,23 @@ declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
1599
1599
  };
1600
1600
  declare type MaybeMockedDeep<T> = T extends Procedure ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
1601
1601
  declare type MaybeMocked<T> = T extends Procedure ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
1602
+ interface Constructable {
1603
+ new (...args: any[]): any;
1604
+ }
1605
+ declare type MockedClass<T extends Constructable> = MockInstance<InstanceType<T>, T extends new (...args: infer P) => any ? P : never> & {
1606
+ prototype: T extends {
1607
+ prototype: any;
1608
+ } ? Mocked<T['prototype']> : never;
1609
+ } & T;
1610
+ declare type Mocked<T> = {
1611
+ [P in keyof T]: T[P] extends (...args: infer Args) => infer Returns ? MockInstance<Args, Returns> : T[P] extends Constructable ? MockedClass<T[P]> : T[P];
1612
+ } & T;
1602
1613
  declare type EnhancedSpy<TArgs extends any[] = any[], TReturns = any> = SpyInstance<TArgs, TReturns> & SpyImpl<TArgs, TReturns>;
1603
1614
  declare function spyOn<T, S extends Properties<Required<T>>>(obj: T, methodName: S, accessType: 'get'): SpyInstance<[], T[S]>;
1604
1615
  declare function spyOn<T, G extends Properties<Required<T>>>(obj: T, methodName: G, accessType: 'set'): SpyInstance<[T[G]], void>;
1605
1616
  declare function spyOn<T, M extends (Methods<Required<T>> | Classes<Required<T>>)>(obj: T, methodName: M): Required<T>[M] extends (...args: infer A) => infer R | (new (...args: infer A) => infer R) ? SpyInstance<A, R> : never;
1606
- declare function fn<TArgs extends any[] = any[], R = any>(): SpyInstanceFn<TArgs, R>;
1607
- declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): SpyInstanceFn<TArgs, R>;
1617
+ declare function fn<TArgs extends any[] = any[], R = any>(): Mock<TArgs, R>;
1618
+ declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): Mock<TArgs, R>;
1608
1619
 
1609
1620
  declare const suite: SuiteAPI<{}>;
1610
1621
  declare const test: TestAPI<{}>;
@@ -1761,4 +1772,4 @@ interface WebSocketHandlers {
1761
1772
  interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' | 'onTaskUpdate' | 'onUserConsoleLog'> {
1762
1773
  }
1763
1774
 
1764
- export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookCleanupCallback, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyContext, SpyInstance, SpyInstanceFn, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TransformResultWithSource, UncheckedSnapshot, UserConfig, UserConsoleLog, Vitest, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerGlobalState, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, createExpect, describe, globalExpect as expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest, withCallback };
1775
+ export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable$1 as Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookCleanupCallback, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyInstance, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TransformResultWithSource, UncheckedSnapshot, UserConfig, UserConsoleLog, Vitest, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerGlobalState, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, createExpect, describe, globalExpect as expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest, withCallback };
package/dist/node.d.ts CHANGED
@@ -604,11 +604,12 @@ interface Test<ExtraContext = {}> extends TaskBase {
604
604
  context: TestContext & ExtraContext;
605
605
  }
606
606
  declare type Task = Test | Suite | File;
607
- declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
607
+ declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
608
+ declare type HookCleanupCallback = (() => Awaitable<unknown>) | void;
608
609
  interface SuiteHooks {
609
- beforeAll: HookListener<[Suite | File], () => Awaitable<void>>[];
610
+ beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
610
611
  afterAll: HookListener<[Suite | File]>[];
611
- beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
612
+ beforeEach: HookListener<[TestContext, Suite], HookCleanupCallback>[];
612
613
  afterEach: HookListener<[TestContext, Suite]>[];
613
614
  }
614
615
  interface TestContext {
package/dist/node.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.0ec89ad1.mjs';
2
- export { V as VitestRunner } from './chunk-runtime-mocker.d3ca0a4e.mjs';
1
+ export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.58e10976.mjs';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.110e3634.mjs';
3
3
  import './chunk-utils-global.79a8b1cc.mjs';
4
4
  import 'tty';
5
5
  import 'local-pkg';
@@ -17,7 +17,7 @@ import 'util';
17
17
  import 'stream';
18
18
  import 'events';
19
19
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
20
- import './chunk-vite-node-utils.1bbdb2c1.mjs';
20
+ import './chunk-vite-node-utils.7450fc0c.mjs';
21
21
  import 'vm';
22
22
  import 'assert';
23
23
  import 'debug';
package/dist/worker.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { m as resolve, a as getWorkerState } from './chunk-utils-global.79a8b1cc.mjs';
2
- import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.1bbdb2c1.mjs';
2
+ import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.7450fc0c.mjs';
3
+ import { workerId } from 'tinypool';
3
4
  import { d as distDir } from './chunk-constants.7b9cfc82.mjs';
4
- import { e as executeInViteNode } from './chunk-runtime-mocker.d3ca0a4e.mjs';
5
+ import { e as executeInViteNode } from './chunk-runtime-mocker.110e3634.mjs';
5
6
  import { r as rpc } from './chunk-runtime-rpc.5e78af38.mjs';
6
7
  import 'tty';
7
8
  import 'local-pkg';
@@ -55,9 +56,9 @@ async function startViteNode(ctx) {
55
56
  function init(ctx) {
56
57
  if (typeof __vitest_worker__ !== "undefined" && ctx.config.threads && ctx.config.isolate)
57
58
  throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${getWorkerState().ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
58
- const { config, port, workerId, poolId } = ctx;
59
- process.env.VITEST_WORKER_ID = String(workerId);
60
- process.env.VITEST_POOL_ID = String(poolId);
59
+ const { config, port, workerId: workerId$1 } = ctx;
60
+ process.env.VITEST_WORKER_ID = String(workerId$1);
61
+ process.env.VITEST_POOL_ID = String(workerId);
61
62
  globalThis.__vitest_worker__ = {
62
63
  ctx,
63
64
  moduleCache,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.15.2",
3
+ "version": "0.16.0",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -83,7 +83,7 @@
83
83
  "chai": "^4.3.6",
84
84
  "debug": "^4.3.4",
85
85
  "local-pkg": "^0.4.1",
86
- "tinypool": "^0.1.3",
86
+ "tinypool": "^0.2.1",
87
87
  "tinyspy": "^0.3.3",
88
88
  "vite": "^2.9.12"
89
89
  },
@@ -96,7 +96,7 @@
96
96
  "@types/natural-compare": "^1.4.1",
97
97
  "@types/prompts": "^2.4.0",
98
98
  "@types/sinonjs__fake-timers": "^8.1.2",
99
- "@vitest/ui": "0.15.2",
99
+ "@vitest/ui": "0.16.0",
100
100
  "birpc": "^0.2.3",
101
101
  "c8": "^7.11.3",
102
102
  "cac": "^6.7.12",
@@ -124,7 +124,7 @@
124
124
  "source-map-js": "^1.0.2",
125
125
  "strip-ansi": "^7.0.1",
126
126
  "typescript": "^4.7.4",
127
- "vite-node": "0.15.2",
127
+ "vite-node": "0.16.0",
128
128
  "ws": "^8.8.0"
129
129
  },
130
130
  "scripts": {