vitest 0.18.0 → 0.19.1
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 +6 -6
- package/dist/browser.d.ts +1850 -0
- package/dist/browser.mjs +20 -0
- package/dist/{chunk-api-setup.63babd7c.mjs → chunk-api-setup.0cf2c96a.mjs} +37 -11
- package/dist/{chunk-constants.8eb2ed35.mjs → chunk-constants.38b43a44.mjs} +3 -3
- package/dist/{chunk-env-node.26c72624.mjs → chunk-defaults.ed196a9a.mjs} +458 -455
- package/dist/{chunk-install-pkg.2dcb2c04.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
- package/dist/chunk-integrations-globals.1018e651.mjs +24 -0
- package/dist/chunk-node-git.9058b82a.mjs +1139 -0
- package/dist/chunk-runtime-chain.f2e00f4c.mjs +2039 -0
- package/dist/{vendor-entry.78de67ab.mjs → chunk-runtime-error.606e0393.mjs} +167 -183
- package/dist/{chunk-runtime-chain.eb764dff.mjs → chunk-runtime-hooks.d4cadf47.mjs} +33 -2012
- package/dist/{chunk-runtime-mocker.79ccc3de.mjs → chunk-runtime-mocker.dfdfd57b.mjs} +70 -22
- package/dist/{chunk-runtime-rpc.cc6a06a2.mjs → chunk-runtime-rpc.45d8ee19.mjs} +1 -1
- package/dist/{chunk-utils-global.1b22c4fd.mjs → chunk-utils-global.2aa95025.mjs} +11 -6
- package/dist/{chunk-utils-source-map.957e7756.mjs → chunk-utils-source-map.8b066ce2.mjs} +2 -2
- package/dist/{chunk-vite-node-externalize.0791f2ed.mjs → chunk-vite-node-externalize.e9af6472.mjs} +105 -1174
- package/dist/chunk-vite-node-utils.ad73f2ab.mjs +1433 -0
- package/dist/cli.mjs +9 -11
- package/dist/config.cjs +4 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.mjs +4 -1
- package/dist/entry.mjs +54 -10
- package/dist/index.d.ts +56 -27
- package/dist/index.mjs +12 -9
- package/dist/node.d.ts +37 -18
- package/dist/node.mjs +10 -12
- package/dist/spy.mjs +102 -2
- package/dist/suite.mjs +13 -0
- package/dist/vendor-index.61438b77.mjs +335 -0
- package/dist/{vendor-index.4bf9c627.mjs → vendor-index.62ce5c33.mjs} +11 -343
- package/dist/worker.mjs +6 -6
- package/package.json +20 -12
- package/dist/chunk-integrations-globals.61e4d6ae.mjs +0 -26
- package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
- package/dist/chunk-vite-node-utils.af8ead96.mjs +0 -9195
|
@@ -1,35 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { s as stringify } from './chunk-utils-source-map.
|
|
1
|
+
import { e as environments, t as takeCoverage, p as pLimit } from './chunk-defaults.ed196a9a.mjs';
|
|
2
|
+
import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.d4cadf47.mjs';
|
|
3
|
+
import { o as deepClone, q as getType, t as isNode, g as getWorkerState, R as RealDate, k as safeClearTimeout, s as safeSetTimeout, u as toArray, v as relativePath, x as isBrowser, y as partitionSuiteChildren, z as shuffle, A as hasTests, B as hasFailed, h as getFullName } from './chunk-utils-global.2aa95025.mjs';
|
|
4
|
+
import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.f2e00f4c.mjs';
|
|
5
|
+
import { r as rpc } from './chunk-runtime-rpc.45d8ee19.mjs';
|
|
6
|
+
import util$1 from 'util';
|
|
7
|
+
import { util } from 'chai';
|
|
8
|
+
import { s as stringify } from './chunk-utils-source-map.8b066ce2.mjs';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
const OBJECT_PROTO = Object.getPrototypeOf({});
|
|
11
|
+
function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
12
|
+
if (!val || typeof val === "string")
|
|
13
|
+
return val;
|
|
14
|
+
if (typeof val === "function")
|
|
15
|
+
return `Function<${val.name}>`;
|
|
16
|
+
if (typeof val !== "object")
|
|
17
|
+
return val;
|
|
18
|
+
if (val instanceof Promise || "then" in val || val.constructor && val.constructor.prototype === "AsyncFunction")
|
|
19
|
+
return "Promise";
|
|
20
|
+
if (typeof Element !== "undefined" && val instanceof Element)
|
|
21
|
+
return val.tagName;
|
|
22
|
+
if (typeof val.asymmetricMatch === "function")
|
|
23
|
+
return `${val.toString()} ${util$1.format(val.sample)}`;
|
|
24
|
+
if (seen.has(val))
|
|
25
|
+
return seen.get(val);
|
|
26
|
+
if (Array.isArray(val)) {
|
|
27
|
+
const clone = new Array(val.length);
|
|
28
|
+
seen.set(val, clone);
|
|
29
|
+
val.forEach((e, i) => {
|
|
30
|
+
clone[i] = serializeError(e, seen);
|
|
31
|
+
});
|
|
32
|
+
return clone;
|
|
33
|
+
} else {
|
|
34
|
+
const clone = /* @__PURE__ */ Object.create(null);
|
|
35
|
+
seen.set(val, clone);
|
|
36
|
+
let obj = val;
|
|
37
|
+
while (obj && obj !== OBJECT_PROTO) {
|
|
38
|
+
Object.getOwnPropertyNames(obj).forEach((key) => {
|
|
39
|
+
if (!(key in clone))
|
|
40
|
+
clone[key] = serializeError(obj[key], seen);
|
|
41
|
+
});
|
|
42
|
+
obj = Object.getPrototypeOf(obj);
|
|
43
|
+
}
|
|
44
|
+
return clone;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function normalizeErrorMessage(message) {
|
|
48
|
+
return message.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
49
|
+
}
|
|
50
|
+
function processError(err) {
|
|
51
|
+
if (!err)
|
|
52
|
+
return err;
|
|
53
|
+
if (err.stack)
|
|
54
|
+
err.stackStr = String(err.stack);
|
|
55
|
+
if (err.name)
|
|
56
|
+
err.nameStr = String(err.name);
|
|
57
|
+
const clonedActual = deepClone(err.actual);
|
|
58
|
+
const clonedExpected = deepClone(err.expected);
|
|
59
|
+
const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(clonedActual, clonedExpected);
|
|
60
|
+
err.actual = replacedActual;
|
|
61
|
+
err.expected = replacedExpected;
|
|
62
|
+
if (typeof err.expected !== "string")
|
|
63
|
+
err.expected = stringify(err.expected);
|
|
64
|
+
if (typeof err.actual !== "string")
|
|
65
|
+
err.actual = stringify(err.actual);
|
|
66
|
+
try {
|
|
67
|
+
if (typeof err.message === "string")
|
|
68
|
+
err.message = normalizeErrorMessage(err.message);
|
|
69
|
+
if (typeof err.cause === "object" && typeof err.cause.message === "string")
|
|
70
|
+
err.cause.message = normalizeErrorMessage(err.cause.message);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return serializeError(err);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return serializeError(new Error(`Failed to fully serialize error: ${e == null ? void 0 : e.message}
|
|
77
|
+
Inner error message: ${err == null ? void 0 : err.message}`));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function isAsymmetricMatcher(data) {
|
|
81
|
+
const type = getType(data);
|
|
82
|
+
return type === "Object" && typeof data.asymmetricMatch === "function";
|
|
83
|
+
}
|
|
84
|
+
function isReplaceable(obj1, obj2) {
|
|
85
|
+
const obj1Type = getType(obj1);
|
|
86
|
+
const obj2Type = getType(obj2);
|
|
87
|
+
return obj1Type === obj2Type && obj1Type === "Object";
|
|
88
|
+
}
|
|
89
|
+
function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakMap(), expectedReplaced = /* @__PURE__ */ new WeakMap()) {
|
|
90
|
+
if (!isReplaceable(actual, expected))
|
|
91
|
+
return { replacedActual: actual, replacedExpected: expected };
|
|
92
|
+
if (actualReplaced.has(actual) || expectedReplaced.has(expected))
|
|
93
|
+
return { replacedActual: actual, replacedExpected: expected };
|
|
94
|
+
actualReplaced.set(actual, true);
|
|
95
|
+
expectedReplaced.set(expected, true);
|
|
96
|
+
util.getOwnEnumerableProperties(expected).forEach((key) => {
|
|
97
|
+
const expectedValue = expected[key];
|
|
98
|
+
const actualValue = actual[key];
|
|
99
|
+
if (isAsymmetricMatcher(expectedValue)) {
|
|
100
|
+
if (expectedValue.asymmetricMatch(actualValue))
|
|
101
|
+
actual[key] = expectedValue;
|
|
102
|
+
} else if (isAsymmetricMatcher(actualValue)) {
|
|
103
|
+
if (actualValue.asymmetricMatch(expectedValue))
|
|
104
|
+
expected[key] = actualValue;
|
|
105
|
+
} else if (isReplaceable(actualValue, expectedValue)) {
|
|
106
|
+
const replaced = replaceAsymmetricMatcher(actualValue, expectedValue, actualReplaced, expectedReplaced);
|
|
107
|
+
actual[key] = replaced.replacedActual;
|
|
108
|
+
expected[key] = replaced.replacedExpected;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
replacedActual: actual,
|
|
113
|
+
replacedExpected: expected
|
|
114
|
+
};
|
|
115
|
+
}
|
|
33
116
|
|
|
34
117
|
let globalSetup = false;
|
|
35
118
|
async function setupGlobalEnv(config) {
|
|
@@ -45,7 +128,7 @@ async function setupGlobalEnv(config) {
|
|
|
45
128
|
if (isNode)
|
|
46
129
|
await setupConsoleLogSpy();
|
|
47
130
|
if (config.globals)
|
|
48
|
-
(await import('./chunk-integrations-globals.
|
|
131
|
+
(await import('./chunk-integrations-globals.1018e651.mjs')).registerApiGlobally();
|
|
49
132
|
}
|
|
50
133
|
function setupDefines(defines) {
|
|
51
134
|
for (const key in defines)
|
|
@@ -173,113 +256,6 @@ async function runSetupFiles(config) {
|
|
|
173
256
|
}));
|
|
174
257
|
}
|
|
175
258
|
|
|
176
|
-
const OBJECT_PROTO = Object.getPrototypeOf({});
|
|
177
|
-
function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
178
|
-
if (!val || typeof val === "string")
|
|
179
|
-
return val;
|
|
180
|
-
if (typeof val === "function")
|
|
181
|
-
return `Function<${val.name}>`;
|
|
182
|
-
if (typeof val !== "object")
|
|
183
|
-
return val;
|
|
184
|
-
if (val instanceof Promise || "then" in val || val.constructor && val.constructor.prototype === "AsyncFunction")
|
|
185
|
-
return "Promise";
|
|
186
|
-
if (typeof Element !== "undefined" && val instanceof Element)
|
|
187
|
-
return val.tagName;
|
|
188
|
-
if (typeof val.asymmetricMatch === "function")
|
|
189
|
-
return `${val.toString()} ${format(val.sample)}`;
|
|
190
|
-
if (seen.has(val))
|
|
191
|
-
return seen.get(val);
|
|
192
|
-
if (Array.isArray(val)) {
|
|
193
|
-
const clone = new Array(val.length);
|
|
194
|
-
seen.set(val, clone);
|
|
195
|
-
val.forEach((e, i) => {
|
|
196
|
-
clone[i] = serializeError(e, seen);
|
|
197
|
-
});
|
|
198
|
-
return clone;
|
|
199
|
-
} else {
|
|
200
|
-
const clone = /* @__PURE__ */ Object.create(null);
|
|
201
|
-
seen.set(val, clone);
|
|
202
|
-
let obj = val;
|
|
203
|
-
while (obj && obj !== OBJECT_PROTO) {
|
|
204
|
-
Object.getOwnPropertyNames(obj).forEach((key) => {
|
|
205
|
-
if (!(key in clone))
|
|
206
|
-
clone[key] = serializeError(obj[key], seen);
|
|
207
|
-
});
|
|
208
|
-
obj = Object.getPrototypeOf(obj);
|
|
209
|
-
}
|
|
210
|
-
return clone;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function normalizeErrorMessage(message) {
|
|
214
|
-
return message.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
215
|
-
}
|
|
216
|
-
function processError(err) {
|
|
217
|
-
if (!err)
|
|
218
|
-
return err;
|
|
219
|
-
if (err.stack)
|
|
220
|
-
err.stackStr = String(err.stack);
|
|
221
|
-
if (err.name)
|
|
222
|
-
err.nameStr = String(err.name);
|
|
223
|
-
const clonedActual = deepClone(err.actual);
|
|
224
|
-
const clonedExpected = deepClone(err.expected);
|
|
225
|
-
const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(clonedActual, clonedExpected);
|
|
226
|
-
err.actual = replacedActual;
|
|
227
|
-
err.expected = replacedExpected;
|
|
228
|
-
if (typeof err.expected !== "string")
|
|
229
|
-
err.expected = stringify(err.expected);
|
|
230
|
-
if (typeof err.actual !== "string")
|
|
231
|
-
err.actual = stringify(err.actual);
|
|
232
|
-
try {
|
|
233
|
-
if (typeof err.message === "string")
|
|
234
|
-
err.message = normalizeErrorMessage(err.message);
|
|
235
|
-
if (typeof err.cause === "object" && err.cause.message === "string")
|
|
236
|
-
err.cause.message = normalizeErrorMessage(err.cause.message);
|
|
237
|
-
} catch {
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
return serializeError(err);
|
|
241
|
-
} catch (e) {
|
|
242
|
-
return serializeError(new Error(`Failed to fully serialize error: ${e == null ? void 0 : e.message}
|
|
243
|
-
Inner error message: ${err == null ? void 0 : err.message}`));
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
function isAsymmetricMatcher(data) {
|
|
247
|
-
const type = getType(data);
|
|
248
|
-
return type === "Object" && typeof data.asymmetricMatch === "function";
|
|
249
|
-
}
|
|
250
|
-
function isReplaceable(obj1, obj2) {
|
|
251
|
-
const obj1Type = getType(obj1);
|
|
252
|
-
const obj2Type = getType(obj2);
|
|
253
|
-
return obj1Type === obj2Type && obj1Type === "Object";
|
|
254
|
-
}
|
|
255
|
-
function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakMap(), expectedReplaced = /* @__PURE__ */ new WeakMap()) {
|
|
256
|
-
if (!isReplaceable(actual, expected))
|
|
257
|
-
return { replacedActual: actual, replacedExpected: expected };
|
|
258
|
-
if (actualReplaced.has(actual) || expectedReplaced.has(expected))
|
|
259
|
-
return { replacedActual: actual, replacedExpected: expected };
|
|
260
|
-
actualReplaced.set(actual, true);
|
|
261
|
-
expectedReplaced.set(expected, true);
|
|
262
|
-
util.getOwnEnumerableProperties(expected).forEach((key) => {
|
|
263
|
-
const expectedValue = expected[key];
|
|
264
|
-
const actualValue = actual[key];
|
|
265
|
-
if (isAsymmetricMatcher(expectedValue)) {
|
|
266
|
-
if (expectedValue.asymmetricMatch(actualValue))
|
|
267
|
-
actual[key] = expectedValue;
|
|
268
|
-
} else if (isAsymmetricMatcher(actualValue)) {
|
|
269
|
-
if (actualValue.asymmetricMatch(expectedValue))
|
|
270
|
-
expected[key] = actualValue;
|
|
271
|
-
} else if (isReplaceable(actualValue, expectedValue)) {
|
|
272
|
-
const replaced = replaceAsymmetricMatcher(actualValue, expectedValue, actualReplaced, expectedReplaced);
|
|
273
|
-
actual[key] = replaced.replacedActual;
|
|
274
|
-
expected[key] = replaced.replacedExpected;
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
return {
|
|
278
|
-
replacedActual: actual,
|
|
279
|
-
replacedExpected: expected
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
259
|
const now$1 = Date.now;
|
|
284
260
|
function hash(str) {
|
|
285
261
|
let hash2 = 0;
|
|
@@ -294,8 +270,17 @@ function hash(str) {
|
|
|
294
270
|
}
|
|
295
271
|
async function collectTests(paths, config) {
|
|
296
272
|
const files = [];
|
|
273
|
+
const browserHashMap = getWorkerState().browserHashMap;
|
|
274
|
+
async function importFromBrowser(filepath) {
|
|
275
|
+
const match = filepath.match(/^(\w:\/)/);
|
|
276
|
+
const hash2 = browserHashMap.get(filepath);
|
|
277
|
+
if (match)
|
|
278
|
+
return await import(`/@fs/${filepath.slice(match[1].length)}?v=${hash2}`);
|
|
279
|
+
else
|
|
280
|
+
return await import(`${filepath}?v=${hash2}`);
|
|
281
|
+
}
|
|
297
282
|
for (const filepath of paths) {
|
|
298
|
-
const path =
|
|
283
|
+
const path = relativePath(config.root, filepath);
|
|
299
284
|
const file = {
|
|
300
285
|
id: hash(path),
|
|
301
286
|
name: path,
|
|
@@ -307,7 +292,10 @@ async function collectTests(paths, config) {
|
|
|
307
292
|
clearCollectorContext();
|
|
308
293
|
try {
|
|
309
294
|
await runSetupFiles(config);
|
|
310
|
-
|
|
295
|
+
if (config.browser && isBrowser)
|
|
296
|
+
await importFromBrowser(filepath);
|
|
297
|
+
else
|
|
298
|
+
await import(filepath);
|
|
311
299
|
const defaultTasks = await defaultSuite.collect(file);
|
|
312
300
|
setHooks(file, getHooks(defaultTasks));
|
|
313
301
|
for (const c of [...defaultTasks.tasks, ...collectorContext.tasks]) {
|
|
@@ -328,6 +316,8 @@ async function collectTests(paths, config) {
|
|
|
328
316
|
state: "fail",
|
|
329
317
|
error: processError(e)
|
|
330
318
|
};
|
|
319
|
+
if (config.browser)
|
|
320
|
+
console.error(e);
|
|
331
321
|
}
|
|
332
322
|
calculateHash(file);
|
|
333
323
|
const hasOnlyTasks = someTasksAreOnly(file);
|
|
@@ -447,6 +437,7 @@ async function sendTasksUpdate() {
|
|
|
447
437
|
async function runTest(test) {
|
|
448
438
|
var _a, _b;
|
|
449
439
|
if (test.mode !== "run") {
|
|
440
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
|
|
450
441
|
getSnapshotClient().skipTestSnapshots(test);
|
|
451
442
|
return;
|
|
452
443
|
}
|
|
@@ -461,7 +452,10 @@ async function runTest(test) {
|
|
|
461
452
|
};
|
|
462
453
|
updateTask(test);
|
|
463
454
|
clearModuleMocks();
|
|
464
|
-
|
|
455
|
+
if (isNode) {
|
|
456
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
|
|
457
|
+
await getSnapshotClient().setTest(test);
|
|
458
|
+
}
|
|
465
459
|
const workerState = getWorkerState();
|
|
466
460
|
workerState.current = test;
|
|
467
461
|
let beforeEachCleanups = [];
|
|
@@ -509,9 +503,14 @@ async function runTest(test) {
|
|
|
509
503
|
test.result.error = void 0;
|
|
510
504
|
}
|
|
511
505
|
}
|
|
512
|
-
|
|
506
|
+
if (isBrowser && test.result.error)
|
|
507
|
+
console.error(test.result.error.message, test.result.error.stackStr);
|
|
508
|
+
if (isNode) {
|
|
509
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
|
|
510
|
+
getSnapshotClient().clearTest();
|
|
511
|
+
}
|
|
513
512
|
test.result.duration = now() - start;
|
|
514
|
-
if (workerState.config.logHeapUsage)
|
|
513
|
+
if (workerState.config.logHeapUsage && isNode)
|
|
515
514
|
test.result.heap = process.memoryUsage().heapUsed;
|
|
516
515
|
workerState.current = void 0;
|
|
517
516
|
updateTask(test);
|
|
@@ -570,7 +569,7 @@ async function runSuite(suite) {
|
|
|
570
569
|
}
|
|
571
570
|
}
|
|
572
571
|
suite.result.duration = now() - start;
|
|
573
|
-
if (workerState.config.logHeapUsage)
|
|
572
|
+
if (workerState.config.logHeapUsage && isNode)
|
|
574
573
|
suite.result.heap = process.memoryUsage().heapUsed;
|
|
575
574
|
if (suite.mode === "run") {
|
|
576
575
|
if (!hasTests(suite)) {
|
|
@@ -588,6 +587,10 @@ async function runSuite(suite) {
|
|
|
588
587
|
async function runSuiteChild(c) {
|
|
589
588
|
return c.type === "test" ? runTest(c) : runSuite(c);
|
|
590
589
|
}
|
|
590
|
+
async function runSuites(suites) {
|
|
591
|
+
for (const suite of suites)
|
|
592
|
+
await runSuite(suite);
|
|
593
|
+
}
|
|
591
594
|
async function runFiles(files, config) {
|
|
592
595
|
var _a;
|
|
593
596
|
for (const file of files) {
|
|
@@ -602,15 +605,32 @@ async function runFiles(files, config) {
|
|
|
602
605
|
await runSuite(file);
|
|
603
606
|
}
|
|
604
607
|
}
|
|
605
|
-
async function
|
|
608
|
+
async function startTestsBrowser(paths, config) {
|
|
609
|
+
if (isNode) {
|
|
610
|
+
rpc().onPathsCollected(paths);
|
|
611
|
+
} else {
|
|
612
|
+
const files = await collectTests(paths, config);
|
|
613
|
+
await rpc().onCollected(files);
|
|
614
|
+
await runSuites(files);
|
|
615
|
+
await sendTasksUpdate();
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
async function startTestsNode(paths, config) {
|
|
606
619
|
const files = await collectTests(paths, config);
|
|
607
620
|
rpc().onCollected(files);
|
|
621
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
|
|
608
622
|
getSnapshotClient().clear();
|
|
609
623
|
await runFiles(files, config);
|
|
610
624
|
takeCoverage();
|
|
611
625
|
await getSnapshotClient().saveCurrent();
|
|
612
626
|
await sendTasksUpdate();
|
|
613
627
|
}
|
|
628
|
+
async function startTests(paths, config) {
|
|
629
|
+
if (config.browser)
|
|
630
|
+
return startTestsBrowser(paths, config);
|
|
631
|
+
else
|
|
632
|
+
return startTestsNode(paths, config);
|
|
633
|
+
}
|
|
614
634
|
function clearModuleMocks() {
|
|
615
635
|
const { clearMocks, mockReset, restoreMocks } = getWorkerState().config;
|
|
616
636
|
if (restoreMocks)
|
|
@@ -621,40 +641,4 @@ function clearModuleMocks() {
|
|
|
621
641
|
vi.clearAllMocks();
|
|
622
642
|
}
|
|
623
643
|
|
|
624
|
-
|
|
625
|
-
await setupGlobalEnv(config);
|
|
626
|
-
const workerState = getWorkerState();
|
|
627
|
-
const filesWithEnv = await Promise.all(files.map(async (file) => {
|
|
628
|
-
var _a;
|
|
629
|
-
const code = await promises.readFile(file, "utf-8");
|
|
630
|
-
const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
|
|
631
|
-
if (!envs.includes(env))
|
|
632
|
-
throw new Error(`Unsupported environment: "${env}" in ${file}`);
|
|
633
|
-
return {
|
|
634
|
-
file,
|
|
635
|
-
env
|
|
636
|
-
};
|
|
637
|
-
}));
|
|
638
|
-
const filesByEnv = filesWithEnv.reduce((acc, { file, env }) => {
|
|
639
|
-
acc[env] || (acc[env] = []);
|
|
640
|
-
acc[env].push(file);
|
|
641
|
-
return acc;
|
|
642
|
-
}, {});
|
|
643
|
-
for (const env of envs) {
|
|
644
|
-
const environment = env;
|
|
645
|
-
const files2 = filesByEnv[environment];
|
|
646
|
-
if (!files2 || !files2.length)
|
|
647
|
-
continue;
|
|
648
|
-
await withEnv(environment, config.environmentOptions || {}, async () => {
|
|
649
|
-
for (const file of files2) {
|
|
650
|
-
workerState.mockMap.clear();
|
|
651
|
-
resetModules();
|
|
652
|
-
workerState.filepath = file;
|
|
653
|
-
await startTests([file], config);
|
|
654
|
-
workerState.filepath = void 0;
|
|
655
|
-
}
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
export { index as i, run as r };
|
|
644
|
+
export { setupGlobalEnv as a, startTests as s, withEnv as w };
|