vitest 5.0.0-beta.3 → 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.Bay6B1Dz.js → base.BEGVMQrS.js} +6 -6
- package/dist/chunks/{browser.d.DM1g8UNp.d.ts → browser.d.BGxB4Xum.d.ts} +4 -25
- package/dist/chunks/{cac.DoK9yX-i.js → cac.CyXAEMkE.js} +22 -31
- package/dist/chunks/{cli-api.BCY9ylNq.js → cli-api.DJMXq34b.js} +502 -549
- package/dist/chunks/{config.d.C0UMwus7.d.ts → config.d.DXq1aBpy.d.ts} +7 -26
- package/dist/chunks/{creator.BqL2U_x4.js → creator.D66cVXYh.js} +2 -2
- package/dist/chunks/{defaults.DVfzlTkU.js → defaults.CUUnbOrq.js} +5 -3
- package/dist/chunks/global.d.BtKPuz2X.d.ts +194 -0
- package/dist/chunks/{globals.8_qjZdeE.js → globals.BuY-yD0m.js} +2 -1
- package/dist/chunks/{index.ukHtlBbI.js → index.CE58PZNH.js} +355 -146
- package/dist/chunks/{index.PuMGMNHF.js → index.CcluKS59.js} +4 -4
- package/dist/chunks/{index.CbgUM9E5.js → index.nQFVd50u.js} +2 -1
- package/dist/chunks/{init-forks.OoZmDo1g.js → init-forks.Ce3vGWgL.js} +1 -1
- package/dist/chunks/{init-threads.eSHAowcx.js → init-threads.8e1OLv5v.js} +1 -1
- package/dist/chunks/{init.YjNsCb-_.js → init.6qx-LaHs.js} +30 -2
- package/dist/chunks/{nativeModuleMocker.DKpFw0pk.js → nativeModuleMocker.DDZfQXLs.js} +1 -1
- package/dist/chunks/{plugin.d.C00LxKL6.d.ts → plugin.d.B7MTG_Fe.d.ts} +71 -82
- package/dist/chunks/{rpc.d.7JZuxZ8u.d.ts → rpc.d.OQ_EZi1Z.d.ts} +18 -2
- package/dist/chunks/{setup-common.eQsbxe88.js → setup-common.DdEF_hkE.js} +1 -1
- package/dist/chunks/{vm.BE_VOfSs.js → vm.Bu7mmcZq.js} +2 -2
- package/dist/chunks/{worker.d.Dv3hDCFf.d.ts → worker.d.yR22cs6X.d.ts} +3 -2
- package/dist/cli.js +1 -1
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +6 -8
- package/dist/config.js +1 -1
- package/dist/index.d.ts +23 -40
- package/dist/index.js +2 -1
- package/dist/module-evaluator.d.ts +4 -1
- package/dist/module-evaluator.js +14 -19
- package/dist/node.d.ts +20 -12
- package/dist/node.js +5 -5
- 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 +15 -15
- package/dist/chunks/global.d.DZbA5YnY.d.ts +0 -101
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
@@ -90,8 +90,7 @@ type NodeImmediate = {
|
|
|
90
90
|
/**
|
|
91
91
|
* Config that tests have access to.
|
|
92
92
|
*/
|
|
93
|
-
interface SerializedConfig {
|
|
94
|
-
name: string | undefined;
|
|
93
|
+
interface SerializedConfig extends VitestRunnerConfig {
|
|
95
94
|
color?: LabelColor;
|
|
96
95
|
globals: boolean;
|
|
97
96
|
base: string | undefined;
|
|
@@ -100,23 +99,14 @@ interface SerializedConfig {
|
|
|
100
99
|
runner: string | undefined;
|
|
101
100
|
isolate: boolean;
|
|
102
101
|
maxWorkers: number;
|
|
103
|
-
mode: "test" | "benchmark";
|
|
104
102
|
bail: number | undefined;
|
|
105
103
|
environmentOptions?: Record<string, any>;
|
|
106
|
-
root: string;
|
|
107
|
-
setupFiles: string[];
|
|
108
|
-
passWithNoTests: boolean;
|
|
109
|
-
testNamePattern: RegExp | undefined;
|
|
110
|
-
allowOnly: boolean;
|
|
111
|
-
testTimeout: number;
|
|
112
|
-
hookTimeout: number;
|
|
113
104
|
clearMocks: boolean;
|
|
114
105
|
mockReset: boolean;
|
|
115
106
|
restoreMocks: boolean;
|
|
116
107
|
unstubGlobals: boolean;
|
|
117
108
|
unstubEnvs: boolean;
|
|
118
109
|
fakeTimers: Config;
|
|
119
|
-
maxConcurrency: number;
|
|
120
110
|
defines: Record<string, any>;
|
|
121
111
|
expect: {
|
|
122
112
|
requireAssertions?: boolean;
|
|
@@ -126,13 +116,6 @@ interface SerializedConfig {
|
|
|
126
116
|
};
|
|
127
117
|
};
|
|
128
118
|
printConsoleTrace: boolean | undefined;
|
|
129
|
-
sequence: {
|
|
130
|
-
shuffle?: boolean;
|
|
131
|
-
concurrent?: boolean;
|
|
132
|
-
seed: number;
|
|
133
|
-
hooks: SequenceHooks;
|
|
134
|
-
setupFiles: SequenceSetupFiles;
|
|
135
|
-
};
|
|
136
119
|
deps: {
|
|
137
120
|
web: {
|
|
138
121
|
transformAssets?: boolean;
|
|
@@ -167,8 +150,6 @@ interface SerializedConfig {
|
|
|
167
150
|
allowWrite: boolean | undefined;
|
|
168
151
|
};
|
|
169
152
|
diff: string | SerializedDiffOptions | undefined;
|
|
170
|
-
retry: SerializableRetry;
|
|
171
|
-
includeTaskLocation: boolean | undefined;
|
|
172
153
|
inspect: boolean | string | undefined;
|
|
173
154
|
inspectBrk: boolean | string | undefined;
|
|
174
155
|
inspector: {
|
|
@@ -212,8 +193,11 @@ interface SerializedConfig {
|
|
|
212
193
|
detectAsyncLeaks: boolean;
|
|
213
194
|
coverage: SerializedCoverageConfig;
|
|
214
195
|
benchmark: {
|
|
215
|
-
|
|
216
|
-
|
|
196
|
+
enabled: boolean;
|
|
197
|
+
retainSamples: boolean;
|
|
198
|
+
suppressExportGetterWarnings: boolean;
|
|
199
|
+
projectName: string;
|
|
200
|
+
};
|
|
217
201
|
serializedDefines: string;
|
|
218
202
|
experimental: {
|
|
219
203
|
fsModuleCache: boolean;
|
|
@@ -234,9 +218,6 @@ interface SerializedConfig {
|
|
|
234
218
|
browserSdkPath?: string;
|
|
235
219
|
} | undefined;
|
|
236
220
|
};
|
|
237
|
-
tags: TestTagDefinition[];
|
|
238
|
-
tagsFilter: string[] | undefined;
|
|
239
|
-
strictTags: boolean;
|
|
240
221
|
mergeReportsLabel: string | undefined;
|
|
241
222
|
slowTestThreshold: number | undefined;
|
|
242
223
|
disableColors: boolean;
|
|
@@ -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
|
`
|
|
@@ -5,11 +5,13 @@ import { isCI, isAgent } from 'std-env';
|
|
|
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,
|
|
@@ -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() {
|