vitest 0.27.3 → 0.28.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.
Files changed (60) hide show
  1. package/LICENSE.md +4 -93
  2. package/browser.d.ts +1 -1
  3. package/dist/browser.d.ts +11 -13
  4. package/dist/browser.js +9 -34
  5. package/dist/{chunk-api-setup.0a2398d8.js → chunk-api-setup.52751a38.js} +26 -12
  6. package/dist/chunk-constants.797d3ebf.js +42 -0
  7. package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.cfd23146.js} +51 -11
  8. package/dist/{vendor-index.57682f0c.js → chunk-integrations-coverage.48e6286b.js} +33 -4
  9. package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
  10. package/dist/chunk-integrations-run-once.38756e30.js +27 -0
  11. package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
  12. package/dist/{chunk-node-git.59caac18.js → chunk-node-git.d9ad64ab.js} +6 -8
  13. package/dist/{chunk-snapshot-manager.d16903ef.js → chunk-node-pkg.dcdf4369.js} +7440 -172
  14. package/dist/{chunk-runtime-mocker.66533d65.js → chunk-runtime-mocker.03017e8c.js} +13 -12
  15. package/dist/{chunk-runtime-rpc.e79efa9a.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
  16. package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
  17. package/dist/chunk-snapshot-env.6457638e.js +11 -0
  18. package/dist/chunk-utils-base.977ae74f.js +77 -0
  19. package/dist/chunk-utils-env.860d90c2.js +6 -0
  20. package/dist/chunk-utils-global.442d1d33.js +73 -0
  21. package/dist/{chunk-utils-import.eb63557e.js → chunk-utils-import.9911c99d.js} +3289 -169
  22. package/dist/chunk-utils-tasks.1b603032.js +103 -0
  23. package/dist/cli-wrapper.js +7 -6
  24. package/dist/cli.js +16 -15
  25. package/dist/config.d.ts +7 -2
  26. package/dist/entry.js +233 -28
  27. package/dist/env-afee91f0.d.ts +10 -0
  28. package/dist/environments.d.ts +7 -2
  29. package/dist/index.d.ts +160 -11
  30. package/dist/index.js +17 -18
  31. package/dist/loader.js +6 -6
  32. package/dist/node.d.ts +9 -7
  33. package/dist/node.js +18 -17
  34. package/dist/runners-chunk.js +215 -0
  35. package/dist/runners.d.ts +39 -0
  36. package/dist/runners.js +18 -0
  37. package/dist/spy.js +1 -2
  38. package/dist/suite.d.ts +2 -0
  39. package/dist/suite.js +2 -19
  40. package/dist/{types-c1386a7d.d.ts → types-c800444e.d.ts} +160 -425
  41. package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
  42. package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
  43. package/dist/worker.js +11 -13
  44. package/package.json +21 -12
  45. package/runners.d.ts +1 -0
  46. package/suite.d.ts +1 -0
  47. package/dist/chunk-integrations-coverage.18366936.js +0 -242
  48. package/dist/chunk-integrations-globals.59b4d460.js +0 -28
  49. package/dist/chunk-mock-date.91595ccd.js +0 -350
  50. package/dist/chunk-runtime-chain.07d16eac.js +0 -2594
  51. package/dist/chunk-runtime-error.f2062967.js +0 -144
  52. package/dist/chunk-runtime-setup.8ca273cd.js +0 -653
  53. package/dist/chunk-utils-env.4ebb0106.js +0 -229
  54. package/dist/chunk-utils-source-map.832515f7.js +0 -408
  55. package/dist/chunk-utils-timers.52534f96.js +0 -3573
  56. package/dist/index-2dd51af4.d.ts +0 -258
  57. package/dist/vendor-index.451e37bc.js +0 -1071
  58. package/dist/vendor-index.723a074f.js +0 -102
  59. package/dist/vendor-index.9c919048.js +0 -61
  60. package/dist/vendor-index.9f20a9be.js +0 -6291
package/dist/index.d.ts CHANGED
@@ -1,23 +1,165 @@
1
- import { s as spyOn, f as fn, M as MaybeMockedDeep, a as MaybeMocked, b as MaybePartiallyMocked, c as MaybePartiallyMockedDeep, E as EnhancedSpy } from './index-2dd51af4.js';
2
- export { A as AssertType, E as EnhancedSpy, q as ExpectTypeOf, x as Mock, y as MockContext, w as MockInstance, z as Mocked, B as MockedClass, u as MockedFunction, v as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, r as assertType, h as beforeAll, k as beforeEach, g as bench, n as createExpect, e as describe, m as expect, p as expectTypeOf, i as it, o as onTestFailed, d as suite, t as test } from './index-2dd51af4.js';
3
- import { D as DoneCallback, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as File, T as TaskResultPack, b as ResolvedConfig, c as ModuleGraphData, d as Reporter } from './types-c1386a7d.js';
4
- export { a1 as AfterSuiteRunMeta, A as ApiConfig, a7 as ArgumentsType, a6 as Arrayable, a4 as Awaitable, ap as BaseCoverageOptions, av as BenchFunction, at as Benchmark, aw as BenchmarkAPI, au as BenchmarkResult, as as BenchmarkUserOptions, B as BuiltinEnvironment, j as CSSModuleScopeStrategy, C as CollectLineNumbers, g as CollectLines, ab as Constructable, i as Context, ar as CoverageC8Options, aq as CoverageIstanbulOptions, an as CoverageOptions, aj as CoverageProvider, al as CoverageProviderModule, am as CoverageReporter, a9 as DeepMerge, D as DoneCallback, ae as Environment, E as EnvironmentOptions, ad as EnvironmentReturn, ah as ErrorWithDiff, a as File, x as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, a8 as MergeInsertions, ac as ModuleCache, c as ModuleGraphData, aa as MutableArray, a5 as Nullable, ai as OnServerRestartHandler, O as OnTestFailedHandler, ag as ParsedStack, e as RawErrsMap, ak as ReportContext, d as Reporter, a0 as ResolveIdFunction, b as ResolvedConfig, ao as ResolvedCoverageOptions, h as RootAndTarget, m as RunMode, R as RuntimeConfig, K as RuntimeContext, S as SequenceHooks, P as SnapshotData, X as SnapshotMatchOptions, Y as SnapshotResult, W as SnapshotStateOptions, _ as SnapshotSummary, Q as SnapshotUpdateState, q as Suite, w as SuiteAPI, z as SuiteCollector, G as SuiteFactory, y as SuiteHooks, s as Task, o as TaskBase, p as TaskResult, T as TaskResultPack, n as TaskState, r as Test, v as TestAPI, L as TestContext, t as TestFunction, u as TestOptions, f as TscErrorInfo, l as TypecheckConfig, Z as UncheckedSnapshot, U as UserConfig, af as UserConsoleLog, N as Vitest, V as VitestEnvironment, k as VitestRunMode, $ as WorkerContext, a3 as WorkerGlobalState, a2 as WorkerRPC } from './types-c1386a7d.js';
1
+ import { Test } from '@vitest/runner';
2
+ export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
3
+ import { B as BenchmarkAPI, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as ResolvedConfig, b as ModuleGraphData, S as SnapshotResult, c as Reporter } from './types-c800444e.js';
4
+ export { u as AfterSuiteRunMeta, A as ApiConfig, z as ArgumentsType, y as Arrayable, x as Awaitable, a2 as BaseCoverageOptions, a8 as BenchFunction, a6 as Benchmark, B as BenchmarkAPI, a7 as BenchmarkResult, a5 as BenchmarkUserOptions, h as BuiltinEnvironment, i as CSSModuleScopeStrategy, C as CollectLineNumbers, e as CollectLines, K as Constructable, g as Context, a4 as CoverageC8Options, a3 as CoverageIstanbulOptions, a0 as CoverageOptions, Y as CoverageProvider, _ as CoverageProviderModule, $ as CoverageReporter, G as DeepMerge, P as Environment, E as EnvironmentOptions, O as EnvironmentReturn, I as InlineConfig, J as JSDOMOptions, D as MergeInsertions, L as ModuleCache, b as ModuleGraphData, H as MutableArray, N as Nullable, X as OnServerRestartHandler, d as RawErrsMap, Z as ReportContext, c as Reporter, t as ResolveIdFunction, a as ResolvedConfig, a1 as ResolvedCoverageOptions, f as RootAndTarget, R as RuntimeConfig, j as SequenceHooks, n as SnapshotData, q as SnapshotMatchOptions, S as SnapshotResult, p as SnapshotStateOptions, s as SnapshotSummary, o as SnapshotUpdateState, T as TscErrorInfo, l as TypecheckConfig, r as UncheckedSnapshot, U as UserConfig, Q as UserConsoleLog, m as Vitest, V as VitestEnvironment, k as VitestRunMode, W as WorkerContext, w as WorkerGlobalState, v as WorkerRPC } from './types-c800444e.js';
5
+ import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, EnhancedSpy } from '@vitest/spy';
6
+ export { EnhancedSpy, Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, SpyInstance } from '@vitest/spy';
7
+ export { S as SnapshotEnvironment } from './env-afee91f0.js';
8
+ import { File, TaskResultPack } from '@vitest/runner/types';
9
+ export { DoneCallback, File, HookCleanupCallback, HookListener, OnTestFailedHandler, RunMode, RuntimeContext, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TestOptions } from '@vitest/runner/types';
5
10
  import { TransformResult } from 'vite';
6
11
  import * as chai from 'chai';
7
12
  export { chai };
8
13
  export { assert, should } from 'chai';
14
+ export { ErrorWithDiff, ParsedStack } from '@vitest/runner/utils';
9
15
  export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
10
- import 'tinyspy';
16
+ import '@vitest/expect';
17
+ import '@vitest/utils';
11
18
  import 'vite-node/client';
12
19
  import 'vite-node/server';
20
+ import 'node:worker_threads';
13
21
  import 'vite-node';
14
22
  import 'node:fs';
15
- import 'node:worker_threads';
16
23
 
24
+ declare type Not<T extends boolean> = T extends true ? false : true;
25
+ declare type And<Types extends boolean[]> = Types[number] extends true ? true : false;
26
+ declare type Eq<Left extends boolean, Right extends boolean> = Left extends true ? Right : Not<Right>;
27
+ declare const secret: unique symbol;
28
+ declare type Secret = typeof secret;
29
+ declare type IsNever<T> = [T] extends [never] ? true : false;
30
+ declare type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
31
+ declare type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
17
32
  /**
18
- * A simple wrapper for converting callback style to promise
33
+ * Recursively walk a type and replace it with a branded type related to the original. This is useful for
34
+ * equality-checking stricter than `A extends B ? B extends A ? true : false : false`, because it detects
35
+ * the difference between a few edge-case types that vanilla typescript doesn't by default:
36
+ * - `any` vs `unknown`
37
+ * - `{ readonly a: string }` vs `{ a: string }`
38
+ * - `{ a?: string }` vs `{ a: string | undefined }`
19
39
  */
20
- declare function withCallback(fn: (done: DoneCallback) => void): Promise<void>;
40
+ declare type DeepBrand<T> = IsNever<T> extends true ? {
41
+ type: 'never';
42
+ } : IsAny<T> extends true ? {
43
+ type: 'any';
44
+ } : IsUnknown<T> extends true ? {
45
+ type: 'unknown';
46
+ } : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
47
+ type: 'primitive';
48
+ value: T;
49
+ } : T extends new (...args: any[]) => any ? {
50
+ type: 'constructor';
51
+ params: ConstructorParams<T>;
52
+ instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
53
+ } : T extends (...args: infer P) => infer R ? {
54
+ type: 'function';
55
+ params: DeepBrand<P>;
56
+ return: DeepBrand<R>;
57
+ } : T extends any[] ? {
58
+ type: 'array';
59
+ items: {
60
+ [K in keyof T]: T[K];
61
+ };
62
+ } : {
63
+ type: 'object';
64
+ properties: {
65
+ [K in keyof T]: DeepBrand<T[K]>;
66
+ };
67
+ readonly: ReadonlyKeys<T>;
68
+ required: RequiredKeys<T>;
69
+ optional: OptionalKeys<T>;
70
+ constructorParams: DeepBrand<ConstructorParams<T>>;
71
+ };
72
+ declare type RequiredKeys<T> = Extract<{
73
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
74
+ }[keyof T], keyof T>;
75
+ declare type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
76
+ declare type ReadonlyKeys<T> = Extract<{
77
+ [K in keyof T]-?: ReadonlyEquivalent<{
78
+ [_K in K]: T[K];
79
+ }, {
80
+ -readonly [_K in K]: T[K];
81
+ }> extends true ? never : K;
82
+ }[keyof T], keyof T>;
83
+ declare type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
84
+ declare type Extends<L, R> = IsNever<L> extends true ? IsNever<R> : [L] extends [R] ? true : false;
85
+ declare type StrictExtends<L, R> = Extends<DeepBrand<L>, DeepBrand<R>>;
86
+ declare type Equal<Left, Right> = And<[StrictExtends<Left, Right>, StrictExtends<Right, Left>]>;
87
+ declare type Params<Actual> = Actual extends (...args: infer P) => any ? P : never;
88
+ declare type ConstructorParams<Actual> = Actual extends new (...args: infer P) => any ? Actual extends new () => any ? P | [] : P : never;
89
+ declare type MismatchArgs<B extends boolean, C extends boolean> = Eq<B, C> extends true ? [] : [never];
90
+ interface ExpectTypeOf<Actual, B extends boolean> {
91
+ toBeAny: (...MISMATCH: MismatchArgs<IsAny<Actual>, B>) => true;
92
+ toBeUnknown: (...MISMATCH: MismatchArgs<IsUnknown<Actual>, B>) => true;
93
+ toBeNever: (...MISMATCH: MismatchArgs<IsNever<Actual>, B>) => true;
94
+ toBeFunction: (...MISMATCH: MismatchArgs<Extends<Actual, (...args: any[]) => any>, B>) => true;
95
+ toBeObject: (...MISMATCH: MismatchArgs<Extends<Actual, object>, B>) => true;
96
+ toBeArray: (...MISMATCH: MismatchArgs<Extends<Actual, any[]>, B>) => true;
97
+ toBeNumber: (...MISMATCH: MismatchArgs<Extends<Actual, number>, B>) => true;
98
+ toBeString: (...MISMATCH: MismatchArgs<Extends<Actual, string>, B>) => true;
99
+ toBeBoolean: (...MISMATCH: MismatchArgs<Extends<Actual, boolean>, B>) => true;
100
+ toBeVoid: (...MISMATCH: MismatchArgs<Extends<Actual, void>, B>) => true;
101
+ toBeSymbol: (...MISMATCH: MismatchArgs<Extends<Actual, symbol>, B>) => true;
102
+ toBeNull: (...MISMATCH: MismatchArgs<Extends<Actual, null>, B>) => true;
103
+ toBeUndefined: (...MISMATCH: MismatchArgs<Extends<Actual, undefined>, B>) => true;
104
+ toBeNullable: (...MISMATCH: MismatchArgs<Not<Equal<Actual, NonNullable<Actual>>>, B>) => true;
105
+ toMatchTypeOf: {
106
+ <Expected>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, B>): true;
107
+ <Expected>(expected: Expected, ...MISMATCH: MismatchArgs<Extends<Actual, Expected>, B>): true;
108
+ };
109
+ toEqualTypeOf: {
110
+ <Expected>(...MISMATCH: MismatchArgs<Equal<Actual, Expected>, B>): true;
111
+ <Expected>(expected: Expected, ...MISMATCH: MismatchArgs<Equal<Actual, Expected>, B>): true;
112
+ };
113
+ toBeCallableWith: B extends true ? (...args: Params<Actual>) => true : never;
114
+ toBeConstructibleWith: B extends true ? (...args: ConstructorParams<Actual>) => true : never;
115
+ toHaveProperty: <K extends string>(key: K, ...MISMATCH: MismatchArgs<Extends<K, keyof Actual>, B>) => K extends keyof Actual ? ExpectTypeOf<Actual[K], B> : true;
116
+ extract: <V>(v?: V) => ExpectTypeOf<Extract<Actual, V>, B>;
117
+ exclude: <V>(v?: V) => ExpectTypeOf<Exclude<Actual, V>, B>;
118
+ parameter: <K extends keyof Params<Actual>>(number: K) => ExpectTypeOf<Params<Actual>[K], B>;
119
+ parameters: ExpectTypeOf<Params<Actual>, B>;
120
+ constructorParameters: ExpectTypeOf<ConstructorParams<Actual>, B>;
121
+ instance: Actual extends new (...args: any[]) => infer I ? ExpectTypeOf<I, B> : never;
122
+ returns: Actual extends (...args: any[]) => infer R ? ExpectTypeOf<R, B> : never;
123
+ resolves: Actual extends PromiseLike<infer R> ? ExpectTypeOf<R, B> : never;
124
+ items: Actual extends ArrayLike<infer R> ? ExpectTypeOf<R, B> : never;
125
+ guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf<T, B> : never;
126
+ asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T ? unknown extends T ? never : ExpectTypeOf<T, B> : never;
127
+ not: ExpectTypeOf<Actual, Not<B>>;
128
+ }
129
+ declare type _ExpectTypeOf = {
130
+ <Actual>(actual: Actual): ExpectTypeOf<Actual, true>;
131
+ <Actual>(): ExpectTypeOf<Actual, true>;
132
+ };
133
+ /**
134
+ * Similar to Jest's `expect`, but with type-awareness.
135
+ * Gives you access to a number of type-matchers that let you make assertions about the
136
+ * form of a reference or generic type parameter.
137
+ *
138
+ * @example
139
+ * import {foo, bar} from '../foo'
140
+ * import {expectTypeOf} from 'expect-type'
141
+ *
142
+ * test('foo types', () => {
143
+ * // make sure `foo` has type {a: number}
144
+ * expectTypeOf(foo).toMatchTypeOf({a: 1})
145
+ * expectTypeOf(foo).toHaveProperty('a').toBeNumber()
146
+ *
147
+ * // make sure `bar` is a function taking a string:
148
+ * expectTypeOf(bar).parameter(0).toBeString()
149
+ * expectTypeOf(bar).returns.not.toBeAny()
150
+ * })
151
+ *
152
+ * @description
153
+ * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
154
+ */
155
+ declare const expectTypeOf: _ExpectTypeOf;
156
+
157
+ interface AssertType {
158
+ <T>(value: T): void;
159
+ }
160
+ declare const assertType: AssertType;
161
+
162
+ declare const bench: BenchmarkAPI;
21
163
 
22
164
  /**
23
165
  * This utils allows computational intensive tasks to only be ran once
@@ -38,6 +180,9 @@ declare function runOnce<T>(fn: (() => T), key?: string): T;
38
180
  */
39
181
  declare function isFirstRun(): boolean;
40
182
 
183
+ declare function createExpect(test?: Test): Vi.ExpectStatic;
184
+ declare const globalExpect: Vi.ExpectStatic;
185
+
41
186
  declare class VitestUtils {
42
187
  private _timers;
43
188
  private _mockedDate;
@@ -196,16 +341,20 @@ interface WebSocketHandlers {
196
341
  onCollected(files?: File[]): Promise<void>;
197
342
  onTaskUpdate(packs: TaskResultPack[]): void;
198
343
  getFiles(): File[];
199
- getPaths(): Promise<string[]>;
344
+ getPaths(): string[];
200
345
  getConfig(): ResolvedConfig;
346
+ resolveSnapshotPath(testPath: string): string;
201
347
  getModuleGraph(id: string): Promise<ModuleGraphData>;
202
348
  getTransformResult(id: string): Promise<TransformResultWithSource | undefined>;
203
- readFile(id: string): Promise<string>;
349
+ readFile(id: string): Promise<string | null>;
204
350
  writeFile(id: string, content: string): Promise<void>;
351
+ removeFile(id: string): Promise<void>;
352
+ createDirectory(id: string): Promise<string | undefined>;
353
+ snapshotSaved(snapshot: SnapshotResult): void;
205
354
  rerun(files: string[]): Promise<void>;
206
355
  updateSnapshot(file?: File): Promise<void>;
207
356
  }
208
357
  interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onFinished' | 'onTaskUpdate' | 'onUserConsoleLog' | 'onPathsCollected'> {
209
358
  }
210
359
 
211
- export { TransformResultWithSource, WebSocketEvents, WebSocketHandlers, getRunningMode, isFirstRun, isWatchMode, runOnce, vi, vitest, withCallback };
360
+ export { AssertType, ExpectTypeOf, TransformResultWithSource, WebSocketEvents, WebSocketHandlers, assertType, bench, createExpect, globalExpect as expect, expectTypeOf, getRunningMode, isFirstRun, isWatchMode, runOnce, vi, vitest };
package/dist/index.js CHANGED
@@ -1,26 +1,25 @@
1
- export { b as bench, c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.07d16eac.js';
2
- import { e as dist } from './chunk-utils-import.eb63557e.js';
3
- export { a as afterAll, d as afterEach, f as assertType, b as beforeAll, c as beforeEach, k as getRunningMode, h as isFirstRun, l as isWatchMode, o as onTestFailed, g as runOnce, v as vi, j as vitest, w as withCallback } from './chunk-utils-import.eb63557e.js';
1
+ export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
+ export { b as bench, c as createExpect, g as expect, a as vi, v as vitest } from './chunk-utils-import.9911c99d.js';
3
+ export { i as isFirstRun, r as runOnce } from './chunk-integrations-run-once.38756e30.js';
4
+ import { d as dist } from './chunk-integrations-utils.f1f6f1ed.js';
5
+ export { b as assertType, g as getRunningMode, a as isWatchMode } from './chunk-integrations-utils.f1f6f1ed.js';
4
6
  import * as chai from 'chai';
5
7
  export { chai };
6
8
  export { assert, should } from 'chai';
7
- import 'util';
8
- import './chunk-mock-date.91595ccd.js';
9
- import 'node:path';
10
- import 'picocolors';
11
- import 'local-pkg';
12
- import './chunk-utils-env.4ebb0106.js';
13
- import 'node:url';
14
- import 'path';
9
+ import '@vitest/runner/utils';
10
+ import '@vitest/utils';
11
+ import './chunk-utils-global.442d1d33.js';
12
+ import 'pathe';
13
+ import './chunk-utils-env.860d90c2.js';
15
14
  import 'std-env';
16
15
  import './vendor-_commonjsHelpers.addc3445.js';
17
- import './chunk-utils-timers.52534f96.js';
18
- import './vendor-index.723a074f.js';
19
- import 'tinyspy';
20
- import './chunk-utils-source-map.832515f7.js';
21
- import './chunk-runtime-rpc.e79efa9a.js';
22
- import 'node:fs';
23
- import 'fs';
16
+ import '@vitest/expect';
17
+ import './chunk-runtime-rpc.9c0386cc.js';
18
+ import './chunk-snapshot-env.6457638e.js';
19
+ import './chunk-utils-base.977ae74f.js';
20
+ import './chunk-utils-tasks.1b603032.js';
21
+ import 'util';
22
+ import '@vitest/spy';
24
23
 
25
24
 
26
25
 
package/dist/loader.js CHANGED
@@ -1,21 +1,21 @@
1
1
  import { pathToFileURL, fileURLToPath } from 'node:url';
2
2
  import { readFile } from 'node:fs/promises';
3
- import { i as isNodeBuiltin, h as hasCJSSyntax } from './vendor-index.b0346fe4.js';
3
+ import { i as isNodeBuiltin, h as hasCJSSyntax } from './vendor-index.bdee400f.js';
4
4
  import { normalizeModuleId } from 'vite-node/utils';
5
- import { g as getWorkerState } from './chunk-mock-date.91595ccd.js';
5
+ import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
6
6
  import 'acorn';
7
7
  import 'node:module';
8
8
  import 'node:fs';
9
+ import 'pathe';
9
10
  import 'node:assert';
10
11
  import 'node:process';
11
12
  import 'node:path';
12
13
  import 'node:v8';
13
14
  import 'node:util';
14
- import 'picocolors';
15
- import 'local-pkg';
16
- import './chunk-utils-env.4ebb0106.js';
17
- import 'path';
15
+ import './chunk-utils-env.860d90c2.js';
18
16
  import 'std-env';
17
+ import '@vitest/runner/utils';
18
+ import '@vitest/utils';
19
19
 
20
20
  var ModuleFormat = /* @__PURE__ */ ((ModuleFormat2) => {
21
21
  ModuleFormat2["Builtin"] = "builtin";
package/dist/node.d.ts CHANGED
@@ -1,12 +1,17 @@
1
- import { k as VitestRunMode, U as UserConfig, N as Vitest, ax as MockFactory, ay as MockMap, az as TestSequencer } from './types-c1386a7d.js';
2
- export { az as TestSequencer, aB as TestSequencerConstructor, N as Vitest, aA as startVitest } from './types-c1386a7d.js';
1
+ import { k as VitestRunMode, U as UserConfig, m as Vitest, a9 as MockFactory, aa as MockMap, ab as TestSequencer } from './types-c800444e.js';
2
+ export { ab as TestSequencer, ad as TestSequencerConstructor, m as Vitest, ac as startVitest } from './types-c800444e.js';
3
3
  import { UserConfig as UserConfig$1, Plugin } from 'vite';
4
4
  import { ViteNodeRunner } from 'vite-node/client';
5
5
  import { ViteNodeRunnerOptions } from 'vite-node';
6
+ import '@vitest/expect';
7
+ import '@vitest/runner/types';
8
+ import '@vitest/runner';
9
+ import '@vitest/runner/utils';
10
+ import '@vitest/utils';
6
11
  import 'tinybench';
7
12
  import 'vite-node/server';
8
- import 'node:fs';
9
13
  import 'node:worker_threads';
14
+ import 'node:fs';
10
15
 
11
16
  declare function createVitest(mode: VitestRunMode, options: UserConfig, viteOverrides?: UserConfig$1): Promise<Vitest>;
12
17
 
@@ -56,10 +61,7 @@ declare class VitestRunner extends ViteNodeRunner {
56
61
  shouldResolveId(id: string, _importee?: string | undefined): boolean;
57
62
  resolveUrl(id: string, importee?: string): Promise<[url: string, fsPath: string]>;
58
63
  dependencyRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
59
- prepareContext(context: Record<string, any>): Record<string, any> & {
60
- __vitest_mocker__: VitestMocker;
61
- };
62
- shouldInterop(path: string, mod: any): boolean;
64
+ prepareContext(context: Record<string, any>): Record<string, any>;
63
65
  }
64
66
 
65
67
  declare class BaseSequencer implements TestSequencer {
package/dist/node.js CHANGED
@@ -1,37 +1,39 @@
1
- export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-snapshot-manager.d16903ef.js';
2
- export { V as VitestRunner } from './chunk-runtime-mocker.66533d65.js';
3
- import './chunk-utils-env.4ebb0106.js';
1
+ export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-node-pkg.dcdf4369.js';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.03017e8c.js';
3
+ import 'pathe';
4
+ import './chunk-constants.797d3ebf.js';
4
5
  import 'node:url';
5
- import 'path';
6
+ import './chunk-utils-env.860d90c2.js';
6
7
  import 'std-env';
7
- import './chunk-integrations-coverage.18366936.js';
8
+ import './chunk-integrations-coverage.48e6286b.js';
8
9
  import 'local-pkg';
10
+ import 'util';
11
+ import 'path';
9
12
  import './chunk-env-node.ffd1183b.js';
10
13
  import 'node:console';
11
- import './chunk-mock-date.91595ccd.js';
12
- import 'node:path';
13
14
  import 'picocolors';
14
15
  import 'vite';
16
+ import 'node:path';
15
17
  import 'node:process';
16
18
  import 'node:fs';
17
19
  import 'os';
18
- import './vendor-index.57682f0c.js';
19
- import 'util';
20
20
  import 'stream';
21
21
  import 'events';
22
22
  import 'fs';
23
23
  import './vendor-_commonjsHelpers.addc3445.js';
24
24
  import 'vite-node/client';
25
25
  import 'vite-node/server';
26
+ import './chunk-utils-global.442d1d33.js';
27
+ import '@vitest/runner/utils';
28
+ import '@vitest/utils';
26
29
  import 'node:fs/promises';
27
- import './vendor-index.451e37bc.js';
30
+ import './vendor-index.618ca5a1.js';
28
31
  import 'node:buffer';
29
32
  import 'node:child_process';
30
- import './vendor-index.e6c27006.js';
31
33
  import 'child_process';
34
+ import 'node:os';
32
35
  import 'assert';
33
36
  import 'buffer';
34
- import 'node:os';
35
37
  import 'source-map';
36
38
  import 'module';
37
39
  import 'acorn';
@@ -40,17 +42,16 @@ import 'node:worker_threads';
40
42
  import 'tinypool';
41
43
  import './vendor-index.783e7f3e.js';
42
44
  import 'perf_hooks';
43
- import './chunk-utils-source-map.832515f7.js';
44
- import './chunk-utils-timers.52534f96.js';
45
+ import './chunk-utils-base.977ae74f.js';
46
+ import './chunk-utils-tasks.1b603032.js';
45
47
  import 'crypto';
46
48
  import 'vite-node/utils';
47
- import './vendor-index.9c919048.js';
49
+ import '@vitest/utils/diff';
48
50
  import 'node:crypto';
49
51
  import './chunk-magic-string.3a794426.js';
50
52
  import 'strip-literal';
51
53
  import 'readline';
52
- import './vendor-index.9f20a9be.js';
53
- import './vendor-index.b0346fe4.js';
54
+ import './vendor-index.bdee400f.js';
54
55
  import 'node:module';
55
56
  import 'node:assert';
56
57
  import 'node:v8';
@@ -0,0 +1,215 @@
1
+ import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
2
+ import { d as getSnapshotClient, c as createExpect, a as vi, e as getBenchOptions, f as getBenchFn } from './chunk-utils-import.9911c99d.js';
3
+ import { g as getWorkerState } from './chunk-utils-global.442d1d33.js';
4
+ import { g as getFullName } from './chunk-utils-tasks.1b603032.js';
5
+ import { updateTask } from '@vitest/runner';
6
+ import { createDefer, getSafeTimers } from '@vitest/utils';
7
+
8
+ class VitestTestRunner {
9
+ constructor(config) {
10
+ this.config = config;
11
+ this.snapshotClient = getSnapshotClient();
12
+ this.workerState = getWorkerState();
13
+ }
14
+ importFile(filepath, source) {
15
+ if (source === "setup")
16
+ this.workerState.moduleCache.delete(filepath);
17
+ return import(filepath);
18
+ }
19
+ onBeforeRun() {
20
+ this.snapshotClient.clear();
21
+ }
22
+ async onAfterRun() {
23
+ await this.snapshotClient.saveCurrent();
24
+ }
25
+ onAfterRunSuite(suite) {
26
+ if (this.config.logHeapUsage && typeof process !== "undefined")
27
+ suite.result.heap = process.memoryUsage().heapUsed;
28
+ }
29
+ onAfterRunTest(test) {
30
+ this.snapshotClient.clearTest();
31
+ if (this.config.logHeapUsage && typeof process !== "undefined")
32
+ test.result.heap = process.memoryUsage().heapUsed;
33
+ this.workerState.current = void 0;
34
+ }
35
+ async onBeforeRunTest(test) {
36
+ if (test.mode !== "run") {
37
+ this.snapshotClient.skipTestSnapshots(test);
38
+ return;
39
+ }
40
+ clearModuleMocks(this.config);
41
+ await this.snapshotClient.setTest(test);
42
+ this.workerState.current = test;
43
+ }
44
+ onBeforeTryTest(test) {
45
+ var _a;
46
+ setState({
47
+ assertionCalls: 0,
48
+ isExpectingAssertions: false,
49
+ isExpectingAssertionsError: null,
50
+ expectedAssertionsNumber: null,
51
+ expectedAssertionsNumberErrorGen: null,
52
+ testPath: (_a = test.suite.file) == null ? void 0 : _a.filepath,
53
+ currentTestName: getFullName(test),
54
+ snapshotState: this.snapshotClient.snapshotState
55
+ }, globalThis[GLOBAL_EXPECT]);
56
+ }
57
+ onAfterTryTest(test) {
58
+ const {
59
+ assertionCalls,
60
+ expectedAssertionsNumber,
61
+ expectedAssertionsNumberErrorGen,
62
+ isExpectingAssertions,
63
+ isExpectingAssertionsError
64
+ } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
65
+ if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
66
+ throw expectedAssertionsNumberErrorGen();
67
+ if (isExpectingAssertions === true && assertionCalls === 0)
68
+ throw isExpectingAssertionsError;
69
+ }
70
+ extendTestContext(context) {
71
+ let _expect;
72
+ Object.defineProperty(context, "expect", {
73
+ get() {
74
+ if (!_expect)
75
+ _expect = createExpect(context.meta);
76
+ return _expect;
77
+ }
78
+ });
79
+ Object.defineProperty(context, "_local", {
80
+ get() {
81
+ return _expect != null;
82
+ }
83
+ });
84
+ return context;
85
+ }
86
+ }
87
+ function clearModuleMocks(config) {
88
+ const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
89
+ if (restoreMocks)
90
+ vi.restoreAllMocks();
91
+ else if (mockReset)
92
+ vi.resetAllMocks();
93
+ else if (clearMocks)
94
+ vi.clearAllMocks();
95
+ if (unstubEnvs)
96
+ vi.unstubAllEnvs();
97
+ if (unstubGlobals)
98
+ vi.unstubAllGlobals();
99
+ }
100
+
101
+ async function importTinybench() {
102
+ if (!globalThis.EventTarget)
103
+ await import('./vendor-index.534e612c.js').then(function (n) { return n.i; });
104
+ return await import('tinybench');
105
+ }
106
+ function createBenchmarkResult(name) {
107
+ return {
108
+ name,
109
+ rank: 0,
110
+ rme: 0,
111
+ samples: []
112
+ };
113
+ }
114
+ async function runBenchmarkSuite(suite, runner) {
115
+ var _a;
116
+ const { Task, Bench } = await importTinybench();
117
+ const start = performance.now();
118
+ const benchmarkGroup = [];
119
+ const benchmarkSuiteGroup = [];
120
+ for (const task of suite.tasks) {
121
+ if (task.mode !== "run")
122
+ continue;
123
+ if ((_a = task.meta) == null ? void 0 : _a.benchmark)
124
+ benchmarkGroup.push(task);
125
+ else if (task.type === "suite")
126
+ benchmarkSuiteGroup.push(task);
127
+ }
128
+ if (benchmarkSuiteGroup.length)
129
+ await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuite(subSuite, runner)));
130
+ if (benchmarkGroup.length) {
131
+ const defer = createDefer();
132
+ const benchmarkMap = {};
133
+ suite.result = {
134
+ state: "run",
135
+ startTime: start,
136
+ benchmark: createBenchmarkResult(suite.name)
137
+ };
138
+ updateTask$1(suite);
139
+ benchmarkGroup.forEach((benchmark, idx) => {
140
+ const options = getBenchOptions(benchmark);
141
+ const benchmarkInstance = new Bench(options);
142
+ const benchmarkFn = getBenchFn(benchmark);
143
+ benchmark.result = {
144
+ state: "run",
145
+ startTime: start,
146
+ benchmark: createBenchmarkResult(benchmark.name)
147
+ };
148
+ const id = idx.toString();
149
+ benchmarkMap[id] = benchmark;
150
+ const task = new Task(benchmarkInstance, id, benchmarkFn);
151
+ benchmark.meta.task = task;
152
+ updateTask$1(benchmark);
153
+ });
154
+ benchmarkGroup.forEach((benchmark) => {
155
+ benchmark.meta.task.addEventListener("complete", (e) => {
156
+ const task = e.task;
157
+ const _benchmark = benchmarkMap[task.name || ""];
158
+ if (_benchmark) {
159
+ const taskRes = task.result;
160
+ const result = _benchmark.result.benchmark;
161
+ Object.assign(result, taskRes);
162
+ updateTask$1(_benchmark);
163
+ }
164
+ });
165
+ benchmark.meta.task.addEventListener("error", (e) => {
166
+ const task = e.task;
167
+ const _benchmark = benchmarkMap[task.name || ""];
168
+ defer.reject(_benchmark ? task.result.error : e);
169
+ });
170
+ });
171
+ Promise.all(benchmarkGroup.map(async (benchmark) => {
172
+ await benchmark.meta.task.warmup();
173
+ const { setTimeout } = getSafeTimers();
174
+ return await new Promise((resolve) => setTimeout(async () => {
175
+ resolve(await benchmark.meta.task.run());
176
+ }));
177
+ })).then((tasks) => {
178
+ suite.result.duration = performance.now() - start;
179
+ suite.result.state = "pass";
180
+ tasks.sort((a, b) => a.result.mean - b.result.mean).forEach((cycle, idx) => {
181
+ const benchmark = benchmarkMap[cycle.name || ""];
182
+ benchmark.result.state = "pass";
183
+ if (benchmark) {
184
+ const result = benchmark.result.benchmark;
185
+ result.rank = Number(idx) + 1;
186
+ updateTask$1(benchmark);
187
+ }
188
+ });
189
+ updateTask$1(suite);
190
+ defer.resolve(null);
191
+ });
192
+ await defer;
193
+ }
194
+ function updateTask$1(task) {
195
+ updateTask(task, runner);
196
+ }
197
+ }
198
+ class NodeBenchmarkRunner {
199
+ constructor(config) {
200
+ this.config = config;
201
+ }
202
+ importFile(filepath, source) {
203
+ if (source === "setup")
204
+ getWorkerState().moduleCache.delete(filepath);
205
+ return import(filepath);
206
+ }
207
+ async runSuite(suite) {
208
+ await runBenchmarkSuite(suite, this);
209
+ }
210
+ async runTest() {
211
+ throw new Error("`test()` and `it()` is only available in test mode.");
212
+ }
213
+ }
214
+
215
+ export { NodeBenchmarkRunner as N, VitestTestRunner as V };
@@ -0,0 +1,39 @@
1
+ import { VitestRunner, VitestRunnerImportSource, Suite, Test, TestContext } from '@vitest/runner';
2
+ import { a as ResolvedConfig } from './types-c800444e.js';
3
+ import '@vitest/expect';
4
+ import 'vite';
5
+ import '@vitest/runner/types';
6
+ import '@vitest/runner/utils';
7
+ import '@vitest/utils';
8
+ import 'tinybench';
9
+ import 'vite-node/client';
10
+ import 'vite-node/server';
11
+ import 'node:worker_threads';
12
+ import 'vite-node';
13
+ import 'node:fs';
14
+
15
+ declare class VitestTestRunner implements VitestRunner {
16
+ config: ResolvedConfig;
17
+ private snapshotClient;
18
+ private workerState;
19
+ constructor(config: ResolvedConfig);
20
+ importFile(filepath: string, source: VitestRunnerImportSource): unknown;
21
+ onBeforeRun(): void;
22
+ onAfterRun(): Promise<void>;
23
+ onAfterRunSuite(suite: Suite): void;
24
+ onAfterRunTest(test: Test): void;
25
+ onBeforeRunTest(test: Test): Promise<void>;
26
+ onBeforeTryTest(test: Test): void;
27
+ onAfterTryTest(test: Test): void;
28
+ extendTestContext(context: TestContext): TestContext;
29
+ }
30
+
31
+ declare class NodeBenchmarkRunner implements VitestRunner {
32
+ config: ResolvedConfig;
33
+ constructor(config: ResolvedConfig);
34
+ importFile(filepath: string, source: VitestRunnerImportSource): unknown;
35
+ runSuite(suite: Suite): Promise<void>;
36
+ runTest(): Promise<void>;
37
+ }
38
+
39
+ export { NodeBenchmarkRunner, VitestTestRunner };