vitest 2.0.0-beta.9 → 2.0.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 -22
- package/dist/browser.d.ts +24 -7
- package/dist/browser.js +5 -19
- package/dist/chunks/browser-creator.DSqYDthP.js +673 -0
- package/dist/chunks/{environments-node.39w4gmlF.js → environments-node.XE5FbRPQ.js} +1 -1
- package/dist/chunks/{integrations-globals.BK0Cn4q1.js → integrations-globals.CzYWb38r.js} +10 -9
- package/dist/chunks/{node-git.CCI8evVZ.js → node-git.ZtkbKc8u.js} +14 -15
- package/dist/chunks/{runtime-console.DiVMr5d4.js → runtime-console.O41g23Zj.js} +26 -11
- package/dist/chunks/{runtime-runBaseTests.C-Bkopka.js → runtime-runBaseTests.DX3h28Mp.js} +47 -34
- package/dist/cli.js +3 -3
- package/dist/config.cjs +48 -23
- package/dist/config.d.ts +2 -1
- package/dist/config.js +48 -24
- package/dist/coverage.d.ts +6 -4
- package/dist/coverage.js +102 -38
- package/dist/environments.d.ts +2 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +4 -3
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +1437 -7
- package/dist/index.js +10 -9
- package/dist/node.d.ts +34 -7
- package/dist/node.js +31 -20
- package/dist/path.js +4 -1
- package/dist/{reporters-DaDey3o0.d.ts → reporters-DrhyxxXt.d.ts} +213 -206
- package/dist/reporters.d.ts +2 -1
- package/dist/reporters.js +8 -8
- package/dist/runners.d.ts +3 -1
- package/dist/runners.js +100 -61
- package/dist/snapshot.js +2 -2
- package/dist/{suite-BHSUxUib.d.ts → suite-DCPwkk7G.d.ts} +1 -1
- package/dist/suite.d.ts +3 -2
- package/dist/suite.js +3 -3
- package/dist/utils.d.ts +1 -5
- package/dist/utils.js +1 -6
- package/dist/vendor/{base._gnK9Slw.js → base.CTYV4Gnz.js} +24 -17
- package/dist/vendor/{base.D4XK-wRp.js → base.CdA1i5tB.js} +6 -4
- package/dist/vendor/{benchmark.BNLebNi5.js → benchmark.B6pblCp2.js} +13 -14
- package/dist/vendor/{cac.DCg3FnEs.js → cac.5nBDv26-.js} +142 -47
- package/dist/vendor/{cli-api.LMvYagQ5.js → cli-api.BT4NJtxX.js} +4162 -9514
- package/dist/vendor/{constants.TCjCaw2D.js → constants.CsnA4eRy.js} +5 -23
- package/dist/vendor/{coverage.ChSqD-qS.js → coverage.BhYSDdTT.js} +27 -11
- package/dist/vendor/{date.BKM1wewY.js → date.W2xKR2qe.js} +5 -3
- package/dist/vendor/env.2ltrQNq0.js +8 -0
- package/dist/vendor/{execute.BHj6OMh4.js → execute.Dx503nGn.js} +186 -64
- package/dist/vendor/{index.TBU3GqRP.js → index.3x3MdmUV.js} +1075 -526
- package/dist/vendor/{index._7XLd8Kd.js → index.BJmtb_7W.js} +3 -2
- package/dist/vendor/{index.DP-km6lF.js → index.BMmMjLIQ.js} +64 -51
- package/dist/vendor/{index.DHRpy7zp.js → index.CROIsoiT.js} +18 -10
- package/dist/vendor/{index.DeR1hhfY.js → index.D4nqnQWz.js} +71 -74
- package/dist/vendor/index.D6GZqexG.js +6575 -0
- package/dist/vendor/{index.DwR86H5i.js → index.Hqvcg1pf.js} +4 -27
- package/dist/vendor/{rpc.DRDE9Pu1.js → rpc.BGx7q_k2.js} +30 -19
- package/dist/vendor/run-once.Db8Hgq9X.js +28 -0
- package/dist/vendor/{setup-common.BhJvzjns.js → setup-common.yHaxjRhz.js} +30 -15
- package/dist/vendor/spy.Cf_4R5Oe.js +22 -0
- package/dist/vendor/{tasks.WC7M-K-v.js → tasks.DhVtQBtW.js} +3 -1
- package/dist/vendor/{utils.YuQ3LT2a.js → utils.BVMrsl6E.js} +55 -30
- package/dist/vendor/{utils.CUjzkRH7.js → utils.DkxLWvS1.js} +12 -5
- package/dist/vendor/{vi.C6AfDXK6.js → vi.DXACdGTu.js} +269 -136
- package/dist/vendor/{vm.Ow-X2mkS.js → vm.BrDS6p7h.js} +157 -90
- package/dist/worker.js +41 -18
- package/dist/workers/forks.js +12 -6
- package/dist/workers/runVmTests.js +22 -16
- package/dist/workers/threads.js +8 -5
- package/dist/workers/vmForks.js +15 -9
- package/dist/workers/vmThreads.js +11 -8
- package/dist/workers.d.ts +8 -5
- package/dist/workers.js +11 -11
- package/package.json +22 -21
- package/suppress-warnings.cjs +2 -4
- package/dist/index-B0dCycbN.d.ts +0 -1571
- package/dist/vendor/env.bmJgw1qP.js +0 -7
package/dist/coverage.js
CHANGED
|
@@ -1,30 +1,46 @@
|
|
|
1
1
|
import { relative } from 'pathe';
|
|
2
|
-
import { m as mm } from './vendor/index.
|
|
2
|
+
import { m as mm } from './vendor/index.BMmMjLIQ.js';
|
|
3
3
|
import './vendor/_commonjsHelpers.BFTU3MAI.js';
|
|
4
4
|
import 'util';
|
|
5
5
|
import 'path';
|
|
6
6
|
|
|
7
|
-
const THRESHOLD_KEYS = [
|
|
7
|
+
const THRESHOLD_KEYS = [
|
|
8
|
+
"lines",
|
|
9
|
+
"functions",
|
|
10
|
+
"statements",
|
|
11
|
+
"branches"
|
|
12
|
+
];
|
|
8
13
|
const GLOBAL_THRESHOLDS_KEY = "global";
|
|
9
14
|
class BaseCoverageProvider {
|
|
10
15
|
/**
|
|
11
16
|
* Check if current coverage is above configured thresholds and bump the thresholds if needed
|
|
12
17
|
*/
|
|
13
|
-
updateThresholds({
|
|
18
|
+
updateThresholds({
|
|
19
|
+
thresholds: allThresholds,
|
|
20
|
+
perFile,
|
|
21
|
+
configurationFile,
|
|
22
|
+
onUpdate
|
|
23
|
+
}) {
|
|
14
24
|
let updatedThresholds = false;
|
|
15
25
|
const config = resolveConfig(configurationFile);
|
|
16
26
|
assertConfigurationModule(config);
|
|
17
27
|
for (const { coverageMap, thresholds, name } of allThresholds) {
|
|
18
|
-
const summaries = perFile ? coverageMap.files().map(
|
|
28
|
+
const summaries = perFile ? coverageMap.files().map(
|
|
29
|
+
(file) => coverageMap.fileCoverageFor(file).toSummary()
|
|
30
|
+
) : [coverageMap.getCoverageSummary()];
|
|
19
31
|
const thresholdsToUpdate = [];
|
|
20
32
|
for (const key of THRESHOLD_KEYS) {
|
|
21
33
|
const threshold = thresholds[key] ?? 100;
|
|
22
|
-
const actual = Math.min(
|
|
23
|
-
|
|
34
|
+
const actual = Math.min(
|
|
35
|
+
...summaries.map((summary) => summary[key].pct)
|
|
36
|
+
);
|
|
37
|
+
if (actual > threshold) {
|
|
24
38
|
thresholdsToUpdate.push([key, actual]);
|
|
39
|
+
}
|
|
25
40
|
}
|
|
26
|
-
if (thresholdsToUpdate.length === 0)
|
|
41
|
+
if (thresholdsToUpdate.length === 0) {
|
|
27
42
|
continue;
|
|
43
|
+
}
|
|
28
44
|
updatedThresholds = true;
|
|
29
45
|
for (const [threshold, newValue] of thresholdsToUpdate) {
|
|
30
46
|
if (name === GLOBAL_THRESHOLDS_KEY) {
|
|
@@ -36,35 +52,53 @@ class BaseCoverageProvider {
|
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
54
|
if (updatedThresholds) {
|
|
39
|
-
console.log(
|
|
55
|
+
console.log(
|
|
56
|
+
"Updating thresholds to configuration file. You may want to push with updated coverage thresholds."
|
|
57
|
+
);
|
|
40
58
|
onUpdate();
|
|
41
59
|
}
|
|
42
60
|
}
|
|
43
61
|
/**
|
|
44
62
|
* Check collected coverage against configured thresholds. Sets exit code to 1 when thresholds not reached.
|
|
45
63
|
*/
|
|
46
|
-
checkThresholds({
|
|
64
|
+
checkThresholds({
|
|
65
|
+
thresholds: allThresholds,
|
|
66
|
+
perFile,
|
|
67
|
+
onError
|
|
68
|
+
}) {
|
|
47
69
|
for (const { coverageMap, thresholds, name } of allThresholds) {
|
|
48
|
-
if (thresholds.branches === void 0 && thresholds.functions === void 0 && thresholds.lines === void 0 && thresholds.statements === void 0)
|
|
70
|
+
if (thresholds.branches === void 0 && thresholds.functions === void 0 && thresholds.lines === void 0 && thresholds.statements === void 0) {
|
|
49
71
|
continue;
|
|
72
|
+
}
|
|
50
73
|
const summaries = perFile ? coverageMap.files().map((file) => ({
|
|
51
74
|
file,
|
|
52
75
|
summary: coverageMap.fileCoverageFor(file).toSummary()
|
|
53
|
-
})) : [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
76
|
+
})) : [
|
|
77
|
+
{
|
|
78
|
+
file: null,
|
|
79
|
+
summary: coverageMap.getCoverageSummary()
|
|
80
|
+
}
|
|
81
|
+
];
|
|
57
82
|
for (const { summary, file } of summaries) {
|
|
58
|
-
for (const thresholdKey of [
|
|
83
|
+
for (const thresholdKey of [
|
|
84
|
+
"lines",
|
|
85
|
+
"functions",
|
|
86
|
+
"statements",
|
|
87
|
+
"branches"
|
|
88
|
+
]) {
|
|
59
89
|
const threshold = thresholds[thresholdKey];
|
|
60
90
|
if (threshold !== void 0) {
|
|
61
91
|
const coverage = summary.data[thresholdKey].pct;
|
|
62
92
|
if (coverage < threshold) {
|
|
63
93
|
process.exitCode = 1;
|
|
64
94
|
let errorMessage = `ERROR: Coverage for ${thresholdKey} (${coverage}%) does not meet ${name === GLOBAL_THRESHOLDS_KEY ? name : `"${name}"`} threshold (${threshold}%)`;
|
|
65
|
-
if (perFile && file)
|
|
66
|
-
errorMessage += ` for ${relative("./", file).replace(
|
|
67
|
-
|
|
95
|
+
if (perFile && file) {
|
|
96
|
+
errorMessage += ` for ${relative("./", file).replace(
|
|
97
|
+
/\\/g,
|
|
98
|
+
"/"
|
|
99
|
+
)}`;
|
|
100
|
+
}
|
|
101
|
+
onError(errorMessage);
|
|
68
102
|
}
|
|
69
103
|
}
|
|
70
104
|
}
|
|
@@ -76,18 +110,28 @@ class BaseCoverageProvider {
|
|
|
76
110
|
* where each threshold set holds their own coverage maps. Threshold set is either
|
|
77
111
|
* for specific files defined by glob pattern or global for all other files.
|
|
78
112
|
*/
|
|
79
|
-
resolveThresholds({
|
|
113
|
+
resolveThresholds({
|
|
114
|
+
coverageMap,
|
|
115
|
+
thresholds,
|
|
116
|
+
createCoverageMap,
|
|
117
|
+
root
|
|
118
|
+
}) {
|
|
80
119
|
const resolvedThresholds = [];
|
|
81
120
|
const files = coverageMap.files();
|
|
82
121
|
const filesMatchedByGlobs = [];
|
|
83
122
|
const globalCoverageMap = createCoverageMap();
|
|
84
|
-
for (const key of Object.keys(
|
|
85
|
-
|
|
123
|
+
for (const key of Object.keys(
|
|
124
|
+
thresholds
|
|
125
|
+
)) {
|
|
126
|
+
if (key === "perFile" || key === "autoUpdate" || key === "100" || THRESHOLD_KEYS.includes(key)) {
|
|
86
127
|
continue;
|
|
128
|
+
}
|
|
87
129
|
const glob = key;
|
|
88
130
|
const globThresholds = resolveGlobThresholds(thresholds[glob]);
|
|
89
131
|
const globCoverageMap = createCoverageMap();
|
|
90
|
-
const matchingFiles = files.filter(
|
|
132
|
+
const matchingFiles = files.filter(
|
|
133
|
+
(file) => mm.isMatch(relative(root, file), glob)
|
|
134
|
+
);
|
|
91
135
|
filesMatchedByGlobs.push(...matchingFiles);
|
|
92
136
|
for (const file of matchingFiles) {
|
|
93
137
|
const fileCoverage = coverageMap.fileCoverageFor(file);
|
|
@@ -99,7 +143,9 @@ class BaseCoverageProvider {
|
|
|
99
143
|
thresholds: globThresholds
|
|
100
144
|
});
|
|
101
145
|
}
|
|
102
|
-
for (const file of files.filter(
|
|
146
|
+
for (const file of files.filter(
|
|
147
|
+
(file2) => !filesMatchedByGlobs.includes(file2)
|
|
148
|
+
)) {
|
|
103
149
|
const fileCoverage = coverageMap.fileCoverageFor(file);
|
|
104
150
|
globalCoverageMap.addFileCoverage(fileCoverage);
|
|
105
151
|
}
|
|
@@ -119,8 +165,9 @@ class BaseCoverageProvider {
|
|
|
119
165
|
* Resolve reporters from various configuration options
|
|
120
166
|
*/
|
|
121
167
|
resolveReporters(configReporters) {
|
|
122
|
-
if (!Array.isArray(configReporters))
|
|
168
|
+
if (!Array.isArray(configReporters)) {
|
|
123
169
|
return [[configReporters, {}]];
|
|
170
|
+
}
|
|
124
171
|
const resolvedReporters = [];
|
|
125
172
|
for (const reporter of configReporters) {
|
|
126
173
|
if (Array.isArray(reporter)) {
|
|
@@ -132,24 +179,28 @@ class BaseCoverageProvider {
|
|
|
132
179
|
return resolvedReporters;
|
|
133
180
|
}
|
|
134
181
|
hasTerminalReporter(reporters) {
|
|
135
|
-
return reporters.some(
|
|
182
|
+
return reporters.some(
|
|
183
|
+
([reporter]) => reporter === "text" || reporter === "text-summary" || reporter === "text-lcov" || reporter === "teamcity"
|
|
184
|
+
);
|
|
136
185
|
}
|
|
137
186
|
toSlices(array, size) {
|
|
138
187
|
return array.reduce((chunks, item) => {
|
|
139
188
|
const index = Math.max(0, chunks.length - 1);
|
|
140
189
|
const lastChunk = chunks[index] || [];
|
|
141
190
|
chunks[index] = lastChunk;
|
|
142
|
-
if (lastChunk.length >= size)
|
|
191
|
+
if (lastChunk.length >= size) {
|
|
143
192
|
chunks.push([item]);
|
|
144
|
-
else
|
|
193
|
+
} else {
|
|
145
194
|
lastChunk.push(item);
|
|
195
|
+
}
|
|
146
196
|
return chunks;
|
|
147
197
|
}, []);
|
|
148
198
|
}
|
|
149
199
|
}
|
|
150
200
|
function resolveGlobThresholds(thresholds) {
|
|
151
|
-
if (!thresholds || typeof thresholds !== "object")
|
|
201
|
+
if (!thresholds || typeof thresholds !== "object") {
|
|
152
202
|
return {};
|
|
203
|
+
}
|
|
153
204
|
return {
|
|
154
205
|
lines: "lines" in thresholds && typeof thresholds.lines === "number" ? thresholds.lines : void 0,
|
|
155
206
|
branches: "branches" in thresholds && typeof thresholds.branches === "number" ? thresholds.branches : void 0,
|
|
@@ -159,42 +210,54 @@ function resolveGlobThresholds(thresholds) {
|
|
|
159
210
|
}
|
|
160
211
|
function assertConfigurationModule(config) {
|
|
161
212
|
try {
|
|
162
|
-
if (typeof config.test.coverage.thresholds !== "object")
|
|
163
|
-
throw new
|
|
213
|
+
if (typeof config.test.coverage.thresholds !== "object") {
|
|
214
|
+
throw new TypeError(
|
|
215
|
+
"Expected config.test.coverage.thresholds to be an object"
|
|
216
|
+
);
|
|
217
|
+
}
|
|
164
218
|
} catch (error) {
|
|
165
219
|
const message = error instanceof Error ? error.message : String(error);
|
|
166
|
-
throw new Error(
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Unable to parse thresholds from configuration file: ${message}`
|
|
222
|
+
);
|
|
167
223
|
}
|
|
168
224
|
}
|
|
169
225
|
function resolveConfig(configModule) {
|
|
170
226
|
const mod = configModule.exports.default;
|
|
171
227
|
try {
|
|
172
|
-
if (mod.$type === "object")
|
|
228
|
+
if (mod.$type === "object") {
|
|
173
229
|
return mod;
|
|
230
|
+
}
|
|
174
231
|
let config = resolveDefineConfig(mod);
|
|
175
|
-
if (config)
|
|
232
|
+
if (config) {
|
|
176
233
|
return config;
|
|
234
|
+
}
|
|
177
235
|
if (mod.$type === "function-call" && mod.$callee === "mergeConfig") {
|
|
178
236
|
config = resolveMergeConfig(mod);
|
|
179
|
-
if (config)
|
|
237
|
+
if (config) {
|
|
180
238
|
return config;
|
|
239
|
+
}
|
|
181
240
|
}
|
|
182
241
|
} catch (error) {
|
|
183
242
|
throw new Error(error instanceof Error ? error.message : String(error));
|
|
184
243
|
}
|
|
185
|
-
throw new Error(
|
|
244
|
+
throw new Error(
|
|
245
|
+
"Failed to update coverage thresholds. Configuration file is too complex."
|
|
246
|
+
);
|
|
186
247
|
}
|
|
187
248
|
function resolveDefineConfig(mod) {
|
|
188
249
|
if (mod.$type === "function-call" && mod.$callee === "defineConfig") {
|
|
189
|
-
if (mod.$args[0].$type === "object")
|
|
250
|
+
if (mod.$args[0].$type === "object") {
|
|
190
251
|
return mod.$args[0];
|
|
252
|
+
}
|
|
191
253
|
if (mod.$args[0].$type === "arrow-function-expression") {
|
|
192
254
|
if (mod.$args[0].$body.$type === "object") {
|
|
193
255
|
return mod.$args[0].$body;
|
|
194
256
|
}
|
|
195
257
|
const config = resolveMergeConfig(mod.$args[0].$body);
|
|
196
|
-
if (config)
|
|
258
|
+
if (config) {
|
|
197
259
|
return config;
|
|
260
|
+
}
|
|
198
261
|
}
|
|
199
262
|
}
|
|
200
263
|
}
|
|
@@ -202,8 +265,9 @@ function resolveMergeConfig(mod) {
|
|
|
202
265
|
if (mod.$type === "function-call" && mod.$callee === "mergeConfig") {
|
|
203
266
|
for (const arg of mod.$args) {
|
|
204
267
|
const config = resolveDefineConfig(arg);
|
|
205
|
-
if (config)
|
|
268
|
+
if (config) {
|
|
206
269
|
return config;
|
|
270
|
+
}
|
|
207
271
|
}
|
|
208
272
|
}
|
|
209
273
|
}
|
package/dist/environments.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as Environment } from './reporters-
|
|
1
|
+
import { E as Environment } from './reporters-DrhyxxXt.js';
|
|
2
2
|
import 'vite';
|
|
3
3
|
import '@vitest/runner';
|
|
4
4
|
import 'vite-node';
|
|
@@ -12,6 +12,7 @@ import 'vite-node/client';
|
|
|
12
12
|
import '@vitest/snapshot/manager';
|
|
13
13
|
import 'vite-node/server';
|
|
14
14
|
import 'node:worker_threads';
|
|
15
|
+
import '@vitest/utils/source-map';
|
|
15
16
|
import 'node:fs';
|
|
16
17
|
import 'chai';
|
|
17
18
|
|
package/dist/environments.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { e as builtinEnvironments, p as populateGlobal } from './vendor/index.
|
|
1
|
+
export { e as builtinEnvironments, p as populateGlobal } from './vendor/index.D4nqnQWz.js';
|
|
2
2
|
import 'node:console';
|
package/dist/execute.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import vm from 'node:vm';
|
|
2
2
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
3
3
|
import { ViteNodeRunnerOptions } from 'vite-node';
|
|
4
|
-
import {
|
|
4
|
+
import { aI as PendingSuiteMock, aJ as MockFactory, e as RuntimeRPC, W as WorkerGlobalState, aK as MockMap } from './reporters-DrhyxxXt.js';
|
|
5
5
|
import 'vite';
|
|
6
6
|
import '@vitest/runner';
|
|
7
7
|
import '@vitest/snapshot';
|
|
@@ -13,6 +13,7 @@ import 'node:stream';
|
|
|
13
13
|
import '@vitest/snapshot/manager';
|
|
14
14
|
import 'vite-node/server';
|
|
15
15
|
import 'node:worker_threads';
|
|
16
|
+
import '@vitest/utils/source-map';
|
|
16
17
|
import 'node:fs';
|
|
17
18
|
import 'chai';
|
|
18
19
|
|
|
@@ -135,9 +136,9 @@ declare class VitestExecutor extends ViteNodeRunner {
|
|
|
135
136
|
private primitives;
|
|
136
137
|
constructor(options: ExecuteOptions);
|
|
137
138
|
protected getContextPrimitives(): {
|
|
138
|
-
Object:
|
|
139
|
+
Object: typeof Object;
|
|
139
140
|
Reflect: typeof Reflect;
|
|
140
|
-
Symbol:
|
|
141
|
+
Symbol: typeof Symbol;
|
|
141
142
|
};
|
|
142
143
|
get state(): WorkerGlobalState;
|
|
143
144
|
shouldResolveId(id: string, _importee?: string | undefined): boolean;
|
package/dist/execute.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { V as VitestExecutor } from './vendor/execute.
|
|
1
|
+
export { V as VitestExecutor } from './vendor/execute.Dx503nGn.js';
|
|
2
2
|
import 'node:vm';
|
|
3
3
|
import 'node:url';
|
|
4
4
|
import 'node:fs';
|
|
@@ -8,4 +8,4 @@ import 'pathe';
|
|
|
8
8
|
import '@vitest/utils/error';
|
|
9
9
|
import './path.js';
|
|
10
10
|
import '@vitest/utils';
|
|
11
|
-
import './vendor/base.
|
|
11
|
+
import './vendor/base.CTYV4Gnz.js';
|