vitest 0.28.4 → 0.29.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 +1 -1
- package/coverage.d.ts +1 -0
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +4 -4
- package/dist/child.js +89 -0
- package/dist/{chunk-api-setup.ec61b167.js → chunk-api-setup.d9eccaeb.js} +5 -5
- package/dist/{chunk-env-node.ffd1183b.js → chunk-env-node.affdd278.js} +1 -2
- package/dist/{chunk-install-pkg.13d8e7be.js → chunk-install-pkg.ea1a5ef4.js} +9 -8
- package/dist/chunk-integrations-coverage.e0a6acd2.js +51 -0
- package/dist/{chunk-integrations-globals.aacbac4d.js → chunk-integrations-globals.b56fcb06.js} +8 -8
- package/dist/{chunk-integrations-run-once.38756e30.js → chunk-integrations-run-once.9012f759.js} +1 -1
- package/dist/{chunk-integrations-utils.dae69d89.js → chunk-integrations-utils.233d6a3b.js} +2 -2
- package/dist/{chunk-node-git.d9ad64ab.js → chunk-node-git.ed5bded8.js} +1 -2
- package/dist/{chunk-node-pkg.94145502.js → chunk-node-pkg.88e7e848.js} +4423 -270
- package/dist/{chunk-runtime-mocker.eb0c265c.js → chunk-runtime-mocker.a048e92d.js} +83 -47
- package/dist/chunk-runtime-rpc.971b3848.js +61 -0
- package/dist/{chunk-runtime-setup.7dfc1a6a.js → chunk-runtime-setup.992bb661.js} +2 -2
- package/dist/{chunk-snapshot-env.6457638e.js → chunk-snapshot-env.a347d647.js} +2 -2
- package/dist/{chunk-utils-base.904102a8.js → chunk-utils-base.81f83dbd.js} +15 -1
- package/dist/{chunk-utils-global.442d1d33.js → chunk-utils-global.727b6d25.js} +1 -7
- package/dist/{chunk-utils-import.0402c9db.js → chunk-utils-import.ec15dcad.js} +18 -29
- package/dist/{chunk-utils-tasks.a9a8d8e1.js → chunk-utils-tasks.b41c8284.js} +14 -10
- package/dist/cli-wrapper.js +1 -2
- package/dist/cli.js +12 -11
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +8 -7
- package/dist/config.js +1 -1
- package/dist/coverage.d.ts +142 -0
- package/dist/coverage.js +49 -0
- package/dist/entry.js +51 -84
- package/dist/environments.d.ts +2 -1
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +9 -9
- package/dist/loader.js +2 -2
- package/dist/node.d.ts +9 -10
- package/dist/node.js +14 -12
- package/dist/runners.d.ts +4 -1
- package/dist/runners.js +221 -13
- package/dist/{types-aac763a5.d.ts → types-7cd96283.d.ts} +164 -39
- package/dist/{vendor-index.618ca5a1.js → vendor-index.2cbcdd1e.js} +18 -13
- package/dist/worker.js +14 -56
- package/package.json +16 -10
- package/dist/chunk-integrations-coverage.48e6286b.js +0 -3993
- package/dist/chunk-runtime-rpc.9c0386cc.js +0 -31
- package/dist/runners-chunk.js +0 -215
package/dist/node.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-node-pkg.
|
|
2
|
-
export { V as
|
|
1
|
+
export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-node-pkg.88e7e848.js';
|
|
2
|
+
export { V as VitestExecutor } from './chunk-runtime-mocker.a048e92d.js';
|
|
3
3
|
import 'pathe';
|
|
4
4
|
import './chunk-constants.797d3ebf.js';
|
|
5
5
|
import 'node:url';
|
|
6
6
|
import './chunk-utils-env.860d90c2.js';
|
|
7
7
|
import 'std-env';
|
|
8
|
-
import './chunk-integrations-coverage.
|
|
8
|
+
import './chunk-integrations-coverage.e0a6acd2.js';
|
|
9
9
|
import 'local-pkg';
|
|
10
|
-
import '
|
|
11
|
-
import 'path';
|
|
12
|
-
import './chunk-env-node.ffd1183b.js';
|
|
10
|
+
import './chunk-env-node.affdd278.js';
|
|
13
11
|
import 'node:console';
|
|
14
12
|
import 'picocolors';
|
|
15
13
|
import 'vite';
|
|
16
14
|
import 'node:path';
|
|
17
15
|
import 'node:process';
|
|
18
16
|
import 'node:fs';
|
|
17
|
+
import 'path';
|
|
19
18
|
import 'os';
|
|
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.
|
|
26
|
+
import './chunk-utils-global.727b6d25.js';
|
|
27
27
|
import '@vitest/runner/utils';
|
|
28
28
|
import '@vitest/utils';
|
|
29
29
|
import 'node:fs/promises';
|
|
30
|
-
import './vendor-index.
|
|
30
|
+
import './vendor-index.2cbcdd1e.js';
|
|
31
31
|
import 'node:buffer';
|
|
32
32
|
import 'node:child_process';
|
|
33
33
|
import 'child_process';
|
|
@@ -38,12 +38,13 @@ import 'source-map';
|
|
|
38
38
|
import 'module';
|
|
39
39
|
import 'acorn';
|
|
40
40
|
import 'acorn-walk';
|
|
41
|
+
import 'node:v8';
|
|
42
|
+
import './vendor-index.783e7f3e.js';
|
|
43
|
+
import './chunk-utils-base.81f83dbd.js';
|
|
41
44
|
import 'node:worker_threads';
|
|
42
45
|
import 'tinypool';
|
|
43
|
-
import './vendor-index.783e7f3e.js';
|
|
44
46
|
import 'perf_hooks';
|
|
45
|
-
import './chunk-utils-
|
|
46
|
-
import './chunk-utils-tasks.a9a8d8e1.js';
|
|
47
|
+
import './chunk-utils-tasks.b41c8284.js';
|
|
47
48
|
import 'crypto';
|
|
48
49
|
import 'vite-node/utils';
|
|
49
50
|
import '@vitest/utils/diff';
|
|
@@ -54,5 +55,6 @@ import 'readline';
|
|
|
54
55
|
import './vendor-index.bdee400f.js';
|
|
55
56
|
import 'node:module';
|
|
56
57
|
import 'node:assert';
|
|
57
|
-
import 'node:v8';
|
|
58
58
|
import 'node:util';
|
|
59
|
+
import '@vitest/spy';
|
|
60
|
+
import './chunk-runtime-rpc.971b3848.js';
|
package/dist/runners.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VitestRunner, VitestRunnerImportSource, Suite, Test, TestContext } from '@vitest/runner';
|
|
2
|
-
import { a as ResolvedConfig } from './types-
|
|
2
|
+
import { a as ResolvedConfig } from './types-7cd96283.js';
|
|
3
3
|
import '@vitest/expect';
|
|
4
4
|
import 'vite';
|
|
5
5
|
import '@vitest/runner/types';
|
|
@@ -10,12 +10,14 @@ import 'vite-node/client';
|
|
|
10
10
|
import 'vite-node/server';
|
|
11
11
|
import 'node:worker_threads';
|
|
12
12
|
import 'vite-node';
|
|
13
|
+
import 'source-map';
|
|
13
14
|
import 'node:fs';
|
|
14
15
|
|
|
15
16
|
declare class VitestTestRunner implements VitestRunner {
|
|
16
17
|
config: ResolvedConfig;
|
|
17
18
|
private snapshotClient;
|
|
18
19
|
private workerState;
|
|
20
|
+
private __vitest_executor;
|
|
19
21
|
constructor(config: ResolvedConfig);
|
|
20
22
|
importFile(filepath: string, source: VitestRunnerImportSource): unknown;
|
|
21
23
|
onBeforeRun(): void;
|
|
@@ -30,6 +32,7 @@ declare class VitestTestRunner implements VitestRunner {
|
|
|
30
32
|
|
|
31
33
|
declare class NodeBenchmarkRunner implements VitestRunner {
|
|
32
34
|
config: ResolvedConfig;
|
|
35
|
+
private __vitest_executor;
|
|
33
36
|
constructor(config: ResolvedConfig);
|
|
34
37
|
importFile(filepath: string, source: VitestRunnerImportSource): unknown;
|
|
35
38
|
runSuite(suite: Suite): Promise<void>;
|
package/dist/runners.js
CHANGED
|
@@ -1,18 +1,226 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import './chunk-utils-
|
|
4
|
-
import '
|
|
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.ec15dcad.js';
|
|
3
|
+
import { g as getWorkerState } from './chunk-utils-global.727b6d25.js';
|
|
4
|
+
import { g as getFullName } from './chunk-utils-tasks.b41c8284.js';
|
|
5
|
+
import { updateTask } from '@vitest/runner';
|
|
6
|
+
import { createDefer, getSafeTimers } from '@vitest/utils';
|
|
5
7
|
import '@vitest/runner/utils';
|
|
6
|
-
import '@vitest/utils';
|
|
7
|
-
import './chunk-utils-global.442d1d33.js';
|
|
8
|
-
import 'pathe';
|
|
9
|
-
import './chunk-utils-env.860d90c2.js';
|
|
10
|
-
import 'std-env';
|
|
11
8
|
import 'chai';
|
|
12
9
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
13
|
-
import './chunk-runtime-rpc.
|
|
14
|
-
import '
|
|
15
|
-
import './chunk-
|
|
16
|
-
import './chunk-utils-
|
|
10
|
+
import './chunk-runtime-rpc.971b3848.js';
|
|
11
|
+
import 'pathe';
|
|
12
|
+
import './chunk-snapshot-env.a347d647.js';
|
|
13
|
+
import './chunk-utils-base.81f83dbd.js';
|
|
17
14
|
import 'util';
|
|
18
15
|
import '@vitest/spy';
|
|
16
|
+
import './chunk-utils-env.860d90c2.js';
|
|
17
|
+
import 'std-env';
|
|
18
|
+
|
|
19
|
+
class VitestTestRunner {
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.snapshotClient = getSnapshotClient();
|
|
23
|
+
this.workerState = getWorkerState();
|
|
24
|
+
}
|
|
25
|
+
importFile(filepath, source) {
|
|
26
|
+
if (source === "setup")
|
|
27
|
+
this.workerState.moduleCache.delete(filepath);
|
|
28
|
+
return this.__vitest_executor.executeId(filepath);
|
|
29
|
+
}
|
|
30
|
+
onBeforeRun() {
|
|
31
|
+
this.snapshotClient.clear();
|
|
32
|
+
}
|
|
33
|
+
async onAfterRun() {
|
|
34
|
+
await this.snapshotClient.saveCurrent();
|
|
35
|
+
}
|
|
36
|
+
onAfterRunSuite(suite) {
|
|
37
|
+
if (this.config.logHeapUsage && typeof process !== "undefined")
|
|
38
|
+
suite.result.heap = process.memoryUsage().heapUsed;
|
|
39
|
+
}
|
|
40
|
+
onAfterRunTest(test) {
|
|
41
|
+
this.snapshotClient.clearTest();
|
|
42
|
+
if (this.config.logHeapUsage && typeof process !== "undefined")
|
|
43
|
+
test.result.heap = process.memoryUsage().heapUsed;
|
|
44
|
+
this.workerState.current = void 0;
|
|
45
|
+
}
|
|
46
|
+
async onBeforeRunTest(test) {
|
|
47
|
+
if (test.mode !== "run") {
|
|
48
|
+
this.snapshotClient.skipTestSnapshots(test);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
clearModuleMocks(this.config);
|
|
52
|
+
await this.snapshotClient.setTest(test);
|
|
53
|
+
this.workerState.current = test;
|
|
54
|
+
}
|
|
55
|
+
onBeforeTryTest(test) {
|
|
56
|
+
var _a;
|
|
57
|
+
setState({
|
|
58
|
+
assertionCalls: 0,
|
|
59
|
+
isExpectingAssertions: false,
|
|
60
|
+
isExpectingAssertionsError: null,
|
|
61
|
+
expectedAssertionsNumber: null,
|
|
62
|
+
expectedAssertionsNumberErrorGen: null,
|
|
63
|
+
testPath: (_a = test.suite.file) == null ? void 0 : _a.filepath,
|
|
64
|
+
currentTestName: getFullName(test),
|
|
65
|
+
snapshotState: this.snapshotClient.snapshotState
|
|
66
|
+
}, globalThis[GLOBAL_EXPECT]);
|
|
67
|
+
}
|
|
68
|
+
onAfterTryTest(test) {
|
|
69
|
+
const {
|
|
70
|
+
assertionCalls,
|
|
71
|
+
expectedAssertionsNumber,
|
|
72
|
+
expectedAssertionsNumberErrorGen,
|
|
73
|
+
isExpectingAssertions,
|
|
74
|
+
isExpectingAssertionsError
|
|
75
|
+
} = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
76
|
+
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
|
|
77
|
+
throw expectedAssertionsNumberErrorGen();
|
|
78
|
+
if (isExpectingAssertions === true && assertionCalls === 0)
|
|
79
|
+
throw isExpectingAssertionsError;
|
|
80
|
+
}
|
|
81
|
+
extendTestContext(context) {
|
|
82
|
+
let _expect;
|
|
83
|
+
Object.defineProperty(context, "expect", {
|
|
84
|
+
get() {
|
|
85
|
+
if (!_expect)
|
|
86
|
+
_expect = createExpect(context.meta);
|
|
87
|
+
return _expect;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(context, "_local", {
|
|
91
|
+
get() {
|
|
92
|
+
return _expect != null;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return context;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function clearModuleMocks(config) {
|
|
99
|
+
const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
|
|
100
|
+
if (restoreMocks)
|
|
101
|
+
vi.restoreAllMocks();
|
|
102
|
+
else if (mockReset)
|
|
103
|
+
vi.resetAllMocks();
|
|
104
|
+
else if (clearMocks)
|
|
105
|
+
vi.clearAllMocks();
|
|
106
|
+
if (unstubEnvs)
|
|
107
|
+
vi.unstubAllEnvs();
|
|
108
|
+
if (unstubGlobals)
|
|
109
|
+
vi.unstubAllGlobals();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function importTinybench() {
|
|
113
|
+
if (!globalThis.EventTarget)
|
|
114
|
+
await import('./vendor-index.534e612c.js').then(function (n) { return n.i; });
|
|
115
|
+
return await import('tinybench');
|
|
116
|
+
}
|
|
117
|
+
function createBenchmarkResult(name) {
|
|
118
|
+
return {
|
|
119
|
+
name,
|
|
120
|
+
rank: 0,
|
|
121
|
+
rme: 0,
|
|
122
|
+
samples: []
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async function runBenchmarkSuite(suite, runner) {
|
|
126
|
+
var _a;
|
|
127
|
+
const { Task, Bench } = await importTinybench();
|
|
128
|
+
const start = performance.now();
|
|
129
|
+
const benchmarkGroup = [];
|
|
130
|
+
const benchmarkSuiteGroup = [];
|
|
131
|
+
for (const task of suite.tasks) {
|
|
132
|
+
if (task.mode !== "run")
|
|
133
|
+
continue;
|
|
134
|
+
if ((_a = task.meta) == null ? void 0 : _a.benchmark)
|
|
135
|
+
benchmarkGroup.push(task);
|
|
136
|
+
else if (task.type === "suite")
|
|
137
|
+
benchmarkSuiteGroup.push(task);
|
|
138
|
+
}
|
|
139
|
+
if (benchmarkSuiteGroup.length)
|
|
140
|
+
await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuite(subSuite, runner)));
|
|
141
|
+
if (benchmarkGroup.length) {
|
|
142
|
+
const defer = createDefer();
|
|
143
|
+
const benchmarkMap = {};
|
|
144
|
+
suite.result = {
|
|
145
|
+
state: "run",
|
|
146
|
+
startTime: start,
|
|
147
|
+
benchmark: createBenchmarkResult(suite.name)
|
|
148
|
+
};
|
|
149
|
+
updateTask$1(suite);
|
|
150
|
+
benchmarkGroup.forEach((benchmark, idx) => {
|
|
151
|
+
const options = getBenchOptions(benchmark);
|
|
152
|
+
const benchmarkInstance = new Bench(options);
|
|
153
|
+
const benchmarkFn = getBenchFn(benchmark);
|
|
154
|
+
benchmark.result = {
|
|
155
|
+
state: "run",
|
|
156
|
+
startTime: start,
|
|
157
|
+
benchmark: createBenchmarkResult(benchmark.name)
|
|
158
|
+
};
|
|
159
|
+
const id = idx.toString();
|
|
160
|
+
benchmarkMap[id] = benchmark;
|
|
161
|
+
const task = new Task(benchmarkInstance, id, benchmarkFn);
|
|
162
|
+
benchmark.meta.task = task;
|
|
163
|
+
updateTask$1(benchmark);
|
|
164
|
+
});
|
|
165
|
+
benchmarkGroup.forEach((benchmark) => {
|
|
166
|
+
benchmark.meta.task.addEventListener("complete", (e) => {
|
|
167
|
+
const task = e.task;
|
|
168
|
+
const _benchmark = benchmarkMap[task.name || ""];
|
|
169
|
+
if (_benchmark) {
|
|
170
|
+
const taskRes = task.result;
|
|
171
|
+
const result = _benchmark.result.benchmark;
|
|
172
|
+
Object.assign(result, taskRes);
|
|
173
|
+
updateTask$1(_benchmark);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
benchmark.meta.task.addEventListener("error", (e) => {
|
|
177
|
+
const task = e.task;
|
|
178
|
+
const _benchmark = benchmarkMap[task.name || ""];
|
|
179
|
+
defer.reject(_benchmark ? task.result.error : e);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
Promise.all(benchmarkGroup.map(async (benchmark) => {
|
|
183
|
+
await benchmark.meta.task.warmup();
|
|
184
|
+
const { setTimeout } = getSafeTimers();
|
|
185
|
+
return await new Promise((resolve) => setTimeout(async () => {
|
|
186
|
+
resolve(await benchmark.meta.task.run());
|
|
187
|
+
}));
|
|
188
|
+
})).then((tasks) => {
|
|
189
|
+
suite.result.duration = performance.now() - start;
|
|
190
|
+
suite.result.state = "pass";
|
|
191
|
+
tasks.sort((a, b) => a.result.mean - b.result.mean).forEach((cycle, idx) => {
|
|
192
|
+
const benchmark = benchmarkMap[cycle.name || ""];
|
|
193
|
+
benchmark.result.state = "pass";
|
|
194
|
+
if (benchmark) {
|
|
195
|
+
const result = benchmark.result.benchmark;
|
|
196
|
+
result.rank = Number(idx) + 1;
|
|
197
|
+
updateTask$1(benchmark);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
updateTask$1(suite);
|
|
201
|
+
defer.resolve(null);
|
|
202
|
+
});
|
|
203
|
+
await defer;
|
|
204
|
+
}
|
|
205
|
+
function updateTask$1(task) {
|
|
206
|
+
updateTask(task, runner);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
class NodeBenchmarkRunner {
|
|
210
|
+
constructor(config) {
|
|
211
|
+
this.config = config;
|
|
212
|
+
}
|
|
213
|
+
importFile(filepath, source) {
|
|
214
|
+
if (source === "setup")
|
|
215
|
+
getWorkerState().moduleCache.delete(filepath);
|
|
216
|
+
return this.__vitest_executor.executeId(filepath);
|
|
217
|
+
}
|
|
218
|
+
async runSuite(suite) {
|
|
219
|
+
await runBenchmarkSuite(suite, this);
|
|
220
|
+
}
|
|
221
|
+
async runTest() {
|
|
222
|
+
throw new Error("`test()` and `it()` is only available in test mode.");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export { NodeBenchmarkRunner, VitestTestRunner };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { MatchersObject, MatcherState } from '@vitest/expect';
|
|
2
|
-
import { UserConfig as UserConfig$1, ViteDevServer, CommonServerOptions, AliasOptions } from 'vite';
|
|
2
|
+
import { UserConfig as UserConfig$1, ViteDevServer, CommonServerOptions, DepOptimizationConfig, AliasOptions } from 'vite';
|
|
3
3
|
import { File, Test as Test$1, Suite, TaskResultPack, Task } from '@vitest/runner/types';
|
|
4
4
|
import * as _vitest_runner from '@vitest/runner';
|
|
5
|
-
import { Task as Task$1,
|
|
5
|
+
import { Task as Task$1, Test as Test$2, TaskCustom } from '@vitest/runner';
|
|
6
6
|
import { ParsedStack, ErrorWithDiff, ChainableFunction } from '@vitest/runner/utils';
|
|
7
7
|
import { Arrayable as Arrayable$1 } from '@vitest/utils';
|
|
8
8
|
import { Task as Task$2, TaskResult, Bench, Options } from 'tinybench';
|
|
9
9
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
10
10
|
import { ViteNodeServer } from 'vite-node/server';
|
|
11
11
|
import { MessagePort } from 'node:worker_threads';
|
|
12
|
-
import { RawSourceMap,
|
|
12
|
+
import { RawSourceMap, FetchResult, ViteNodeResolveId, ModuleCacheMap } from 'vite-node';
|
|
13
|
+
import { RawSourceMap as RawSourceMap$1 } from 'source-map';
|
|
13
14
|
import { Stats } from 'node:fs';
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -252,7 +253,7 @@ declare class Typechecker {
|
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
|
|
255
|
-
interface
|
|
256
|
+
interface ProcessPool {
|
|
256
257
|
runTests: RunWithFiles;
|
|
257
258
|
close: () => Promise<void>;
|
|
258
259
|
}
|
|
@@ -375,7 +376,7 @@ declare class Vitest {
|
|
|
375
376
|
reporters: Reporter[];
|
|
376
377
|
coverageProvider: CoverageProvider | null | undefined;
|
|
377
378
|
logger: Logger;
|
|
378
|
-
pool:
|
|
379
|
+
pool: ProcessPool | undefined;
|
|
379
380
|
typechecker: Typechecker | undefined;
|
|
380
381
|
vitenode: ViteNodeServer;
|
|
381
382
|
invalidates: Set<string>;
|
|
@@ -417,7 +418,10 @@ declare class Vitest {
|
|
|
417
418
|
*/
|
|
418
419
|
exit(force?: boolean): Promise<void>;
|
|
419
420
|
report<T extends keyof Reporter>(name: T, ...args: ArgumentsType$1<Reporter[T]>): Promise<void>;
|
|
420
|
-
globFiles(
|
|
421
|
+
globFiles(include: string[], exclude: string[], cwd: string): Promise<string[]>;
|
|
422
|
+
private _allTestsCache;
|
|
423
|
+
globAllTestFiles(config: ResolvedConfig, cwd: string): Promise<string[]>;
|
|
424
|
+
filterFiles(testFiles: string[], filters?: string[]): string[];
|
|
421
425
|
globTestFiles(filters?: string[]): Promise<string[]>;
|
|
422
426
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
423
427
|
isInSourceTestFile(code: string): boolean;
|
|
@@ -890,6 +894,87 @@ interface AcornNode {
|
|
|
890
894
|
type: string;
|
|
891
895
|
}
|
|
892
896
|
|
|
897
|
+
// Type definitions for istanbul-lib-report 3.0
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
interface Node {
|
|
901
|
+
isRoot(): boolean;
|
|
902
|
+
visit(visitor: Visitor, state: any): void;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
interface Visitor<N extends Node = Node> {
|
|
906
|
+
onStart(root: N, state: any): void;
|
|
907
|
+
onSummary(root: N, state: any): void;
|
|
908
|
+
onDetail(root: N, state: any): void;
|
|
909
|
+
onSummaryEnd(root: N, state: any): void;
|
|
910
|
+
onEnd(root: N, state: any): void;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// Type definitions for istanbul-reports 3.0
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
interface FileOptions {
|
|
917
|
+
file: string;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
interface ProjectOptions {
|
|
921
|
+
projectRoot: string;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
interface ReportOptions {
|
|
925
|
+
clover: CloverOptions;
|
|
926
|
+
cobertura: CoberturaOptions;
|
|
927
|
+
'html-spa': HtmlSpaOptions;
|
|
928
|
+
html: HtmlOptions;
|
|
929
|
+
json: JsonOptions;
|
|
930
|
+
'json-summary': JsonSummaryOptions;
|
|
931
|
+
lcov: LcovOptions;
|
|
932
|
+
lcovonly: LcovOnlyOptions;
|
|
933
|
+
none: never;
|
|
934
|
+
teamcity: TeamcityOptions;
|
|
935
|
+
text: TextOptions;
|
|
936
|
+
'text-lcov': TextLcovOptions;
|
|
937
|
+
'text-summary': TextSummaryOptions;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
interface CloverOptions extends FileOptions, ProjectOptions {}
|
|
941
|
+
|
|
942
|
+
interface CoberturaOptions extends FileOptions, ProjectOptions {}
|
|
943
|
+
|
|
944
|
+
interface HtmlSpaOptions extends HtmlOptions {
|
|
945
|
+
metricsToShow: Array<'lines' | 'branches' | 'functions' | 'statements'>;
|
|
946
|
+
}
|
|
947
|
+
interface HtmlOptions {
|
|
948
|
+
verbose: boolean;
|
|
949
|
+
skipEmpty: boolean;
|
|
950
|
+
subdir: string;
|
|
951
|
+
linkMapper: LinkMapper;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
type JsonOptions = FileOptions;
|
|
955
|
+
type JsonSummaryOptions = FileOptions;
|
|
956
|
+
|
|
957
|
+
interface LcovOptions extends FileOptions, ProjectOptions {}
|
|
958
|
+
interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
|
|
959
|
+
|
|
960
|
+
interface TeamcityOptions extends FileOptions {
|
|
961
|
+
blockName: string;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
interface TextOptions extends FileOptions {
|
|
965
|
+
maxCols: number;
|
|
966
|
+
skipEmpty: boolean;
|
|
967
|
+
skipFull: boolean;
|
|
968
|
+
}
|
|
969
|
+
type TextLcovOptions = ProjectOptions;
|
|
970
|
+
type TextSummaryOptions = FileOptions;
|
|
971
|
+
|
|
972
|
+
interface LinkMapper {
|
|
973
|
+
getPath(node: string | Node): string;
|
|
974
|
+
relativePath(source: string | Node, target: string | Node): string;
|
|
975
|
+
assetPath(node: Node, name: string): string;
|
|
976
|
+
}
|
|
977
|
+
|
|
893
978
|
declare type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
|
|
894
979
|
declare type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
|
|
895
980
|
declare type PromisifyFn<T> = ReturnType$1<T> extends Promise<any> ? T : (...args: ArgumentsType<T>) => Promise<Awaited<ReturnType$1<T>>>;
|
|
@@ -950,36 +1035,44 @@ interface SnapshotSummary {
|
|
|
950
1035
|
updated: number;
|
|
951
1036
|
}
|
|
952
1037
|
|
|
953
|
-
interface
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
files:
|
|
958
|
-
invalidates?: string[];
|
|
959
|
-
}
|
|
960
|
-
type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
|
|
961
|
-
interface AfterSuiteRunMeta {
|
|
962
|
-
coverage?: unknown;
|
|
963
|
-
}
|
|
964
|
-
interface WorkerRPC {
|
|
965
|
-
fetch: FetchFunction;
|
|
966
|
-
resolveId: ResolveIdFunction;
|
|
967
|
-
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
|
|
968
|
-
onFinished: (files: File$1[], errors?: unknown[]) => void;
|
|
1038
|
+
interface RuntimeRPC {
|
|
1039
|
+
fetch: (id: string, environment: VitestEnvironment) => Promise<FetchResult>;
|
|
1040
|
+
resolveId: (id: string, importer: string | undefined, environment: VitestEnvironment) => Promise<ViteNodeResolveId | null>;
|
|
1041
|
+
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap$1 | undefined>;
|
|
1042
|
+
onFinished: (files: File[], errors?: unknown[]) => void;
|
|
969
1043
|
onWorkerExit: (error: unknown, code?: number) => void;
|
|
970
1044
|
onPathsCollected: (paths: string[]) => void;
|
|
971
1045
|
onUserConsoleLog: (log: UserConsoleLog) => void;
|
|
972
1046
|
onUnhandledError: (err: unknown, type: string) => void;
|
|
973
|
-
onCollected: (files: File
|
|
1047
|
+
onCollected: (files: File[]) => void;
|
|
974
1048
|
onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
|
|
975
|
-
onTaskUpdate: (pack: TaskResultPack
|
|
1049
|
+
onTaskUpdate: (pack: TaskResultPack[]) => void;
|
|
976
1050
|
snapshotSaved: (snapshot: SnapshotResult) => void;
|
|
977
1051
|
resolveSnapshotPath: (testPath: string) => string;
|
|
978
1052
|
}
|
|
1053
|
+
interface ContextTestEnvironment {
|
|
1054
|
+
name: VitestEnvironment;
|
|
1055
|
+
options: EnvironmentOptions | null;
|
|
1056
|
+
}
|
|
1057
|
+
interface ContextRPC {
|
|
1058
|
+
config: ResolvedConfig;
|
|
1059
|
+
files: string[];
|
|
1060
|
+
invalidates?: string[];
|
|
1061
|
+
environment: ContextTestEnvironment;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
interface WorkerContext extends ContextRPC {
|
|
1065
|
+
workerId: number;
|
|
1066
|
+
port: MessagePort;
|
|
1067
|
+
}
|
|
1068
|
+
type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
|
|
1069
|
+
interface AfterSuiteRunMeta {
|
|
1070
|
+
coverage?: unknown;
|
|
1071
|
+
}
|
|
979
1072
|
interface WorkerGlobalState {
|
|
980
1073
|
ctx: WorkerContext;
|
|
981
1074
|
config: ResolvedConfig;
|
|
982
|
-
rpc: BirpcReturn<
|
|
1075
|
+
rpc: BirpcReturn<RuntimeRPC>;
|
|
983
1076
|
current?: Test$2;
|
|
984
1077
|
filepath?: string;
|
|
985
1078
|
moduleCache: ModuleCacheMap;
|
|
@@ -991,7 +1084,6 @@ interface CoverageProvider {
|
|
|
991
1084
|
initialize(ctx: Vitest): Promise<void> | void;
|
|
992
1085
|
resolveOptions(): ResolvedCoverageOptions;
|
|
993
1086
|
clean(clean?: boolean): void | Promise<void>;
|
|
994
|
-
onBeforeFilesRun?(): void | Promise<void>;
|
|
995
1087
|
onAfterSuiteRun(meta: AfterSuiteRunMeta): void | Promise<void>;
|
|
996
1088
|
reportCoverage(reportContext?: ReportContext): void | Promise<void>;
|
|
997
1089
|
onFileTransform?(sourceCode: string, id: string, pluginCtx: TransformPluginContext): TransformResult | Promise<TransformResult>;
|
|
@@ -1005,28 +1097,39 @@ interface CoverageProviderModule {
|
|
|
1005
1097
|
* Factory for creating a new coverage provider
|
|
1006
1098
|
*/
|
|
1007
1099
|
getProvider(): CoverageProvider | Promise<CoverageProvider>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Executed before tests are run in the worker thread.
|
|
1102
|
+
*/
|
|
1103
|
+
startCoverage?(): unknown | Promise<unknown>;
|
|
1008
1104
|
/**
|
|
1009
1105
|
* Executed on after each run in the worker thread. Possible to return a payload passed to the provider
|
|
1010
1106
|
*/
|
|
1011
1107
|
takeCoverage?(): unknown | Promise<unknown>;
|
|
1108
|
+
/**
|
|
1109
|
+
* Executed after all tests have been run in the worker thread.
|
|
1110
|
+
*/
|
|
1111
|
+
stopCoverage?(): unknown | Promise<unknown>;
|
|
1012
1112
|
}
|
|
1013
|
-
type CoverageReporter =
|
|
1014
|
-
type
|
|
1015
|
-
type
|
|
1113
|
+
type CoverageReporter = keyof ReportOptions;
|
|
1114
|
+
type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends CoverageReporter ? ReportOptions[ReporterName] extends never ? [ReporterName, {}] : [ReporterName, Partial<ReportOptions[ReporterName]>] : never;
|
|
1115
|
+
type Provider = 'c8' | 'istanbul' | 'custom' | undefined;
|
|
1116
|
+
type CoverageOptions<T extends Provider = Provider> = T extends 'istanbul' ? ({
|
|
1016
1117
|
provider: T;
|
|
1017
|
-
} &
|
|
1118
|
+
} & CoverageIstanbulOptions) : T extends 'c8' ? ({
|
|
1018
1119
|
provider: T;
|
|
1019
|
-
} &
|
|
1120
|
+
} & CoverageC8Options) : T extends 'custom' ? ({
|
|
1121
|
+
provider: T;
|
|
1122
|
+
} & CustomProviderOptions) : ({
|
|
1020
1123
|
provider?: T;
|
|
1021
|
-
} & CoverageC8Options);
|
|
1124
|
+
} & (CoverageC8Options));
|
|
1022
1125
|
/** Fields that have default values. Internally these will always be defined. */
|
|
1023
|
-
type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension'
|
|
1126
|
+
type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension';
|
|
1024
1127
|
type ResolvedCoverageOptions<T extends Provider = Provider> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
|
|
1025
|
-
reporter:
|
|
1128
|
+
reporter: CoverageReporterWithOptions[];
|
|
1026
1129
|
};
|
|
1027
1130
|
interface BaseCoverageOptions {
|
|
1028
1131
|
/**
|
|
1029
|
-
* Enables coverage collection. Can be
|
|
1132
|
+
* Enables coverage collection. Can be overridden using `--coverage` CLI option.
|
|
1030
1133
|
*
|
|
1031
1134
|
* @default false
|
|
1032
1135
|
*/
|
|
@@ -1075,7 +1178,7 @@ interface BaseCoverageOptions {
|
|
|
1075
1178
|
*
|
|
1076
1179
|
* @default ['text', 'html', 'clover', 'json']
|
|
1077
1180
|
*/
|
|
1078
|
-
reporter?: Arrayable<CoverageReporter
|
|
1181
|
+
reporter?: Arrayable<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
|
|
1079
1182
|
/**
|
|
1080
1183
|
* Do not show files with 100% statement, branch, and function coverage
|
|
1081
1184
|
*
|
|
@@ -1113,6 +1216,12 @@ interface BaseCoverageOptions {
|
|
|
1113
1216
|
* @default undefined
|
|
1114
1217
|
*/
|
|
1115
1218
|
statements?: number;
|
|
1219
|
+
/**
|
|
1220
|
+
* Update threshold values automatically when current coverage is higher than earlier thresholds
|
|
1221
|
+
*
|
|
1222
|
+
* @default false
|
|
1223
|
+
*/
|
|
1224
|
+
thresholdAutoUpdate?: boolean;
|
|
1116
1225
|
}
|
|
1117
1226
|
interface CoverageIstanbulOptions extends BaseCoverageOptions {
|
|
1118
1227
|
/**
|
|
@@ -1159,6 +1268,10 @@ interface CoverageC8Options extends BaseCoverageOptions {
|
|
|
1159
1268
|
*/
|
|
1160
1269
|
100?: boolean;
|
|
1161
1270
|
}
|
|
1271
|
+
interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
|
|
1272
|
+
/** Name of the module or path to a file to load the custom provider from */
|
|
1273
|
+
customProviderModule: string;
|
|
1274
|
+
}
|
|
1162
1275
|
|
|
1163
1276
|
interface JSDOMOptions {
|
|
1164
1277
|
/**
|
|
@@ -1336,6 +1449,12 @@ interface InlineConfig {
|
|
|
1336
1449
|
* Handling for dependencies inlining or externalizing
|
|
1337
1450
|
*/
|
|
1338
1451
|
deps?: {
|
|
1452
|
+
/**
|
|
1453
|
+
* Enable dependency optimization. This can improve the performance of your tests.
|
|
1454
|
+
*/
|
|
1455
|
+
experimentalOptimizer?: Omit<DepOptimizationConfig, 'disabled'> & {
|
|
1456
|
+
enabled: boolean;
|
|
1457
|
+
};
|
|
1339
1458
|
/**
|
|
1340
1459
|
* Externalize means that Vite will bypass the package to native Node.
|
|
1341
1460
|
*
|
|
@@ -1541,6 +1660,12 @@ interface InlineConfig {
|
|
|
1541
1660
|
* @default true
|
|
1542
1661
|
*/
|
|
1543
1662
|
isolate?: boolean;
|
|
1663
|
+
/**
|
|
1664
|
+
* Run tests inside a single thread.
|
|
1665
|
+
*
|
|
1666
|
+
* @default false
|
|
1667
|
+
*/
|
|
1668
|
+
singleThread?: boolean;
|
|
1544
1669
|
/**
|
|
1545
1670
|
* Coverage options
|
|
1546
1671
|
*/
|
|
@@ -1828,7 +1953,7 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
|
|
|
1828
1953
|
sequencer: TestSequencerConstructor;
|
|
1829
1954
|
hooks: SequenceHooks;
|
|
1830
1955
|
shuffle?: boolean;
|
|
1831
|
-
seed
|
|
1956
|
+
seed: number;
|
|
1832
1957
|
};
|
|
1833
1958
|
typecheck: TypecheckConfig;
|
|
1834
1959
|
runner?: string;
|
|
@@ -1979,7 +2104,7 @@ declare global {
|
|
|
1979
2104
|
toBeInstanceOf<E>(expected: E): void;
|
|
1980
2105
|
toBeCalledTimes(times: number): void;
|
|
1981
2106
|
toHaveLength(length: number): void;
|
|
1982
|
-
toHaveProperty<E>(property: string | string[], value?: E): void;
|
|
2107
|
+
toHaveProperty<E>(property: string | (string | number)[], value?: E): void;
|
|
1983
2108
|
toBeCloseTo(number: number, numDigits?: number): void;
|
|
1984
2109
|
toHaveBeenCalledTimes(times: number): void;
|
|
1985
2110
|
toHaveBeenCalledOnce(): void;
|
|
@@ -2041,4 +2166,4 @@ type Context = RootAndTarget & {
|
|
|
2041
2166
|
lastActivePath?: string;
|
|
2042
2167
|
};
|
|
2043
2168
|
|
|
2044
|
-
export {
|
|
2169
|
+
export { ReportContext as $, ApiConfig as A, BenchmarkAPI as B, CollectLineNumbers as C, Arrayable as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, ArgumentsType$1 as G, MergeInsertions as H, InlineConfig as I, JSDOMOptions as J, DeepMerge as K, MutableArray as L, MockFactoryWithHelper as M, Nullable as N, Constructable as O, ModuleCache as P, EnvironmentReturn as Q, RuntimeConfig as R, SnapshotResult as S, TscErrorInfo as T, UserConfig as U, VitestEnvironment as V, WorkerContext as W, Environment as X, UserConsoleLog as Y, OnServerRestartHandler as Z, CoverageProvider as _, ResolvedConfig as a, CoverageProviderModule as a0, CoverageReporter as a1, CoverageOptions as a2, ResolvedCoverageOptions as a3, BaseCoverageOptions as a4, CoverageIstanbulOptions as a5, CoverageC8Options as a6, CustomProviderOptions as a7, BenchmarkUserOptions as a8, Benchmark as a9, BenchmarkResult as aa, BenchFunction as ab, MockFactory as ac, MockMap as ad, TestSequencer as ae, startVitest as af, TestSequencerConstructor as ag, HtmlOptions as ah, FileOptions as ai, CloverOptions as aj, CoberturaOptions as ak, HtmlSpaOptions as al, LcovOptions as am, LcovOnlyOptions as an, TeamcityOptions as ao, TextOptions as ap, ProjectOptions as aq, ModuleGraphData as b, Reporter as c, RawErrsMap as d, CollectLines as e, RootAndTarget as f, Context as g, BuiltinEnvironment as h, CSSModuleScopeStrategy as i, SequenceHooks as j, VitestRunMode as k, TypecheckConfig as l, RuntimeRPC as m, ContextTestEnvironment as n, ContextRPC as o, Vitest as p, SnapshotData as q, SnapshotUpdateState as r, SnapshotStateOptions as s, SnapshotMatchOptions as t, UncheckedSnapshot as u, SnapshotSummary as v, ResolveIdFunction as w, AfterSuiteRunMeta as x, WorkerGlobalState as y, Awaitable as z };
|