vitest 5.0.0-beta.2 → 5.0.0-beta.4
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/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.Opc_YHkk.js → base.BEGVMQrS.js} +6 -6
- package/dist/chunks/{browser.d.BUhkKcDl.d.ts → browser.d.BGxB4Xum.d.ts} +5 -26
- package/dist/chunks/{cac.8N4bOkkB.js → cac.CyXAEMkE.js} +26 -33
- package/dist/chunks/{cli-api.B0RFke2g.js → cli-api.DJMXq34b.js} +640 -615
- package/dist/chunks/{config.d.D91DHYaD.d.ts → config.d.DXq1aBpy.d.ts} +93 -89
- package/dist/chunks/{creator.BqL2U_x4.js → creator.D66cVXYh.js} +2 -2
- package/dist/chunks/{defaults.szbHWQun.js → defaults.CUUnbOrq.js} +6 -4
- package/dist/chunks/{env.D4Lgay0q.js → env.BKKtU2WC.js} +2 -1
- package/dist/chunks/global.d.BtKPuz2X.d.ts +194 -0
- package/dist/chunks/{globals.EHmmu0nC.js → globals.BuY-yD0m.js} +2 -1
- package/dist/chunks/{index.D_7-4CaB.js → index.CE58PZNH.js} +1660 -701
- package/dist/chunks/{index.CViWo__T.js → index.CcluKS59.js} +4 -4
- package/dist/chunks/{index.CbgUM9E5.js → index.nQFVd50u.js} +2 -1
- package/dist/chunks/{init-forks.DMge3WTt.js → init-forks.Ce3vGWgL.js} +1 -1
- package/dist/chunks/{init-threads.eIoyCTon.js → init-threads.8e1OLv5v.js} +1 -1
- package/dist/chunks/{init.BVd7SaCA.js → init.6qx-LaHs.js} +31 -3
- package/dist/chunks/{nativeModuleMocker.DKpFw0pk.js → nativeModuleMocker.DDZfQXLs.js} +1 -1
- package/dist/chunks/{plugin.d.cIKZEZ16.d.ts → plugin.d.B7MTG_Fe.d.ts} +103 -88
- package/dist/chunks/{rpc.d.7JZuxZ8u.d.ts → rpc.d.OQ_EZi1Z.d.ts} +18 -2
- package/dist/chunks/{setup-common.Hpq30zVk.js → setup-common.DdEF_hkE.js} +1 -1
- package/dist/chunks/{vm.2okbRRME.js → vm.Bu7mmcZq.js} +2 -2
- package/dist/chunks/{worker.d.Bu1kXGw4.d.ts → worker.d.yR22cs6X.d.ts} +3 -2
- package/dist/cli.js +2 -2
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +7 -10
- package/dist/config.js +2 -2
- package/dist/index.d.ts +24 -41
- package/dist/index.js +2 -1
- package/dist/module-evaluator.d.ts +4 -1
- package/dist/module-evaluator.js +15 -20
- package/dist/node.d.ts +20 -13
- package/dist/node.js +6 -6
- package/dist/runtime.js +2 -2
- package/dist/worker.d.ts +3 -3
- package/dist/worker.js +7 -6
- package/dist/workers/forks.js +8 -7
- package/dist/workers/runVmTests.js +4 -3
- package/dist/workers/threads.js +8 -7
- package/dist/workers/vmForks.js +4 -4
- package/dist/workers/vmThreads.js +4 -4
- package/package.json +20 -21
- package/dist/chunks/global.d.DhbKSQoV.d.ts +0 -99
|
@@ -1,75 +1,96 @@
|
|
|
1
1
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
2
|
-
import {
|
|
2
|
+
import { VitestRunnerConfig, SequenceHooks } from '@vitest/runner';
|
|
3
3
|
import { L as LabelColor, g as SnapshotUpdateState } from './general.d.DFAHgpC2.js';
|
|
4
4
|
import { S as SnapshotEnvironment } from './environment.d-DOJxxZV9.d.DOJxxZV9.js';
|
|
5
5
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
7
|
+
type VoidVarArgsFunc = (...args: unknown[]) => void;
|
|
8
|
+
type SetImmediate = (callback: VoidVarArgsFunc, ...args: unknown[]) => NodeImmediate;
|
|
9
|
+
type SetTimeout = (callback: VoidVarArgsFunc, delay?: number, ...args: unknown[]) => TimerId;
|
|
10
|
+
type ClearTimeout = (id?: TimerId) => void;
|
|
11
|
+
type SetInterval = (callback: VoidVarArgsFunc, delay?: number, ...args: unknown[]) => TimerId;
|
|
12
|
+
type ClearInterval = (id?: TimerId) => void;
|
|
13
|
+
type QueueMicrotask = (callback: VoidVarArgsFunc) => void;
|
|
14
|
+
type TimeRemaining = () => number;
|
|
15
|
+
type IdleDeadline = {
|
|
16
|
+
didTimeout: boolean;
|
|
17
|
+
timeRemaining: TimeRemaining;
|
|
18
|
+
};
|
|
19
|
+
type RequestIdleCallbackCallback = (deadline: IdleDeadline) => any;
|
|
20
|
+
type RequestIdleCallback = (callback: RequestIdleCallbackCallback, options?: {
|
|
21
|
+
timeout?: number;
|
|
22
|
+
}) => number;
|
|
23
|
+
type AnimationFrameCallback = (timestamp: number) => any;
|
|
24
|
+
type RequestAnimationFrame = (callback: AnimationFrameCallback) => TimerId;
|
|
25
|
+
type CancelAnimationFrame = (id: TimerId) => void;
|
|
26
|
+
type CancelIdleCallback = (id: TimerId) => void;
|
|
27
|
+
type ClearImmediate = (id: NodeImmediate) => void;
|
|
28
|
+
type FakeMethod = "setTimeout" | "clearTimeout" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "Date" | "nextTick" | "hrtime" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "performance" | "queueMicrotask";
|
|
29
|
+
type TimerId = number | NodeImmediate | Timer;
|
|
30
|
+
type GlobalObject = Record<string, any> & {
|
|
31
|
+
setTimeout?: SetTimeout;
|
|
32
|
+
clearTimeout?: ClearTimeout;
|
|
33
|
+
setInterval?: SetInterval;
|
|
34
|
+
clearInterval?: ClearInterval;
|
|
35
|
+
setImmediate?: SetImmediate;
|
|
36
|
+
clearImmediate?: ClearImmediate;
|
|
37
|
+
queueMicrotask?: QueueMicrotask;
|
|
38
|
+
requestAnimationFrame?: RequestAnimationFrame;
|
|
39
|
+
cancelAnimationFrame?: CancelAnimationFrame;
|
|
40
|
+
requestIdleCallback?: RequestIdleCallback;
|
|
41
|
+
cancelIdleCallback?: CancelIdleCallback;
|
|
42
|
+
process?: any;
|
|
43
|
+
performance?: any;
|
|
44
|
+
Performance?: any;
|
|
45
|
+
Intl?: any;
|
|
46
|
+
Promise?: typeof Promise;
|
|
47
|
+
Date: typeof Date & {
|
|
48
|
+
isFake?: boolean;
|
|
49
|
+
toSource?: () => string;
|
|
50
|
+
clock?: any;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
type TimerInitialProps = {
|
|
54
|
+
func: VoidVarArgsFunc;
|
|
55
|
+
args?: unknown[];
|
|
56
|
+
type?: 'Timeout' | 'Interval' | 'Immediate' | 'AnimationFrame' | 'IdleCallback';
|
|
57
|
+
delay?: number;
|
|
58
|
+
callAt?: number;
|
|
59
|
+
createdAt?: number;
|
|
60
|
+
immediate?: boolean;
|
|
61
|
+
id?: number;
|
|
62
|
+
error?: Error;
|
|
63
|
+
interval?: number;
|
|
64
|
+
animation?: boolean;
|
|
65
|
+
requestIdleCallback?: boolean;
|
|
66
|
+
order?: number;
|
|
67
|
+
heapIndex?: number;
|
|
68
|
+
};
|
|
69
|
+
type Config = {
|
|
70
|
+
now?: number | Date;
|
|
71
|
+
toFake?: FakeMethod[];
|
|
72
|
+
toNotFake?: FakeMethod[];
|
|
73
|
+
loopLimit?: number;
|
|
74
|
+
shouldAdvanceTime?: boolean;
|
|
75
|
+
advanceTimeDelta?: number;
|
|
76
|
+
shouldClearNativeTimers?: boolean;
|
|
77
|
+
ignoreMissingTimers?: boolean;
|
|
78
|
+
target?: GlobalObject;
|
|
79
|
+
};
|
|
80
|
+
type Timer = TimerInitialProps;
|
|
81
|
+
type NodeImmediateHasRef = () => boolean;
|
|
82
|
+
type NodeImmediateRef = () => NodeImmediate;
|
|
83
|
+
type NodeImmediateUnref = () => NodeImmediate;
|
|
84
|
+
type NodeImmediate = {
|
|
85
|
+
hasRef: NodeImmediateHasRef;
|
|
86
|
+
ref: NodeImmediateRef;
|
|
87
|
+
unref: NodeImmediateUnref;
|
|
88
|
+
};
|
|
67
89
|
|
|
68
90
|
/**
|
|
69
91
|
* Config that tests have access to.
|
|
70
92
|
*/
|
|
71
|
-
interface SerializedConfig {
|
|
72
|
-
name: string | undefined;
|
|
93
|
+
interface SerializedConfig extends VitestRunnerConfig {
|
|
73
94
|
color?: LabelColor;
|
|
74
95
|
globals: boolean;
|
|
75
96
|
base: string | undefined;
|
|
@@ -78,23 +99,14 @@ interface SerializedConfig {
|
|
|
78
99
|
runner: string | undefined;
|
|
79
100
|
isolate: boolean;
|
|
80
101
|
maxWorkers: number;
|
|
81
|
-
mode: "test" | "benchmark";
|
|
82
102
|
bail: number | undefined;
|
|
83
103
|
environmentOptions?: Record<string, any>;
|
|
84
|
-
root: string;
|
|
85
|
-
setupFiles: string[];
|
|
86
|
-
passWithNoTests: boolean;
|
|
87
|
-
testNamePattern: RegExp | undefined;
|
|
88
|
-
allowOnly: boolean;
|
|
89
|
-
testTimeout: number;
|
|
90
|
-
hookTimeout: number;
|
|
91
104
|
clearMocks: boolean;
|
|
92
105
|
mockReset: boolean;
|
|
93
106
|
restoreMocks: boolean;
|
|
94
107
|
unstubGlobals: boolean;
|
|
95
108
|
unstubEnvs: boolean;
|
|
96
|
-
fakeTimers:
|
|
97
|
-
maxConcurrency: number;
|
|
109
|
+
fakeTimers: Config;
|
|
98
110
|
defines: Record<string, any>;
|
|
99
111
|
expect: {
|
|
100
112
|
requireAssertions?: boolean;
|
|
@@ -104,13 +116,6 @@ interface SerializedConfig {
|
|
|
104
116
|
};
|
|
105
117
|
};
|
|
106
118
|
printConsoleTrace: boolean | undefined;
|
|
107
|
-
sequence: {
|
|
108
|
-
shuffle?: boolean;
|
|
109
|
-
concurrent?: boolean;
|
|
110
|
-
seed: number;
|
|
111
|
-
hooks: SequenceHooks;
|
|
112
|
-
setupFiles: SequenceSetupFiles;
|
|
113
|
-
};
|
|
114
119
|
deps: {
|
|
115
120
|
web: {
|
|
116
121
|
transformAssets?: boolean;
|
|
@@ -145,8 +150,6 @@ interface SerializedConfig {
|
|
|
145
150
|
allowWrite: boolean | undefined;
|
|
146
151
|
};
|
|
147
152
|
diff: string | SerializedDiffOptions | undefined;
|
|
148
|
-
retry: SerializableRetry;
|
|
149
|
-
includeTaskLocation: boolean | undefined;
|
|
150
153
|
inspect: boolean | string | undefined;
|
|
151
154
|
inspectBrk: boolean | string | undefined;
|
|
152
155
|
inspector: {
|
|
@@ -170,6 +173,7 @@ interface SerializedConfig {
|
|
|
170
173
|
locators: {
|
|
171
174
|
testIdAttribute: string;
|
|
172
175
|
exact: boolean;
|
|
176
|
+
errorFormat: "html" | "aria" | "all";
|
|
173
177
|
};
|
|
174
178
|
screenshotFailures: boolean;
|
|
175
179
|
providerOptions: {
|
|
@@ -189,8 +193,11 @@ interface SerializedConfig {
|
|
|
189
193
|
detectAsyncLeaks: boolean;
|
|
190
194
|
coverage: SerializedCoverageConfig;
|
|
191
195
|
benchmark: {
|
|
192
|
-
|
|
193
|
-
|
|
196
|
+
enabled: boolean;
|
|
197
|
+
retainSamples: boolean;
|
|
198
|
+
suppressExportGetterWarnings: boolean;
|
|
199
|
+
projectName: string;
|
|
200
|
+
};
|
|
194
201
|
serializedDefines: string;
|
|
195
202
|
experimental: {
|
|
196
203
|
fsModuleCache: boolean;
|
|
@@ -211,12 +218,9 @@ interface SerializedConfig {
|
|
|
211
218
|
browserSdkPath?: string;
|
|
212
219
|
} | undefined;
|
|
213
220
|
};
|
|
214
|
-
tags: TestTagDefinition[];
|
|
215
|
-
tagsFilter: string[] | undefined;
|
|
216
|
-
strictTags: boolean;
|
|
217
221
|
mergeReportsLabel: string | undefined;
|
|
218
222
|
slowTestThreshold: number | undefined;
|
|
219
|
-
|
|
223
|
+
disableColors: boolean;
|
|
220
224
|
}
|
|
221
225
|
interface SerializedCoverageConfig {
|
|
222
226
|
provider: "istanbul" | "v8" | "custom" | undefined;
|
|
@@ -237,4 +241,4 @@ type RuntimeConfig = Pick<SerializedConfig, "allowOnly" | "testTimeout" | "hookT
|
|
|
237
241
|
type RuntimeOptions = Partial<RuntimeConfig>;
|
|
238
242
|
type BrowserTraceViewMode = "on" | "off" | "on-first-retry" | "on-all-retries" | "retain-on-failure";
|
|
239
243
|
|
|
240
|
-
export type { BrowserTraceViewMode as B,
|
|
244
|
+
export type { BrowserTraceViewMode as B, Config as C, RuntimeOptions as R, SerializedRootConfig as S, SerializedConfig as a, RuntimeConfig as b, SerializedCoverageConfig as c };
|
|
@@ -78,7 +78,7 @@ import { render } from 'vitest-browser-vue'
|
|
|
78
78
|
import HelloWorld from './HelloWorld.vue'
|
|
79
79
|
|
|
80
80
|
test('renders name', async () => {
|
|
81
|
-
const { getByText } = render(HelloWorld, {
|
|
81
|
+
const { getByText } = await render(HelloWorld, {
|
|
82
82
|
props: { name: 'Vitest' },
|
|
83
83
|
})
|
|
84
84
|
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
@@ -107,7 +107,7 @@ import { render } from 'vitest-browser-svelte'
|
|
|
107
107
|
import HelloWorld from './HelloWorld.svelte'
|
|
108
108
|
|
|
109
109
|
test('renders name', async () => {
|
|
110
|
-
const { getByText } = render(HelloWorld, { name: 'Vitest' })
|
|
110
|
+
const { getByText } = await render(HelloWorld, { name: 'Vitest' })
|
|
111
111
|
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
112
112
|
})
|
|
113
113
|
`
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import nodeos__default from 'node:os';
|
|
2
|
-
import './env.
|
|
2
|
+
import './env.BKKtU2WC.js';
|
|
3
3
|
import { isCI, isAgent } from 'std-env';
|
|
4
4
|
|
|
5
5
|
const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
|
|
6
6
|
const defaultExclude = ["**/node_modules/**", "**/.git/**"];
|
|
7
7
|
const benchmarkConfigDefaults = {
|
|
8
|
+
enabled: false,
|
|
8
9
|
include: ["**/*.{bench,benchmark}.?(c|m)[jt]s?(x)"],
|
|
9
10
|
exclude: defaultExclude,
|
|
10
11
|
includeSource: [],
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
retainSamples: false,
|
|
13
|
+
suppressExportGetterWarnings: false,
|
|
14
|
+
projectName: ""
|
|
13
15
|
};
|
|
14
16
|
// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
|
|
15
17
|
const coverageConfigDefaults = {
|
|
@@ -57,7 +59,7 @@ const configDefaults = Object.freeze({
|
|
|
57
59
|
include: defaultInclude,
|
|
58
60
|
exclude: defaultExclude,
|
|
59
61
|
teardownTimeout: 1e4,
|
|
60
|
-
forceRerunTriggers: ["**/package.json
|
|
62
|
+
forceRerunTriggers: ["**/package.json", "**/{vitest,vite}.config.*"],
|
|
61
63
|
update: false,
|
|
62
64
|
reporters: [isAgent ? "minimal" : "default", ...process.env.GITHUB_ACTIONS === "true" ? ["github-actions"] : []],
|
|
63
65
|
silent: false,
|
|
@@ -4,5 +4,6 @@ const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.v
|
|
|
4
4
|
const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
|
|
5
5
|
const isWindows = (isNode || isDeno) && process.platform === "win32";
|
|
6
6
|
const isTTY = (isNode || isDeno) && process.stdout?.isTTY && !isCI;
|
|
7
|
+
const isForceColor = () => "FORCE_COLOR" in process.env;
|
|
7
8
|
|
|
8
|
-
export {
|
|
9
|
+
export { isTTY as a, isWindows as b, isForceColor as i };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { P as PromisifyAssertion, T as Tester, E as ExpectStatic } from './browser.d.BGxB4Xum.js';
|
|
2
|
+
import { Plugin } from '@vitest/pretty-format';
|
|
3
|
+
import { BaselineData, Test } from '@vitest/runner';
|
|
4
|
+
import { i as SnapshotState, U as UserConsoleLog } from './general.d.DFAHgpC2.js';
|
|
5
|
+
import { TaskResultCompleted, TaskResultRuntimeInfo, TaskResultTimestampProviderInfo, Fn, FnOptions, BenchOptions } from 'tinybench';
|
|
6
|
+
|
|
7
|
+
type ExtractBenchNames<T extends BenchRegistration<any>[]> = Exclude<{ [K in keyof T] : T[K] extends BenchRegistration<infer N> ? N : never }[number], never>;
|
|
8
|
+
type BenchResult = TaskResultCompleted & TaskResultRuntimeInfo & TaskResultTimestampProviderInfo;
|
|
9
|
+
interface BenchStorage<T extends string> {
|
|
10
|
+
get: (name: T) => BenchResult;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options accepted by `bench(name, options, fn)`. Extends tinybench's
|
|
15
|
+
* `FnOptions` with Vitest-specific fields.
|
|
16
|
+
*/
|
|
17
|
+
interface BenchFnOptions extends FnOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Path (relative to the project root) where the benchmark result is written
|
|
20
|
+
* after a successful run. The string `${projectName}` is substituted with
|
|
21
|
+
* the current project name. Absolute paths are accepted as long as they
|
|
22
|
+
* resolve inside the project root.
|
|
23
|
+
*/
|
|
24
|
+
writeResult?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Mark this benchmark as a per-project entry. Per-project tasks still appear
|
|
27
|
+
* in the inline comparison table for the current run, and Vitest additionally
|
|
28
|
+
* collects them across projects and prints a single cross-project table at
|
|
29
|
+
* the end of the run.
|
|
30
|
+
*/
|
|
31
|
+
perProject?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface BenchRegistration<Name extends string> {
|
|
34
|
+
name: Name;
|
|
35
|
+
/**
|
|
36
|
+
* The benchmark function. Absent for registrations created via `bench.from()`.
|
|
37
|
+
*/
|
|
38
|
+
fn?: Fn;
|
|
39
|
+
/**
|
|
40
|
+
* Per-benchmark options (`beforeEach`, `beforeAll`, etc.). Absent for
|
|
41
|
+
* registrations created via `bench.from()`.
|
|
42
|
+
*/
|
|
43
|
+
fnOpts?: FnOptions;
|
|
44
|
+
run: (options?: BenchOptions) => Promise<BenchResult>;
|
|
45
|
+
}
|
|
46
|
+
interface BenchCompare {
|
|
47
|
+
<Args extends BenchRegistration<any>[]>(...args: Args): Promise<BenchStorage<ExtractBenchNames<Args>>>;
|
|
48
|
+
<Args extends BenchRegistration<any>[]>(...args: [...Args, BenchOptions]): Promise<BenchStorage<ExtractBenchNames<Args>>>;
|
|
49
|
+
}
|
|
50
|
+
interface BenchFactory {
|
|
51
|
+
<Name extends string>(name: Name | Function, fn: Fn): BenchRegistration<Name>;
|
|
52
|
+
<Name extends string>(name: Name | Function, options: BenchFnOptions, fn: Fn): BenchRegistration<Name>;
|
|
53
|
+
}
|
|
54
|
+
interface BenchFromSource {
|
|
55
|
+
(): BaselineData | Promise<BaselineData>;
|
|
56
|
+
}
|
|
57
|
+
interface BenchFrom {
|
|
58
|
+
<Name extends string>(name: Name | Function, source: string | BenchFromSource): BenchRegistration<Name>;
|
|
59
|
+
}
|
|
60
|
+
interface Bench extends BenchFactory {
|
|
61
|
+
compare: BenchCompare;
|
|
62
|
+
from: BenchFrom;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface SnapshotMatcher<T> {
|
|
66
|
+
<U extends { [P in keyof T] : any }>(snapshot: Partial<U>, hint?: string): void;
|
|
67
|
+
(hint?: string): void;
|
|
68
|
+
}
|
|
69
|
+
interface InlineSnapshotMatcher<T> {
|
|
70
|
+
<U extends { [P in keyof T] : any }>(properties: Partial<U>, snapshot?: string, hint?: string): void;
|
|
71
|
+
(hint?: string): void;
|
|
72
|
+
}
|
|
73
|
+
declare module "vitest" {
|
|
74
|
+
interface MatcherState {
|
|
75
|
+
environment: string;
|
|
76
|
+
snapshotState: SnapshotState;
|
|
77
|
+
task?: Readonly<Test>;
|
|
78
|
+
}
|
|
79
|
+
interface ExpectPollOptions {
|
|
80
|
+
interval?: number;
|
|
81
|
+
timeout?: number;
|
|
82
|
+
message?: string;
|
|
83
|
+
}
|
|
84
|
+
interface ExpectStatic {
|
|
85
|
+
assert: Chai.AssertStatic;
|
|
86
|
+
unreachable: (message?: string) => never;
|
|
87
|
+
soft: <T>(actual: T, message?: string) => Assertion<T>;
|
|
88
|
+
poll: <T>(actual: (options: {
|
|
89
|
+
signal: AbortSignal;
|
|
90
|
+
}) => T, options?: ExpectPollOptions) => PromisifyAssertion<Awaited<T>>;
|
|
91
|
+
addEqualityTesters: (testers: Array<Tester>) => void;
|
|
92
|
+
assertions: (expected: number) => void;
|
|
93
|
+
hasAssertions: () => void;
|
|
94
|
+
addSnapshotSerializer: (plugin: Plugin) => void;
|
|
95
|
+
}
|
|
96
|
+
interface Assertion<T> {
|
|
97
|
+
matchSnapshot: SnapshotMatcher<T>;
|
|
98
|
+
toMatchSnapshot: SnapshotMatcher<T>;
|
|
99
|
+
toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
|
|
100
|
+
/**
|
|
101
|
+
* Checks that an error thrown by a function matches a previously recorded snapshot.
|
|
102
|
+
*
|
|
103
|
+
* @param hint - Optional custom error message.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* expect(functionWithError).toThrowErrorMatchingSnapshot();
|
|
107
|
+
*/
|
|
108
|
+
toThrowErrorMatchingSnapshot: (hint?: string) => void;
|
|
109
|
+
/**
|
|
110
|
+
* Checks that an error thrown by a function matches an inline snapshot within the test file.
|
|
111
|
+
* Useful for keeping snapshots close to the test code.
|
|
112
|
+
*
|
|
113
|
+
* @param snapshot - Optional inline snapshot string to match.
|
|
114
|
+
* @param hint - Optional custom error message.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* const throwError = () => { throw new Error('Error occurred') };
|
|
118
|
+
* expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
|
|
119
|
+
*/
|
|
120
|
+
toThrowErrorMatchingInlineSnapshot: (snapshot?: string, hint?: string) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Compares the received value to a snapshot saved in a specified file.
|
|
123
|
+
* Useful for cases where snapshot content is large or needs to be shared across tests.
|
|
124
|
+
*
|
|
125
|
+
* @param filepath - Path to the snapshot file.
|
|
126
|
+
* @param hint - Optional custom error message.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
|
|
130
|
+
*/
|
|
131
|
+
toMatchFileSnapshot: (filepath: string, hint?: string) => Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Asserts that a benchmark result is faster than another benchmark result.
|
|
134
|
+
* Compares mean latency — lower is faster.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* const result = await bench.compare(
|
|
138
|
+
* bench('lib1', () => { lib1() }),
|
|
139
|
+
* bench('lib2', () => { lib2() }),
|
|
140
|
+
* )
|
|
141
|
+
* expect(result.get('lib1')).toBeFasterThan(result.get('lib2'))
|
|
142
|
+
* expect(result.get('lib1')).toBeFasterThan(result.get('lib2'), { delta: 0.1 })
|
|
143
|
+
*/
|
|
144
|
+
toBeFasterThan: (expected: BenchResult, options?: {
|
|
145
|
+
delta?: number;
|
|
146
|
+
}) => void;
|
|
147
|
+
/**
|
|
148
|
+
* Asserts that a benchmark result is slower than another benchmark result.
|
|
149
|
+
* Compares mean latency — higher is slower.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* const result = await bench.compare(
|
|
153
|
+
* bench('lib1', () => { lib1() }),
|
|
154
|
+
* bench('lib2', () => { lib2() }),
|
|
155
|
+
* )
|
|
156
|
+
* expect(result.get('lib2')).toBeSlowerThan(result.get('lib1'))
|
|
157
|
+
* expect(result.get('lib2')).toBeSlowerThan(result.get('lib1'), { delta: 0.2 })
|
|
158
|
+
*/
|
|
159
|
+
toBeSlowerThan: (expected: BenchResult, options?: {
|
|
160
|
+
delta?: number;
|
|
161
|
+
}) => void;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
declare module "@vitest/runner" {
|
|
165
|
+
interface TestContext {
|
|
166
|
+
/**
|
|
167
|
+
* `expect` instance bound to the current test.
|
|
168
|
+
*
|
|
169
|
+
* This API is useful for running snapshot tests concurrently because global expect cannot track them.
|
|
170
|
+
*/
|
|
171
|
+
readonly expect: ExpectStatic;
|
|
172
|
+
/**
|
|
173
|
+
* Create a benchmark to run. It will be reported after the test is finished.
|
|
174
|
+
* @see {@link https://vitest.dev/guide/benchmarking}
|
|
175
|
+
*/
|
|
176
|
+
readonly bench: Bench;
|
|
177
|
+
/** @internal */
|
|
178
|
+
_local: boolean;
|
|
179
|
+
}
|
|
180
|
+
interface TaskMeta {
|
|
181
|
+
typecheck?: boolean;
|
|
182
|
+
benchmark?: boolean;
|
|
183
|
+
__vitest_label__?: string;
|
|
184
|
+
}
|
|
185
|
+
interface File {
|
|
186
|
+
prepareDuration?: number;
|
|
187
|
+
environmentLoad?: number;
|
|
188
|
+
}
|
|
189
|
+
interface TaskBase {
|
|
190
|
+
logs?: UserConsoleLog[];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type { Bench as B, BenchFnOptions as a, BenchFromSource as b, BenchRegistration as c, BenchResult as d, BenchStorage as e };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { g as globalApis } from './constants.-juJ8b_4.js';
|
|
2
|
-
import { i as index } from './index.
|
|
2
|
+
import { i as index } from './index.CE58PZNH.js';
|
|
3
3
|
import '@vitest/runner';
|
|
4
4
|
import './utils.BX5Fg8C4.js';
|
|
5
5
|
import '@vitest/utils/timers';
|
|
@@ -20,6 +20,7 @@ import '@vitest/pretty-format';
|
|
|
20
20
|
import '@vitest/utils/diff';
|
|
21
21
|
import '@vitest/utils/display';
|
|
22
22
|
import 'tinyrainbow';
|
|
23
|
+
import 'tinybench';
|
|
23
24
|
import 'expect-type';
|
|
24
25
|
|
|
25
26
|
function registerApiGlobally() {
|