vitest 0.27.2 → 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.
- package/LICENSE.md +4 -93
- package/browser.d.ts +1 -1
- package/dist/browser.d.ts +11 -13
- package/dist/browser.js +10 -34
- package/dist/{chunk-api-setup.029198e3.js → chunk-api-setup.52751a38.js} +27 -12
- package/dist/chunk-constants.797d3ebf.js +42 -0
- package/dist/{chunk-env-node.787e9561.js → chunk-env-node.ffd1183b.js} +26 -0
- package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.cfd23146.js} +51 -11
- package/dist/chunk-integrations-coverage.48e6286b.js +3993 -0
- package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
- package/dist/chunk-integrations-run-once.38756e30.js +27 -0
- package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
- package/dist/{chunk-node-git.125c9008.js → chunk-node-git.d9ad64ab.js} +6 -7
- package/dist/{chunk-snapshot-manager.ce714e21.js → chunk-node-pkg.dcdf4369.js} +12653 -9324
- package/dist/{chunk-runtime-mocker.58511c38.js → chunk-runtime-mocker.03017e8c.js} +14 -13
- package/dist/{chunk-runtime-rpc.d709e91b.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
- package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
- package/dist/chunk-snapshot-env.6457638e.js +11 -0
- package/dist/chunk-utils-base.977ae74f.js +77 -0
- package/dist/chunk-utils-env.860d90c2.js +6 -0
- package/dist/chunk-utils-global.442d1d33.js +73 -0
- package/dist/{chunk-utils-import.054ab315.js → chunk-utils-import.9911c99d.js} +3289 -169
- package/dist/chunk-utils-tasks.1b603032.js +103 -0
- package/dist/cli-wrapper.js +8 -6
- package/dist/cli.js +18 -15
- package/dist/config.cjs +10 -7
- package/dist/config.d.ts +22 -4
- package/dist/config.js +10 -8
- package/dist/entry.js +244 -28
- package/dist/env-afee91f0.d.ts +10 -0
- package/dist/environments.d.ts +7 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +160 -11
- package/dist/index.js +18 -18
- package/dist/loader.js +9 -8
- package/dist/node.d.ts +9 -7
- package/dist/node.js +20 -17
- package/dist/runners-chunk.js +215 -0
- package/dist/runners.d.ts +39 -0
- package/dist/runners.js +18 -0
- package/dist/spy.js +1 -2
- package/dist/suite.d.ts +2 -0
- package/dist/suite.js +2 -18
- package/dist/{types-d97c72c7.d.ts → types-c800444e.d.ts} +196 -437
- package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
- package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
- package/dist/worker.js +17 -16
- package/package.json +22 -12
- package/runners.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/dist/chunk-integrations-coverage.44413252.js +0 -240
- package/dist/chunk-integrations-globals.0024ce21.js +0 -27
- package/dist/chunk-mock-date.c543fa3e.js +0 -349
- package/dist/chunk-runtime-chain.2da9e75c.js +0 -2595
- package/dist/chunk-runtime-error.de671af0.js +0 -144
- package/dist/chunk-runtime-setup.35da9209.js +0 -649
- package/dist/chunk-utils-env.f4a39d2c.js +0 -228
- package/dist/chunk-utils-source-map.5f5d12cf.js +0 -408
- package/dist/chunk-utils-timers.52534f96.js +0 -3573
- package/dist/index-50755efe.d.ts +0 -258
- package/dist/vendor-index.451e37bc.js +0 -1071
- package/dist/vendor-index.723a074f.js +0 -102
- package/dist/vendor-index.9c919048.js +0 -61
- package/dist/vendor-index.9f20a9be.js +0 -6291
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface SnapshotEnvironment {
|
|
2
|
+
resolvePath(filepath: string): Promise<string>;
|
|
3
|
+
prepareDirectory(filepath: string): Promise<void>;
|
|
4
|
+
saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
|
|
5
|
+
readSnapshotFile(filepath: string): Promise<string | null>;
|
|
6
|
+
removeSnapshotFile(filepath: string): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
declare function setupSnapshotEnvironment(environment: SnapshotEnvironment): void;
|
|
9
|
+
|
|
10
|
+
export { SnapshotEnvironment as S, setupSnapshotEnvironment as s };
|
package/dist/environments.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as Environment } from './types-c800444e.js';
|
|
2
|
+
import '@vitest/expect';
|
|
2
3
|
import 'vite';
|
|
4
|
+
import '@vitest/runner/types';
|
|
5
|
+
import '@vitest/runner';
|
|
6
|
+
import '@vitest/runner/utils';
|
|
7
|
+
import '@vitest/utils';
|
|
3
8
|
import 'tinybench';
|
|
4
9
|
import 'vite-node/client';
|
|
5
10
|
import 'vite-node/server';
|
|
11
|
+
import 'node:worker_threads';
|
|
6
12
|
import 'vite-node';
|
|
7
13
|
import 'node:fs';
|
|
8
|
-
import 'node:worker_threads';
|
|
9
14
|
|
|
10
15
|
declare const environments: {
|
|
11
16
|
node: Environment;
|
package/dist/environments.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,165 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
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 '
|
|
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
|
-
*
|
|
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
|
|
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():
|
|
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
|
|
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,25 +1,25 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
export {
|
|
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 '
|
|
8
|
-
import '
|
|
9
|
-
import '
|
|
10
|
-
import '
|
|
11
|
-
import '
|
|
12
|
-
import '
|
|
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';
|
|
14
|
+
import 'std-env';
|
|
15
15
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
16
|
-
import '
|
|
17
|
-
import './
|
|
18
|
-
import '
|
|
19
|
-
import './chunk-utils-
|
|
20
|
-
import './chunk-
|
|
21
|
-
import '
|
|
22
|
-
import '
|
|
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';
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
package/dist/loader.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { pathToFileURL } from 'node:url';
|
|
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.
|
|
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-
|
|
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 '
|
|
15
|
-
import '
|
|
16
|
-
import '
|
|
17
|
-
import '
|
|
15
|
+
import './chunk-utils-env.860d90c2.js';
|
|
16
|
+
import 'std-env';
|
|
17
|
+
import '@vitest/runner/utils';
|
|
18
|
+
import '@vitest/utils';
|
|
18
19
|
|
|
19
20
|
var ModuleFormat = /* @__PURE__ */ ((ModuleFormat2) => {
|
|
20
21
|
ModuleFormat2["Builtin"] = "builtin";
|
|
@@ -67,7 +68,7 @@ const resolve = async (url, context, next) => {
|
|
|
67
68
|
};
|
|
68
69
|
} else {
|
|
69
70
|
const { url: resolvedUrl, format } = await next(url, context, next);
|
|
70
|
-
filepath =
|
|
71
|
+
filepath = fileURLToPath(resolvedUrl);
|
|
71
72
|
result = {
|
|
72
73
|
url: resolvedUrl,
|
|
73
74
|
format,
|
package/dist/node.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { k as VitestRunMode, U as UserConfig,
|
|
2
|
-
export {
|
|
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,35 +1,39 @@
|
|
|
1
|
-
export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-
|
|
2
|
-
export { V as VitestRunner } from './chunk-runtime-mocker.
|
|
3
|
-
import '
|
|
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 '
|
|
6
|
-
import '
|
|
6
|
+
import './chunk-utils-env.860d90c2.js';
|
|
7
|
+
import 'std-env';
|
|
8
|
+
import './chunk-integrations-coverage.48e6286b.js';
|
|
7
9
|
import 'local-pkg';
|
|
8
|
-
import '
|
|
10
|
+
import 'util';
|
|
11
|
+
import 'path';
|
|
12
|
+
import './chunk-env-node.ffd1183b.js';
|
|
9
13
|
import 'node:console';
|
|
10
|
-
import './chunk-mock-date.c543fa3e.js';
|
|
11
|
-
import 'node:path';
|
|
12
14
|
import 'picocolors';
|
|
13
15
|
import 'vite';
|
|
16
|
+
import 'node:path';
|
|
14
17
|
import 'node:process';
|
|
15
18
|
import 'node:fs';
|
|
16
19
|
import 'os';
|
|
17
|
-
import 'util';
|
|
18
20
|
import 'stream';
|
|
19
21
|
import 'events';
|
|
20
22
|
import 'fs';
|
|
21
23
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
22
24
|
import 'vite-node/client';
|
|
23
25
|
import 'vite-node/server';
|
|
26
|
+
import './chunk-utils-global.442d1d33.js';
|
|
27
|
+
import '@vitest/runner/utils';
|
|
28
|
+
import '@vitest/utils';
|
|
24
29
|
import 'node:fs/promises';
|
|
25
|
-
import './vendor-index.
|
|
30
|
+
import './vendor-index.618ca5a1.js';
|
|
26
31
|
import 'node:buffer';
|
|
27
32
|
import 'node:child_process';
|
|
28
|
-
import './vendor-index.e6c27006.js';
|
|
29
33
|
import 'child_process';
|
|
34
|
+
import 'node:os';
|
|
30
35
|
import 'assert';
|
|
31
36
|
import 'buffer';
|
|
32
|
-
import 'node:os';
|
|
33
37
|
import 'source-map';
|
|
34
38
|
import 'module';
|
|
35
39
|
import 'acorn';
|
|
@@ -38,17 +42,16 @@ import 'node:worker_threads';
|
|
|
38
42
|
import 'tinypool';
|
|
39
43
|
import './vendor-index.783e7f3e.js';
|
|
40
44
|
import 'perf_hooks';
|
|
41
|
-
import './chunk-utils-
|
|
42
|
-
import './chunk-utils-
|
|
45
|
+
import './chunk-utils-base.977ae74f.js';
|
|
46
|
+
import './chunk-utils-tasks.1b603032.js';
|
|
43
47
|
import 'crypto';
|
|
44
48
|
import 'vite-node/utils';
|
|
45
|
-
import '
|
|
49
|
+
import '@vitest/utils/diff';
|
|
46
50
|
import 'node:crypto';
|
|
47
51
|
import './chunk-magic-string.3a794426.js';
|
|
48
52
|
import 'strip-literal';
|
|
49
53
|
import 'readline';
|
|
50
|
-
import './vendor-index.
|
|
51
|
-
import './vendor-index.b0346fe4.js';
|
|
54
|
+
import './vendor-index.bdee400f.js';
|
|
52
55
|
import 'node:module';
|
|
53
56
|
import 'node:assert';
|
|
54
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 };
|