vitest 3.0.9 → 3.1.0-beta.2
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.js +4 -4
- package/dist/chunks/base.CylSMlTD.js +41 -0
- package/dist/chunks/benchmark.BKUatJGy.js +39 -0
- package/dist/chunks/cac.JtTXbKz0.js +1525 -0
- package/dist/chunks/{cli-api.Ckwz_xSb.js → cli-api.BTtPTYMs.js} +4638 -5072
- package/dist/chunks/console.D6t261w0.js +173 -0
- package/dist/chunks/constants.BZZyIeIE.js +43 -0
- package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
- package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
- package/dist/chunks/creator.BEXek7yQ.js +640 -0
- package/dist/chunks/date.CDOsz-HY.js +53 -0
- package/dist/chunks/defaults.DmfNPoe5.js +114 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
- package/dist/chunks/execute.DZKwfrTs.js +791 -0
- package/dist/chunks/git.DXfdBEfR.js +74 -0
- package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
- package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
- package/dist/chunks/index.DFXFpH3w.js +607 -0
- package/dist/chunks/index.VfYQ6MXY.js +104 -0
- package/dist/chunks/index.ZIOEXBQB.js +2382 -0
- package/dist/chunks/inspector.DbDkSkFn.js +54 -0
- package/dist/chunks/node.IqGoMrm4.js +15 -0
- package/dist/chunks/{reporters.d.CqBhtcTq.d.ts → reporters.d.5g6jXhoW.d.ts} +25 -8
- package/dist/chunks/rpc.DGgL5dw7.js +92 -0
- package/dist/chunks/run-once.I7PpBOk1.js +47 -0
- package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
- package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
- package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
- package/dist/chunks/utils.BfxieIyZ.js +66 -0
- package/dist/chunks/utils.CtocqOoE.js +72 -0
- package/dist/chunks/utils.OLmtDstN.js +194 -0
- package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
- package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
- package/dist/chunks/vm.BW5voG-u.js +789 -0
- package/dist/cli.js +2 -2
- package/dist/config.cjs +97 -103
- package/dist/config.d.ts +3 -3
- package/dist/config.js +6 -6
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +6 -6
- package/dist/environments.js +1 -1
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/node.d.ts +3 -3
- package/dist/node.js +36 -45
- package/dist/path.js +1 -4
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +4 -4
- package/dist/runners.js +231 -267
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +98 -114
- package/dist/workers/forks.js +22 -22
- package/dist/workers/runVmTests.js +61 -66
- package/dist/workers/threads.js +13 -13
- package/dist/workers/vmForks.js +24 -24
- package/dist/workers/vmThreads.js +15 -15
- package/dist/workers.js +10 -10
- package/package.json +11 -11
- package/dist/chunks/base.DV59CbtV.js +0 -45
- package/dist/chunks/benchmark.DL72EVN-.js +0 -40
- package/dist/chunks/cac.CeVHgzve.js +0 -1659
- package/dist/chunks/console.CN7AiMGV.js +0 -179
- package/dist/chunks/constants.DTYd6dNH.js +0 -46
- package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
- package/dist/chunks/creator.BsBnpTzI.js +0 -670
- package/dist/chunks/date.W2xKR2qe.js +0 -53
- package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
- package/dist/chunks/execute.eDH0aFFd.js +0 -839
- package/dist/chunks/git.B5SDxu-n.js +0 -69
- package/dist/chunks/index.B8tIoLPT.js +0 -2526
- package/dist/chunks/index.K90BXFOx.js +0 -658
- package/dist/chunks/index.uXkkC4xl.js +0 -111
- package/dist/chunks/inspector.DKLceBVD.js +0 -54
- package/dist/chunks/node.AKq966Jp.js +0 -15
- package/dist/chunks/rpc.TVf73xOu.js +0 -102
- package/dist/chunks/run-once.2ogXb3JV.js +0 -28
- package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
- package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
- package/dist/chunks/utils.C8RiOc4B.js +0 -77
- package/dist/chunks/utils.Cn0zI1t3.js +0 -68
- package/dist/chunks/utils.bLM2atbD.js +0 -198
- package/dist/chunks/vite.d.BUZTGxQ3.d.ts +0 -11
- package/dist/chunks/vm.jEFQDlX_.js +0 -852
|
@@ -2,146 +2,116 @@ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, J
|
|
|
2
2
|
import { getCurrentTest } from '@vitest/runner';
|
|
3
3
|
import { getNames, getTestName } from '@vitest/runner/utils';
|
|
4
4
|
import * as chai$1 from 'chai';
|
|
5
|
-
import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.
|
|
5
|
+
import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.CtocqOoE.js';
|
|
6
6
|
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
7
7
|
import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
|
|
8
8
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
|
|
9
9
|
import '@vitest/utils/error';
|
|
10
10
|
import { fn, spyOn, mocks, isMockFunction } from '@vitest/spy';
|
|
11
11
|
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
12
|
-
import { R as RealDate, r as resetDate, m as mockDate } from './date.
|
|
12
|
+
import { R as RealDate, r as resetDate, m as mockDate } from './date.CDOsz-HY.js';
|
|
13
13
|
|
|
14
14
|
const unsupported = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"Throw",
|
|
26
|
-
"throw",
|
|
27
|
-
"toThrow",
|
|
28
|
-
"toThrowError"
|
|
29
|
-
// these are not supported because you can call them without `.poll`,
|
|
30
|
-
// we throw an error inside the rejects/resolves methods to prevent this
|
|
31
|
-
// rejects,
|
|
32
|
-
// resolves
|
|
15
|
+
"matchSnapshot",
|
|
16
|
+
"toMatchSnapshot",
|
|
17
|
+
"toMatchInlineSnapshot",
|
|
18
|
+
"toThrowErrorMatchingSnapshot",
|
|
19
|
+
"toThrowErrorMatchingInlineSnapshot",
|
|
20
|
+
"throws",
|
|
21
|
+
"Throw",
|
|
22
|
+
"throw",
|
|
23
|
+
"toThrow",
|
|
24
|
+
"toThrowError"
|
|
33
25
|
];
|
|
34
26
|
function createExpectPoll(expect) {
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
throw copyStackTrace$1(error, STACK_TRACE_ERROR);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
let resultPromise;
|
|
121
|
-
return {
|
|
122
|
-
then(onFulfilled, onRejected) {
|
|
123
|
-
awaited = true;
|
|
124
|
-
return (resultPromise ||= promise()).then(onFulfilled, onRejected);
|
|
125
|
-
},
|
|
126
|
-
catch(onRejected) {
|
|
127
|
-
return (resultPromise ||= promise()).catch(onRejected);
|
|
128
|
-
},
|
|
129
|
-
finally(onFinally) {
|
|
130
|
-
return (resultPromise ||= promise()).finally(onFinally);
|
|
131
|
-
},
|
|
132
|
-
[Symbol.toStringTag]: "Promise"
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
return proxy;
|
|
138
|
-
};
|
|
27
|
+
return function poll(fn, options = {}) {
|
|
28
|
+
const state = getWorkerState();
|
|
29
|
+
const defaults = state.config.expect?.poll ?? {};
|
|
30
|
+
const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
|
|
31
|
+
const assertion = expect(null, message).withContext({ poll: true });
|
|
32
|
+
fn = fn.bind(assertion);
|
|
33
|
+
const test = chai$1.util.flag(assertion, "vitest-test");
|
|
34
|
+
if (!test) {
|
|
35
|
+
throw new Error("expect.poll() must be called inside a test");
|
|
36
|
+
}
|
|
37
|
+
const proxy = new Proxy(assertion, { get(target, key, receiver) {
|
|
38
|
+
const assertionFunction = Reflect.get(target, key, receiver);
|
|
39
|
+
if (typeof assertionFunction !== "function") {
|
|
40
|
+
return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
|
|
41
|
+
}
|
|
42
|
+
if (key === "assert") {
|
|
43
|
+
return assertionFunction;
|
|
44
|
+
}
|
|
45
|
+
if (typeof key === "string" && unsupported.includes(key)) {
|
|
46
|
+
throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
|
|
47
|
+
}
|
|
48
|
+
return function(...args) {
|
|
49
|
+
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
50
|
+
const promise = () => new Promise((resolve, reject) => {
|
|
51
|
+
let intervalId;
|
|
52
|
+
let timeoutId;
|
|
53
|
+
let lastError;
|
|
54
|
+
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
55
|
+
const check = async () => {
|
|
56
|
+
try {
|
|
57
|
+
chai$1.util.flag(assertion, "_name", key);
|
|
58
|
+
const obj = await fn();
|
|
59
|
+
chai$1.util.flag(assertion, "object", obj);
|
|
60
|
+
resolve(await assertionFunction.call(assertion, ...args));
|
|
61
|
+
clearTimeout(intervalId);
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
lastError = err;
|
|
65
|
+
if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) {
|
|
66
|
+
intervalId = setTimeout(check, interval);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
timeoutId = setTimeout(() => {
|
|
71
|
+
clearTimeout(intervalId);
|
|
72
|
+
chai$1.util.flag(assertion, "_isLastPollAttempt", true);
|
|
73
|
+
const rejectWithCause = (cause) => {
|
|
74
|
+
reject(copyStackTrace$1(new Error("Matcher did not succeed in time.", { cause }), STACK_TRACE_ERROR));
|
|
75
|
+
};
|
|
76
|
+
check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
|
|
77
|
+
}, timeout);
|
|
78
|
+
check();
|
|
79
|
+
});
|
|
80
|
+
let awaited = false;
|
|
81
|
+
test.onFinished ??= [];
|
|
82
|
+
test.onFinished.push(() => {
|
|
83
|
+
if (!awaited) {
|
|
84
|
+
const negated = chai$1.util.flag(assertion, "negate") ? "not." : "";
|
|
85
|
+
const name = chai$1.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)";
|
|
86
|
+
const assertionString = `expect.${name}.${negated}${String(key)}()`;
|
|
87
|
+
const error = new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:\n\nawait ${assertionString}\n`);
|
|
88
|
+
throw copyStackTrace$1(error, STACK_TRACE_ERROR);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
let resultPromise;
|
|
92
|
+
return {
|
|
93
|
+
then(onFulfilled, onRejected) {
|
|
94
|
+
awaited = true;
|
|
95
|
+
return (resultPromise ||= promise()).then(onFulfilled, onRejected);
|
|
96
|
+
},
|
|
97
|
+
catch(onRejected) {
|
|
98
|
+
return (resultPromise ||= promise()).catch(onRejected);
|
|
99
|
+
},
|
|
100
|
+
finally(onFinally) {
|
|
101
|
+
return (resultPromise ||= promise()).finally(onFinally);
|
|
102
|
+
},
|
|
103
|
+
[Symbol.toStringTag]: "Promise"
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
} });
|
|
107
|
+
return proxy;
|
|
108
|
+
};
|
|
139
109
|
}
|
|
140
110
|
function copyStackTrace$1(target, source) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
111
|
+
if (source.stack !== undefined) {
|
|
112
|
+
target.stack = source.stack.replace(source.message, target.message);
|
|
113
|
+
}
|
|
114
|
+
return target;
|
|
145
115
|
}
|
|
146
116
|
|
|
147
117
|
function commonjsRequire(path) {
|
|
@@ -244,258 +214,219 @@ var chaiSubsetExports = requireChaiSubset();
|
|
|
244
214
|
var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
|
|
245
215
|
|
|
246
216
|
function createAssertionMessage(util, assertion, hasArgs) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
217
|
+
const not = util.flag(assertion, "negate") ? "not." : "";
|
|
218
|
+
const name = `${util.flag(assertion, "_name")}(${"expected" })`;
|
|
219
|
+
const promiseName = util.flag(assertion, "promise");
|
|
220
|
+
const promise = promiseName ? `.${promiseName}` : "";
|
|
221
|
+
return `expect(actual)${promise}.${not}${name}`;
|
|
252
222
|
}
|
|
253
223
|
function recordAsyncExpect(_test, promise, assertion, error) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
224
|
+
const test = _test;
|
|
225
|
+
if (test && promise instanceof Promise) {
|
|
226
|
+
promise = promise.finally(() => {
|
|
227
|
+
if (!test.promises) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const index = test.promises.indexOf(promise);
|
|
231
|
+
if (index !== -1) {
|
|
232
|
+
test.promises.splice(index, 1);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
if (!test.promises) {
|
|
236
|
+
test.promises = [];
|
|
237
|
+
}
|
|
238
|
+
test.promises.push(promise);
|
|
239
|
+
let resolved = false;
|
|
240
|
+
test.onFinished ??= [];
|
|
241
|
+
test.onFinished.push(() => {
|
|
242
|
+
if (!resolved) {
|
|
243
|
+
const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || "");
|
|
244
|
+
const stack = processor(error.stack);
|
|
245
|
+
console.warn([
|
|
246
|
+
`Promise returned by \`${assertion}\` was not awaited. `,
|
|
247
|
+
"Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
|
|
248
|
+
"Please remember to await the assertion.\n",
|
|
249
|
+
stack
|
|
250
|
+
].join(""));
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
then(onFulfilled, onRejected) {
|
|
255
|
+
resolved = true;
|
|
256
|
+
return promise.then(onFulfilled, onRejected);
|
|
257
|
+
},
|
|
258
|
+
catch(onRejected) {
|
|
259
|
+
return promise.catch(onRejected);
|
|
260
|
+
},
|
|
261
|
+
finally(onFinally) {
|
|
262
|
+
return promise.finally(onFinally);
|
|
263
|
+
},
|
|
264
|
+
[Symbol.toStringTag]: "Promise"
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return promise;
|
|
298
268
|
}
|
|
299
269
|
|
|
300
270
|
let _client;
|
|
301
271
|
function getSnapshotClient() {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
return _client;
|
|
272
|
+
if (!_client) {
|
|
273
|
+
_client = new SnapshotClient({ isEqual: (received, expected) => {
|
|
274
|
+
return equals(received, expected, [iterableEquality, subsetEquality]);
|
|
275
|
+
} });
|
|
276
|
+
}
|
|
277
|
+
return _client;
|
|
310
278
|
}
|
|
311
279
|
function getError(expected, promise) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
throw new Error("snapshot function didn't throw");
|
|
280
|
+
if (typeof expected !== "function") {
|
|
281
|
+
if (!promise) {
|
|
282
|
+
throw new Error(`expected must be a function, received ${typeof expected}`);
|
|
283
|
+
}
|
|
284
|
+
return expected;
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
expected();
|
|
288
|
+
} catch (e) {
|
|
289
|
+
return e;
|
|
290
|
+
}
|
|
291
|
+
throw new Error("snapshot function didn't throw");
|
|
326
292
|
}
|
|
327
293
|
function getTestNames(test) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
294
|
+
return {
|
|
295
|
+
filepath: test.file.filepath,
|
|
296
|
+
name: getNames(test).slice(1).join(" > "),
|
|
297
|
+
testId: test.id
|
|
298
|
+
};
|
|
333
299
|
}
|
|
334
300
|
const SnapshotPlugin = (chai, utils) => {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
chai.Assertion.prototype,
|
|
465
|
-
"toThrowErrorMatchingInlineSnapshot",
|
|
466
|
-
function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
467
|
-
const isNot = utils.flag(this, "negate");
|
|
468
|
-
if (isNot) {
|
|
469
|
-
throw new Error(
|
|
470
|
-
'toThrowErrorMatchingInlineSnapshot cannot be used with "not"'
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
const test = getTest("toThrowErrorMatchingInlineSnapshot", this);
|
|
474
|
-
const isInsideEach = test.each || test.suite?.each;
|
|
475
|
-
if (isInsideEach) {
|
|
476
|
-
throw new Error(
|
|
477
|
-
"InlineSnapshot cannot be used inside of test.each or describe.each"
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
const expected = utils.flag(this, "object");
|
|
481
|
-
const error = utils.flag(this, "error");
|
|
482
|
-
const promise = utils.flag(this, "promise");
|
|
483
|
-
const errorMessage = utils.flag(this, "message");
|
|
484
|
-
if (inlineSnapshot) {
|
|
485
|
-
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
486
|
-
}
|
|
487
|
-
getSnapshotClient().assert({
|
|
488
|
-
received: getError(expected, promise),
|
|
489
|
-
message,
|
|
490
|
-
inlineSnapshot,
|
|
491
|
-
isInline: true,
|
|
492
|
-
error,
|
|
493
|
-
errorMessage,
|
|
494
|
-
...getTestNames(test)
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
);
|
|
498
|
-
utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
|
|
301
|
+
function getTest(assertionName, obj) {
|
|
302
|
+
const test = utils.flag(obj, "vitest-test");
|
|
303
|
+
if (!test) {
|
|
304
|
+
throw new Error(`'${assertionName}' cannot be used without test context`);
|
|
305
|
+
}
|
|
306
|
+
return test;
|
|
307
|
+
}
|
|
308
|
+
for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
|
|
309
|
+
utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
|
|
310
|
+
utils.flag(this, "_name", key);
|
|
311
|
+
const isNot = utils.flag(this, "negate");
|
|
312
|
+
if (isNot) {
|
|
313
|
+
throw new Error(`${key} cannot be used with "not"`);
|
|
314
|
+
}
|
|
315
|
+
const expected = utils.flag(this, "object");
|
|
316
|
+
const test = getTest(key, this);
|
|
317
|
+
if (typeof properties === "string" && typeof message === "undefined") {
|
|
318
|
+
message = properties;
|
|
319
|
+
properties = undefined;
|
|
320
|
+
}
|
|
321
|
+
const errorMessage = utils.flag(this, "message");
|
|
322
|
+
getSnapshotClient().assert({
|
|
323
|
+
received: expected,
|
|
324
|
+
message,
|
|
325
|
+
isInline: false,
|
|
326
|
+
properties,
|
|
327
|
+
errorMessage,
|
|
328
|
+
...getTestNames(test)
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
utils.addMethod(chai.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
|
|
333
|
+
utils.flag(this, "_name", "toMatchFileSnapshot");
|
|
334
|
+
const isNot = utils.flag(this, "negate");
|
|
335
|
+
if (isNot) {
|
|
336
|
+
throw new Error("toMatchFileSnapshot cannot be used with \"not\"");
|
|
337
|
+
}
|
|
338
|
+
const error = new Error("resolves");
|
|
339
|
+
const expected = utils.flag(this, "object");
|
|
340
|
+
const test = getTest("toMatchFileSnapshot", this);
|
|
341
|
+
const errorMessage = utils.flag(this, "message");
|
|
342
|
+
const promise = getSnapshotClient().assertRaw({
|
|
343
|
+
received: expected,
|
|
344
|
+
message,
|
|
345
|
+
isInline: false,
|
|
346
|
+
rawSnapshot: { file },
|
|
347
|
+
errorMessage,
|
|
348
|
+
...getTestNames(test)
|
|
349
|
+
});
|
|
350
|
+
return recordAsyncExpect(test, promise, createAssertionMessage(utils, this), error);
|
|
351
|
+
});
|
|
352
|
+
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
353
|
+
utils.flag(this, "_name", "toMatchInlineSnapshot");
|
|
354
|
+
const isNot = utils.flag(this, "negate");
|
|
355
|
+
if (isNot) {
|
|
356
|
+
throw new Error("toMatchInlineSnapshot cannot be used with \"not\"");
|
|
357
|
+
}
|
|
358
|
+
const test = getTest("toMatchInlineSnapshot", this);
|
|
359
|
+
const isInsideEach = test.each || test.suite?.each;
|
|
360
|
+
if (isInsideEach) {
|
|
361
|
+
throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
362
|
+
}
|
|
363
|
+
const expected = utils.flag(this, "object");
|
|
364
|
+
const error = utils.flag(this, "error");
|
|
365
|
+
if (typeof properties === "string") {
|
|
366
|
+
message = inlineSnapshot;
|
|
367
|
+
inlineSnapshot = properties;
|
|
368
|
+
properties = undefined;
|
|
369
|
+
}
|
|
370
|
+
if (inlineSnapshot) {
|
|
371
|
+
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
372
|
+
}
|
|
373
|
+
const errorMessage = utils.flag(this, "message");
|
|
374
|
+
getSnapshotClient().assert({
|
|
375
|
+
received: expected,
|
|
376
|
+
message,
|
|
377
|
+
isInline: true,
|
|
378
|
+
properties,
|
|
379
|
+
inlineSnapshot,
|
|
380
|
+
error,
|
|
381
|
+
errorMessage,
|
|
382
|
+
...getTestNames(test)
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
|
|
386
|
+
utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
|
|
387
|
+
const isNot = utils.flag(this, "negate");
|
|
388
|
+
if (isNot) {
|
|
389
|
+
throw new Error("toThrowErrorMatchingSnapshot cannot be used with \"not\"");
|
|
390
|
+
}
|
|
391
|
+
const expected = utils.flag(this, "object");
|
|
392
|
+
const test = getTest("toThrowErrorMatchingSnapshot", this);
|
|
393
|
+
const promise = utils.flag(this, "promise");
|
|
394
|
+
const errorMessage = utils.flag(this, "message");
|
|
395
|
+
getSnapshotClient().assert({
|
|
396
|
+
received: getError(expected, promise),
|
|
397
|
+
message,
|
|
398
|
+
errorMessage,
|
|
399
|
+
...getTestNames(test)
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
403
|
+
const isNot = utils.flag(this, "negate");
|
|
404
|
+
if (isNot) {
|
|
405
|
+
throw new Error("toThrowErrorMatchingInlineSnapshot cannot be used with \"not\"");
|
|
406
|
+
}
|
|
407
|
+
const test = getTest("toThrowErrorMatchingInlineSnapshot", this);
|
|
408
|
+
const isInsideEach = test.each || test.suite?.each;
|
|
409
|
+
if (isInsideEach) {
|
|
410
|
+
throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
411
|
+
}
|
|
412
|
+
const expected = utils.flag(this, "object");
|
|
413
|
+
const error = utils.flag(this, "error");
|
|
414
|
+
const promise = utils.flag(this, "promise");
|
|
415
|
+
const errorMessage = utils.flag(this, "message");
|
|
416
|
+
if (inlineSnapshot) {
|
|
417
|
+
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
418
|
+
}
|
|
419
|
+
getSnapshotClient().assert({
|
|
420
|
+
received: getError(expected, promise),
|
|
421
|
+
message,
|
|
422
|
+
inlineSnapshot,
|
|
423
|
+
isInline: true,
|
|
424
|
+
error,
|
|
425
|
+
errorMessage,
|
|
426
|
+
...getTestNames(test)
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
|
|
499
430
|
};
|
|
500
431
|
|
|
501
432
|
chai$1.use(JestExtend);
|
|
@@ -505,87 +436,83 @@ chai$1.use(SnapshotPlugin);
|
|
|
505
436
|
chai$1.use(JestAsymmetricMatchers);
|
|
506
437
|
|
|
507
438
|
function createExpect(test) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
isExpectingAssertions: true,
|
|
571
|
-
isExpectingAssertionsError: error
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
chai$1.util.addMethod(expect, "assertions", assertions);
|
|
575
|
-
chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
|
|
576
|
-
expect.extend(customMatchers);
|
|
577
|
-
return expect;
|
|
439
|
+
const expect = (value, message) => {
|
|
440
|
+
const { assertionCalls } = getState(expect);
|
|
441
|
+
setState({ assertionCalls: assertionCalls + 1 }, expect);
|
|
442
|
+
const assert = chai$1.expect(value, message);
|
|
443
|
+
const _test = test || getCurrentTest();
|
|
444
|
+
if (_test) {
|
|
445
|
+
return assert.withTest(_test);
|
|
446
|
+
} else {
|
|
447
|
+
return assert;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
Object.assign(expect, chai$1.expect);
|
|
451
|
+
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
452
|
+
expect.getState = () => getState(expect);
|
|
453
|
+
expect.setState = (state) => setState(state, expect);
|
|
454
|
+
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
|
|
455
|
+
setState({
|
|
456
|
+
...globalState,
|
|
457
|
+
assertionCalls: 0,
|
|
458
|
+
isExpectingAssertions: false,
|
|
459
|
+
isExpectingAssertionsError: null,
|
|
460
|
+
expectedAssertionsNumber: null,
|
|
461
|
+
expectedAssertionsNumberErrorGen: null,
|
|
462
|
+
environment: getCurrentEnvironment(),
|
|
463
|
+
get testPath() {
|
|
464
|
+
return getWorkerState().filepath;
|
|
465
|
+
},
|
|
466
|
+
currentTestName: test ? getTestName(test) : globalState.currentTestName
|
|
467
|
+
}, expect);
|
|
468
|
+
expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
|
|
469
|
+
expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
|
|
470
|
+
expect.soft = (...args) => {
|
|
471
|
+
return expect(...args).withContext({ soft: true });
|
|
472
|
+
};
|
|
473
|
+
expect.poll = createExpectPoll(expect);
|
|
474
|
+
expect.unreachable = (message) => {
|
|
475
|
+
chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
|
|
476
|
+
};
|
|
477
|
+
function assertions(expected) {
|
|
478
|
+
const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
|
|
479
|
+
if (Error.captureStackTrace) {
|
|
480
|
+
Error.captureStackTrace(errorGen(), assertions);
|
|
481
|
+
}
|
|
482
|
+
expect.setState({
|
|
483
|
+
expectedAssertionsNumber: expected,
|
|
484
|
+
expectedAssertionsNumberErrorGen: errorGen
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
function hasAssertions() {
|
|
488
|
+
const error = new Error("expected any number of assertion, but got none");
|
|
489
|
+
if (Error.captureStackTrace) {
|
|
490
|
+
Error.captureStackTrace(error, hasAssertions);
|
|
491
|
+
}
|
|
492
|
+
expect.setState({
|
|
493
|
+
isExpectingAssertions: true,
|
|
494
|
+
isExpectingAssertionsError: error
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
chai$1.util.addMethod(expect, "assertions", assertions);
|
|
498
|
+
chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
|
|
499
|
+
expect.extend(customMatchers);
|
|
500
|
+
return expect;
|
|
578
501
|
}
|
|
579
502
|
const globalExpect = createExpect();
|
|
580
503
|
Object.defineProperty(globalThis, GLOBAL_EXPECT, {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
504
|
+
value: globalExpect,
|
|
505
|
+
writable: true,
|
|
506
|
+
configurable: true
|
|
584
507
|
});
|
|
585
508
|
|
|
509
|
+
/**
|
|
510
|
+
* Gives access to injected context provided from the main thread.
|
|
511
|
+
* This usually returns a value provided by `globalSetup` or an external library.
|
|
512
|
+
*/
|
|
586
513
|
function inject(key) {
|
|
587
|
-
|
|
588
|
-
|
|
514
|
+
const workerState = getWorkerState();
|
|
515
|
+
return workerState.providedContext[key];
|
|
589
516
|
}
|
|
590
517
|
|
|
591
518
|
var fakeTimersSrc = {};
|
|
@@ -3682,598 +3609,530 @@ function requireFakeTimersSrc () {
|
|
|
3682
3609
|
var fakeTimersSrcExports = requireFakeTimersSrc();
|
|
3683
3610
|
|
|
3684
3611
|
class FakeTimers {
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
}
|
|
3838
|
-
return 0;
|
|
3839
|
-
}
|
|
3840
|
-
configure(config) {
|
|
3841
|
-
this._userConfig = config;
|
|
3842
|
-
}
|
|
3843
|
-
isFakeTimers() {
|
|
3844
|
-
return this._fakingTime;
|
|
3845
|
-
}
|
|
3846
|
-
_checkFakeTimers() {
|
|
3847
|
-
if (!this._fakingTime) {
|
|
3848
|
-
throw new Error(
|
|
3849
|
-
'Timers are not mocked. Try calling "vi.useFakeTimers()" first.'
|
|
3850
|
-
);
|
|
3851
|
-
}
|
|
3852
|
-
return this._fakingTime;
|
|
3853
|
-
}
|
|
3612
|
+
_global;
|
|
3613
|
+
_clock;
|
|
3614
|
+
_fakingTime;
|
|
3615
|
+
_fakingDate;
|
|
3616
|
+
_fakeTimers;
|
|
3617
|
+
_userConfig;
|
|
3618
|
+
_now = RealDate.now;
|
|
3619
|
+
constructor({ global, config }) {
|
|
3620
|
+
this._userConfig = config;
|
|
3621
|
+
this._fakingDate = null;
|
|
3622
|
+
this._fakingTime = false;
|
|
3623
|
+
this._fakeTimers = fakeTimersSrcExports.withGlobal(global);
|
|
3624
|
+
this._global = global;
|
|
3625
|
+
}
|
|
3626
|
+
clearAllTimers() {
|
|
3627
|
+
if (this._fakingTime) {
|
|
3628
|
+
this._clock.reset();
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
dispose() {
|
|
3632
|
+
this.useRealTimers();
|
|
3633
|
+
}
|
|
3634
|
+
runAllTimers() {
|
|
3635
|
+
if (this._checkFakeTimers()) {
|
|
3636
|
+
this._clock.runAll();
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3639
|
+
async runAllTimersAsync() {
|
|
3640
|
+
if (this._checkFakeTimers()) {
|
|
3641
|
+
await this._clock.runAllAsync();
|
|
3642
|
+
}
|
|
3643
|
+
}
|
|
3644
|
+
runOnlyPendingTimers() {
|
|
3645
|
+
if (this._checkFakeTimers()) {
|
|
3646
|
+
this._clock.runToLast();
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
async runOnlyPendingTimersAsync() {
|
|
3650
|
+
if (this._checkFakeTimers()) {
|
|
3651
|
+
await this._clock.runToLastAsync();
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
advanceTimersToNextTimer(steps = 1) {
|
|
3655
|
+
if (this._checkFakeTimers()) {
|
|
3656
|
+
for (let i = steps; i > 0; i--) {
|
|
3657
|
+
this._clock.next();
|
|
3658
|
+
this._clock.tick(0);
|
|
3659
|
+
if (this._clock.countTimers() === 0) {
|
|
3660
|
+
break;
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
async advanceTimersToNextTimerAsync(steps = 1) {
|
|
3666
|
+
if (this._checkFakeTimers()) {
|
|
3667
|
+
for (let i = steps; i > 0; i--) {
|
|
3668
|
+
await this._clock.nextAsync();
|
|
3669
|
+
this._clock.tick(0);
|
|
3670
|
+
if (this._clock.countTimers() === 0) {
|
|
3671
|
+
break;
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
advanceTimersByTime(msToRun) {
|
|
3677
|
+
if (this._checkFakeTimers()) {
|
|
3678
|
+
this._clock.tick(msToRun);
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
async advanceTimersByTimeAsync(msToRun) {
|
|
3682
|
+
if (this._checkFakeTimers()) {
|
|
3683
|
+
await this._clock.tickAsync(msToRun);
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
advanceTimersToNextFrame() {
|
|
3687
|
+
if (this._checkFakeTimers()) {
|
|
3688
|
+
this._clock.runToFrame();
|
|
3689
|
+
}
|
|
3690
|
+
}
|
|
3691
|
+
runAllTicks() {
|
|
3692
|
+
if (this._checkFakeTimers()) {
|
|
3693
|
+
this._clock.runMicrotasks();
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
useRealTimers() {
|
|
3697
|
+
if (this._fakingDate) {
|
|
3698
|
+
resetDate();
|
|
3699
|
+
this._fakingDate = null;
|
|
3700
|
+
}
|
|
3701
|
+
if (this._fakingTime) {
|
|
3702
|
+
this._clock.uninstall();
|
|
3703
|
+
this._fakingTime = false;
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
useFakeTimers() {
|
|
3707
|
+
if (this._fakingDate) {
|
|
3708
|
+
throw new Error("\"setSystemTime\" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.");
|
|
3709
|
+
}
|
|
3710
|
+
if (!this._fakingTime) {
|
|
3711
|
+
const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick" && timer !== "queueMicrotask");
|
|
3712
|
+
if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) {
|
|
3713
|
+
throw new Error("process.nextTick cannot be mocked inside child_process");
|
|
3714
|
+
}
|
|
3715
|
+
this._clock = this._fakeTimers.install({
|
|
3716
|
+
now: Date.now(),
|
|
3717
|
+
...this._userConfig,
|
|
3718
|
+
toFake: this._userConfig?.toFake || toFake,
|
|
3719
|
+
ignoreMissingTimers: true
|
|
3720
|
+
});
|
|
3721
|
+
this._fakingTime = true;
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
reset() {
|
|
3725
|
+
if (this._checkFakeTimers()) {
|
|
3726
|
+
const { now } = this._clock;
|
|
3727
|
+
this._clock.reset();
|
|
3728
|
+
this._clock.setSystemTime(now);
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
setSystemTime(now) {
|
|
3732
|
+
const date = typeof now === "undefined" || now instanceof Date ? now : new Date(now);
|
|
3733
|
+
if (this._fakingTime) {
|
|
3734
|
+
this._clock.setSystemTime(date);
|
|
3735
|
+
} else {
|
|
3736
|
+
this._fakingDate = date ?? new Date(this.getRealSystemTime());
|
|
3737
|
+
mockDate(this._fakingDate);
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
getMockedSystemTime() {
|
|
3741
|
+
return this._fakingTime ? new Date(this._clock.now) : this._fakingDate;
|
|
3742
|
+
}
|
|
3743
|
+
getRealSystemTime() {
|
|
3744
|
+
return this._now();
|
|
3745
|
+
}
|
|
3746
|
+
getTimerCount() {
|
|
3747
|
+
if (this._checkFakeTimers()) {
|
|
3748
|
+
return this._clock.countTimers();
|
|
3749
|
+
}
|
|
3750
|
+
return 0;
|
|
3751
|
+
}
|
|
3752
|
+
configure(config) {
|
|
3753
|
+
this._userConfig = config;
|
|
3754
|
+
}
|
|
3755
|
+
isFakeTimers() {
|
|
3756
|
+
return this._fakingTime;
|
|
3757
|
+
}
|
|
3758
|
+
_checkFakeTimers() {
|
|
3759
|
+
if (!this._fakingTime) {
|
|
3760
|
+
throw new Error("Timers are not mocked. Try calling \"vi.useFakeTimers()\" first.");
|
|
3761
|
+
}
|
|
3762
|
+
return this._fakingTime;
|
|
3763
|
+
}
|
|
3854
3764
|
}
|
|
3855
3765
|
|
|
3856
3766
|
function copyStackTrace(target, source) {
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3767
|
+
if (source.stack !== undefined) {
|
|
3768
|
+
target.stack = source.stack.replace(source.message, target.message);
|
|
3769
|
+
}
|
|
3770
|
+
return target;
|
|
3861
3771
|
}
|
|
3862
3772
|
function waitFor(callback, options = {}) {
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
if (checkCallback() === true) {
|
|
3924
|
-
return;
|
|
3925
|
-
}
|
|
3926
|
-
timeoutId = setTimeout(handleTimeout, timeout);
|
|
3927
|
-
intervalId = setInterval(checkCallback, interval);
|
|
3928
|
-
});
|
|
3773
|
+
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
|
|
3774
|
+
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
3775
|
+
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
3776
|
+
return new Promise((resolve, reject) => {
|
|
3777
|
+
let lastError;
|
|
3778
|
+
let promiseStatus = "idle";
|
|
3779
|
+
let timeoutId;
|
|
3780
|
+
let intervalId;
|
|
3781
|
+
const onResolve = (result) => {
|
|
3782
|
+
if (timeoutId) {
|
|
3783
|
+
clearTimeout(timeoutId);
|
|
3784
|
+
}
|
|
3785
|
+
if (intervalId) {
|
|
3786
|
+
clearInterval(intervalId);
|
|
3787
|
+
}
|
|
3788
|
+
resolve(result);
|
|
3789
|
+
};
|
|
3790
|
+
const handleTimeout = () => {
|
|
3791
|
+
if (intervalId) {
|
|
3792
|
+
clearInterval(intervalId);
|
|
3793
|
+
}
|
|
3794
|
+
let error = lastError;
|
|
3795
|
+
if (!error) {
|
|
3796
|
+
error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
|
|
3797
|
+
}
|
|
3798
|
+
reject(error);
|
|
3799
|
+
};
|
|
3800
|
+
const checkCallback = () => {
|
|
3801
|
+
if (vi.isFakeTimers()) {
|
|
3802
|
+
vi.advanceTimersByTime(interval);
|
|
3803
|
+
}
|
|
3804
|
+
if (promiseStatus === "pending") {
|
|
3805
|
+
return;
|
|
3806
|
+
}
|
|
3807
|
+
try {
|
|
3808
|
+
const result = callback();
|
|
3809
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
3810
|
+
const thenable = result;
|
|
3811
|
+
promiseStatus = "pending";
|
|
3812
|
+
thenable.then((resolvedValue) => {
|
|
3813
|
+
promiseStatus = "resolved";
|
|
3814
|
+
onResolve(resolvedValue);
|
|
3815
|
+
}, (rejectedValue) => {
|
|
3816
|
+
promiseStatus = "rejected";
|
|
3817
|
+
lastError = rejectedValue;
|
|
3818
|
+
});
|
|
3819
|
+
} else {
|
|
3820
|
+
onResolve(result);
|
|
3821
|
+
return true;
|
|
3822
|
+
}
|
|
3823
|
+
} catch (error) {
|
|
3824
|
+
lastError = error;
|
|
3825
|
+
}
|
|
3826
|
+
};
|
|
3827
|
+
if (checkCallback() === true) {
|
|
3828
|
+
return;
|
|
3829
|
+
}
|
|
3830
|
+
timeoutId = setTimeout(handleTimeout, timeout);
|
|
3831
|
+
intervalId = setInterval(checkCallback, interval);
|
|
3832
|
+
});
|
|
3929
3833
|
}
|
|
3930
3834
|
function waitUntil(callback, options = {}) {
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
if (checkCallback() === true) {
|
|
3993
|
-
return;
|
|
3994
|
-
}
|
|
3995
|
-
timeoutId = setTimeout(onReject, timeout);
|
|
3996
|
-
intervalId = setInterval(checkCallback, interval);
|
|
3997
|
-
});
|
|
3835
|
+
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
|
|
3836
|
+
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
3837
|
+
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
3838
|
+
return new Promise((resolve, reject) => {
|
|
3839
|
+
let promiseStatus = "idle";
|
|
3840
|
+
let timeoutId;
|
|
3841
|
+
let intervalId;
|
|
3842
|
+
const onReject = (error) => {
|
|
3843
|
+
if (intervalId) {
|
|
3844
|
+
clearInterval(intervalId);
|
|
3845
|
+
}
|
|
3846
|
+
if (!error) {
|
|
3847
|
+
error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
|
|
3848
|
+
}
|
|
3849
|
+
reject(error);
|
|
3850
|
+
};
|
|
3851
|
+
const onResolve = (result) => {
|
|
3852
|
+
if (!result) {
|
|
3853
|
+
return;
|
|
3854
|
+
}
|
|
3855
|
+
if (timeoutId) {
|
|
3856
|
+
clearTimeout(timeoutId);
|
|
3857
|
+
}
|
|
3858
|
+
if (intervalId) {
|
|
3859
|
+
clearInterval(intervalId);
|
|
3860
|
+
}
|
|
3861
|
+
resolve(result);
|
|
3862
|
+
return true;
|
|
3863
|
+
};
|
|
3864
|
+
const checkCallback = () => {
|
|
3865
|
+
if (vi.isFakeTimers()) {
|
|
3866
|
+
vi.advanceTimersByTime(interval);
|
|
3867
|
+
}
|
|
3868
|
+
if (promiseStatus === "pending") {
|
|
3869
|
+
return;
|
|
3870
|
+
}
|
|
3871
|
+
try {
|
|
3872
|
+
const result = callback();
|
|
3873
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
3874
|
+
const thenable = result;
|
|
3875
|
+
promiseStatus = "pending";
|
|
3876
|
+
thenable.then((resolvedValue) => {
|
|
3877
|
+
promiseStatus = "resolved";
|
|
3878
|
+
onResolve(resolvedValue);
|
|
3879
|
+
}, (rejectedValue) => {
|
|
3880
|
+
promiseStatus = "rejected";
|
|
3881
|
+
onReject(rejectedValue);
|
|
3882
|
+
});
|
|
3883
|
+
} else {
|
|
3884
|
+
return onResolve(result);
|
|
3885
|
+
}
|
|
3886
|
+
} catch (error) {
|
|
3887
|
+
onReject(error);
|
|
3888
|
+
}
|
|
3889
|
+
};
|
|
3890
|
+
if (checkCallback() === true) {
|
|
3891
|
+
return;
|
|
3892
|
+
}
|
|
3893
|
+
timeoutId = setTimeout(onReject, timeout);
|
|
3894
|
+
intervalId = setInterval(checkCallback, interval);
|
|
3895
|
+
});
|
|
3998
3896
|
}
|
|
3999
3897
|
|
|
4000
3898
|
function createVitest() {
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
},
|
|
4223
|
-
unstubAllEnvs() {
|
|
4224
|
-
_stubsEnv.forEach((original, name) => {
|
|
4225
|
-
if (original === void 0) {
|
|
4226
|
-
delete process.env[name];
|
|
4227
|
-
} else {
|
|
4228
|
-
process.env[name] = original;
|
|
4229
|
-
}
|
|
4230
|
-
});
|
|
4231
|
-
_stubsEnv.clear();
|
|
4232
|
-
return utils;
|
|
4233
|
-
},
|
|
4234
|
-
resetModules() {
|
|
4235
|
-
resetModules(workerState.moduleCache);
|
|
4236
|
-
return utils;
|
|
4237
|
-
},
|
|
4238
|
-
async dynamicImportSettled() {
|
|
4239
|
-
return waitForImportsToResolve();
|
|
4240
|
-
},
|
|
4241
|
-
setConfig(config) {
|
|
4242
|
-
if (!_config) {
|
|
4243
|
-
_config = { ...workerState.config };
|
|
4244
|
-
}
|
|
4245
|
-
Object.assign(workerState.config, config);
|
|
4246
|
-
},
|
|
4247
|
-
resetConfig() {
|
|
4248
|
-
if (_config) {
|
|
4249
|
-
Object.assign(workerState.config, _config);
|
|
4250
|
-
}
|
|
4251
|
-
}
|
|
4252
|
-
};
|
|
4253
|
-
return utils;
|
|
3899
|
+
let _config = null;
|
|
3900
|
+
const workerState = getWorkerState();
|
|
3901
|
+
let _timers;
|
|
3902
|
+
const timers = () => _timers ||= new FakeTimers({
|
|
3903
|
+
global: globalThis,
|
|
3904
|
+
config: workerState.config.fakeTimers
|
|
3905
|
+
});
|
|
3906
|
+
const _stubsGlobal = new Map();
|
|
3907
|
+
const _stubsEnv = new Map();
|
|
3908
|
+
const _envBooleans = [
|
|
3909
|
+
"PROD",
|
|
3910
|
+
"DEV",
|
|
3911
|
+
"SSR"
|
|
3912
|
+
];
|
|
3913
|
+
const utils = {
|
|
3914
|
+
useFakeTimers(config) {
|
|
3915
|
+
if (isChildProcess()) {
|
|
3916
|
+
if (config?.toFake?.includes("nextTick") || workerState.config?.fakeTimers?.toFake?.includes("nextTick")) {
|
|
3917
|
+
throw new Error("vi.useFakeTimers({ toFake: [\"nextTick\"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.");
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
if (config) {
|
|
3921
|
+
timers().configure({
|
|
3922
|
+
...workerState.config.fakeTimers,
|
|
3923
|
+
...config
|
|
3924
|
+
});
|
|
3925
|
+
} else {
|
|
3926
|
+
timers().configure(workerState.config.fakeTimers);
|
|
3927
|
+
}
|
|
3928
|
+
timers().useFakeTimers();
|
|
3929
|
+
return utils;
|
|
3930
|
+
},
|
|
3931
|
+
isFakeTimers() {
|
|
3932
|
+
return timers().isFakeTimers();
|
|
3933
|
+
},
|
|
3934
|
+
useRealTimers() {
|
|
3935
|
+
timers().useRealTimers();
|
|
3936
|
+
return utils;
|
|
3937
|
+
},
|
|
3938
|
+
runOnlyPendingTimers() {
|
|
3939
|
+
timers().runOnlyPendingTimers();
|
|
3940
|
+
return utils;
|
|
3941
|
+
},
|
|
3942
|
+
async runOnlyPendingTimersAsync() {
|
|
3943
|
+
await timers().runOnlyPendingTimersAsync();
|
|
3944
|
+
return utils;
|
|
3945
|
+
},
|
|
3946
|
+
runAllTimers() {
|
|
3947
|
+
timers().runAllTimers();
|
|
3948
|
+
return utils;
|
|
3949
|
+
},
|
|
3950
|
+
async runAllTimersAsync() {
|
|
3951
|
+
await timers().runAllTimersAsync();
|
|
3952
|
+
return utils;
|
|
3953
|
+
},
|
|
3954
|
+
runAllTicks() {
|
|
3955
|
+
timers().runAllTicks();
|
|
3956
|
+
return utils;
|
|
3957
|
+
},
|
|
3958
|
+
advanceTimersByTime(ms) {
|
|
3959
|
+
timers().advanceTimersByTime(ms);
|
|
3960
|
+
return utils;
|
|
3961
|
+
},
|
|
3962
|
+
async advanceTimersByTimeAsync(ms) {
|
|
3963
|
+
await timers().advanceTimersByTimeAsync(ms);
|
|
3964
|
+
return utils;
|
|
3965
|
+
},
|
|
3966
|
+
advanceTimersToNextTimer() {
|
|
3967
|
+
timers().advanceTimersToNextTimer();
|
|
3968
|
+
return utils;
|
|
3969
|
+
},
|
|
3970
|
+
async advanceTimersToNextTimerAsync() {
|
|
3971
|
+
await timers().advanceTimersToNextTimerAsync();
|
|
3972
|
+
return utils;
|
|
3973
|
+
},
|
|
3974
|
+
advanceTimersToNextFrame() {
|
|
3975
|
+
timers().advanceTimersToNextFrame();
|
|
3976
|
+
return utils;
|
|
3977
|
+
},
|
|
3978
|
+
getTimerCount() {
|
|
3979
|
+
return timers().getTimerCount();
|
|
3980
|
+
},
|
|
3981
|
+
setSystemTime(time) {
|
|
3982
|
+
timers().setSystemTime(time);
|
|
3983
|
+
return utils;
|
|
3984
|
+
},
|
|
3985
|
+
getMockedSystemTime() {
|
|
3986
|
+
return timers().getMockedSystemTime();
|
|
3987
|
+
},
|
|
3988
|
+
getRealSystemTime() {
|
|
3989
|
+
return timers().getRealSystemTime();
|
|
3990
|
+
},
|
|
3991
|
+
clearAllTimers() {
|
|
3992
|
+
timers().clearAllTimers();
|
|
3993
|
+
return utils;
|
|
3994
|
+
},
|
|
3995
|
+
spyOn,
|
|
3996
|
+
fn,
|
|
3997
|
+
waitFor,
|
|
3998
|
+
waitUntil,
|
|
3999
|
+
hoisted(factory) {
|
|
4000
|
+
assertTypes(factory, "\"vi.hoisted\" factory", ["function"]);
|
|
4001
|
+
return factory();
|
|
4002
|
+
},
|
|
4003
|
+
mock(path, factory) {
|
|
4004
|
+
if (typeof path !== "string") {
|
|
4005
|
+
throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
|
|
4006
|
+
}
|
|
4007
|
+
const importer = getImporter("mock");
|
|
4008
|
+
_mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer, _mocker().getMockContext().callstack)) : factory);
|
|
4009
|
+
},
|
|
4010
|
+
unmock(path) {
|
|
4011
|
+
if (typeof path !== "string") {
|
|
4012
|
+
throw new TypeError(`vi.unmock() expects a string path, but received a ${typeof path}`);
|
|
4013
|
+
}
|
|
4014
|
+
_mocker().queueUnmock(path, getImporter("unmock"));
|
|
4015
|
+
},
|
|
4016
|
+
doMock(path, factory) {
|
|
4017
|
+
if (typeof path !== "string") {
|
|
4018
|
+
throw new TypeError(`vi.doMock() expects a string path, but received a ${typeof path}`);
|
|
4019
|
+
}
|
|
4020
|
+
const importer = getImporter("doMock");
|
|
4021
|
+
_mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer, _mocker().getMockContext().callstack)) : factory);
|
|
4022
|
+
},
|
|
4023
|
+
doUnmock(path) {
|
|
4024
|
+
if (typeof path !== "string") {
|
|
4025
|
+
throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
|
|
4026
|
+
}
|
|
4027
|
+
_mocker().queueUnmock(path, getImporter("doUnmock"));
|
|
4028
|
+
},
|
|
4029
|
+
async importActual(path) {
|
|
4030
|
+
return _mocker().importActual(path, getImporter("importActual"), _mocker().getMockContext().callstack);
|
|
4031
|
+
},
|
|
4032
|
+
async importMock(path) {
|
|
4033
|
+
return _mocker().importMock(path, getImporter("importMock"));
|
|
4034
|
+
},
|
|
4035
|
+
mocked(item, _options = {}) {
|
|
4036
|
+
return item;
|
|
4037
|
+
},
|
|
4038
|
+
isMockFunction(fn) {
|
|
4039
|
+
return isMockFunction(fn);
|
|
4040
|
+
},
|
|
4041
|
+
clearAllMocks() {
|
|
4042
|
+
[...mocks].reverse().forEach((spy) => spy.mockClear());
|
|
4043
|
+
return utils;
|
|
4044
|
+
},
|
|
4045
|
+
resetAllMocks() {
|
|
4046
|
+
[...mocks].reverse().forEach((spy) => spy.mockReset());
|
|
4047
|
+
return utils;
|
|
4048
|
+
},
|
|
4049
|
+
restoreAllMocks() {
|
|
4050
|
+
[...mocks].reverse().forEach((spy) => spy.mockRestore());
|
|
4051
|
+
return utils;
|
|
4052
|
+
},
|
|
4053
|
+
stubGlobal(name, value) {
|
|
4054
|
+
if (!_stubsGlobal.has(name)) {
|
|
4055
|
+
_stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
|
|
4056
|
+
}
|
|
4057
|
+
Object.defineProperty(globalThis, name, {
|
|
4058
|
+
value,
|
|
4059
|
+
writable: true,
|
|
4060
|
+
configurable: true,
|
|
4061
|
+
enumerable: true
|
|
4062
|
+
});
|
|
4063
|
+
return utils;
|
|
4064
|
+
},
|
|
4065
|
+
stubEnv(name, value) {
|
|
4066
|
+
if (!_stubsEnv.has(name)) {
|
|
4067
|
+
_stubsEnv.set(name, process.env[name]);
|
|
4068
|
+
}
|
|
4069
|
+
if (_envBooleans.includes(name)) {
|
|
4070
|
+
process.env[name] = value ? "1" : "";
|
|
4071
|
+
} else if (value === undefined) {
|
|
4072
|
+
delete process.env[name];
|
|
4073
|
+
} else {
|
|
4074
|
+
process.env[name] = String(value);
|
|
4075
|
+
}
|
|
4076
|
+
return utils;
|
|
4077
|
+
},
|
|
4078
|
+
unstubAllGlobals() {
|
|
4079
|
+
_stubsGlobal.forEach((original, name) => {
|
|
4080
|
+
if (!original) {
|
|
4081
|
+
Reflect.deleteProperty(globalThis, name);
|
|
4082
|
+
} else {
|
|
4083
|
+
Object.defineProperty(globalThis, name, original);
|
|
4084
|
+
}
|
|
4085
|
+
});
|
|
4086
|
+
_stubsGlobal.clear();
|
|
4087
|
+
return utils;
|
|
4088
|
+
},
|
|
4089
|
+
unstubAllEnvs() {
|
|
4090
|
+
_stubsEnv.forEach((original, name) => {
|
|
4091
|
+
if (original === undefined) {
|
|
4092
|
+
delete process.env[name];
|
|
4093
|
+
} else {
|
|
4094
|
+
process.env[name] = original;
|
|
4095
|
+
}
|
|
4096
|
+
});
|
|
4097
|
+
_stubsEnv.clear();
|
|
4098
|
+
return utils;
|
|
4099
|
+
},
|
|
4100
|
+
resetModules() {
|
|
4101
|
+
resetModules(workerState.moduleCache);
|
|
4102
|
+
return utils;
|
|
4103
|
+
},
|
|
4104
|
+
async dynamicImportSettled() {
|
|
4105
|
+
return waitForImportsToResolve();
|
|
4106
|
+
},
|
|
4107
|
+
setConfig(config) {
|
|
4108
|
+
if (!_config) {
|
|
4109
|
+
_config = { ...workerState.config };
|
|
4110
|
+
}
|
|
4111
|
+
Object.assign(workerState.config, config);
|
|
4112
|
+
},
|
|
4113
|
+
resetConfig() {
|
|
4114
|
+
if (_config) {
|
|
4115
|
+
Object.assign(workerState.config, _config);
|
|
4116
|
+
}
|
|
4117
|
+
}
|
|
4118
|
+
};
|
|
4119
|
+
return utils;
|
|
4254
4120
|
}
|
|
4255
4121
|
const vitest = createVitest();
|
|
4256
4122
|
const vi = vitest;
|
|
4257
4123
|
function _mocker() {
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
get(_, name) {
|
|
4262
|
-
throw new Error(
|
|
4263
|
-
`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
|
|
4264
|
-
);
|
|
4265
|
-
}
|
|
4266
|
-
}
|
|
4267
|
-
);
|
|
4124
|
+
return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, { get(_, name) {
|
|
4125
|
+
throw new Error("Vitest mocker was not initialized in this environment. " + `vi.${String(name)}() is forbidden.`);
|
|
4126
|
+
} });
|
|
4268
4127
|
}
|
|
4269
4128
|
function getImporter(name) {
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4129
|
+
const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
|
|
4130
|
+
const stackArray = stackTrace.split("\n");
|
|
4131
|
+
const importerStackIndex = stackArray.findIndex((stack) => {
|
|
4132
|
+
return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
|
|
4133
|
+
});
|
|
4134
|
+
const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
|
|
4135
|
+
return stack?.file || "";
|
|
4277
4136
|
}
|
|
4278
4137
|
|
|
4279
4138
|
export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, inject as i, vi as v };
|