assistant-cloud 0.1.4 → 0.1.5
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/tests/setup.js +201 -465
- package/dist/tests/setup.js.map +1 -1
- package/package.json +5 -5
package/dist/tests/setup.js
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
// ../../node_modules/.pnpm/vitest@
|
|
2
|
-
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from "@vitest/expect.js";
|
|
1
|
+
// ../../node_modules/.pnpm/vitest@4.0.1_@types+debug@4.1.12_@types+node@24.9.1_@vitest+ui@4.0.1_jiti@2.6.1_jsdom@2_f7e90f889c75ea518901b8d845576f89/node_modules/vitest/dist/chunks/vi.BZvkKVkM.js
|
|
2
|
+
import { chai, equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from "@vitest/expect.js";
|
|
3
3
|
import { getCurrentTest } from "@vitest/runner.js";
|
|
4
4
|
import { getNames, getTestName } from "@vitest/runner/utils.js";
|
|
5
|
-
import * as chai$1 from "chai.js";
|
|
6
5
|
|
|
7
|
-
// ../../node_modules/.pnpm/vitest@
|
|
8
|
-
import { getSafeTimers } from "@vitest/utils.js";
|
|
6
|
+
// ../../node_modules/.pnpm/vitest@4.0.1_@types+debug@4.1.12_@types+node@24.9.1_@vitest+ui@4.0.1_jiti@2.6.1_jsdom@2_f7e90f889c75ea518901b8d845576f89/node_modules/vitest/dist/chunks/utils.CG9h5ccR.js
|
|
7
|
+
import { getSafeTimers } from "@vitest/utils/timers.js";
|
|
9
8
|
var NAME_WORKER_STATE = "__vitest_worker__";
|
|
10
9
|
function getWorkerState() {
|
|
11
10
|
const workerState = globalThis[NAME_WORKER_STATE];
|
|
12
|
-
if (!workerState)
|
|
13
|
-
const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- "vitest" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
|
|
14
|
-
throw new Error(errorMsg);
|
|
15
|
-
}
|
|
11
|
+
if (!workerState) throw new Error('Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- "vitest" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n');
|
|
16
12
|
return workerState;
|
|
17
13
|
}
|
|
18
|
-
function getCurrentEnvironment() {
|
|
19
|
-
const state = getWorkerState();
|
|
20
|
-
return state?.environment.name;
|
|
21
|
-
}
|
|
22
14
|
function isChildProcess() {
|
|
23
15
|
return typeof process !== "undefined" && !!process.send;
|
|
24
16
|
}
|
|
25
17
|
function resetModules(modules, resetMocks = false) {
|
|
26
18
|
const skipPaths = [
|
|
27
19
|
/\/vitest\/dist\//,
|
|
28
|
-
/\/vite-node\/dist\//,
|
|
29
20
|
/vitest-virtual-\w+\/dist/,
|
|
30
21
|
/@vitest\/dist/,
|
|
31
22
|
...!resetMocks ? [/^mock:/] : []
|
|
32
23
|
];
|
|
33
|
-
modules.forEach((
|
|
34
|
-
|
|
35
|
-
modules.invalidateModule(mod);
|
|
24
|
+
modules.idToModuleMap.forEach((node, path) => {
|
|
25
|
+
skipPaths.some((re) => re.test(path)) || (node.promise = void 0, node.exports = void 0, node.evaluated = false, node.importers.clear());
|
|
36
26
|
});
|
|
37
27
|
}
|
|
38
28
|
function waitNextTick() {
|
|
@@ -41,34 +31,24 @@ function waitNextTick() {
|
|
|
41
31
|
}
|
|
42
32
|
async function waitForImportsToResolve() {
|
|
43
33
|
await waitNextTick();
|
|
44
|
-
const state = getWorkerState();
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
for (const mod of state.moduleCache.values()) {
|
|
48
|
-
if (mod.promise && !mod.evaluated) promises.push(mod.promise);
|
|
49
|
-
if (mod.resolving) resolvingCount++;
|
|
50
|
-
}
|
|
51
|
-
if (!promises.length && !resolvingCount) return;
|
|
52
|
-
await Promise.allSettled(promises);
|
|
53
|
-
await waitForImportsToResolve();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.8.1_@vitest+ui@3.2.4_jiti@2.6.1_jsdom@2_a74286031a180d0adb1e0eb29ae4a9eb/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
|
|
57
|
-
import { getSafeTimers as getSafeTimers2, assertTypes, createSimpleStackTrace } from "@vitest/utils.js";
|
|
58
|
-
|
|
59
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.8.1_@vitest+ui@3.2.4_jiti@2.6.1_jsdom@2_a74286031a180d0adb1e0eb29ae4a9eb/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
|
|
60
|
-
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
61
|
-
function getDefaultExportFromCjs(x) {
|
|
62
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
34
|
+
const state = getWorkerState(), promises = [], resolvingCount = state.resolvingModules.size;
|
|
35
|
+
for (const [_, mod] of state.evaluatedModules.idToModuleMap) if (mod.promise && !mod.evaluated) promises.push(mod.promise);
|
|
36
|
+
!promises.length && !resolvingCount || (await Promise.allSettled(promises), await waitForImportsToResolve());
|
|
63
37
|
}
|
|
64
38
|
|
|
65
|
-
// ../../node_modules/.pnpm/vitest@
|
|
39
|
+
// ../../node_modules/.pnpm/vitest@4.0.1_@types+debug@4.1.12_@types+node@24.9.1_@vitest+ui@4.0.1_jiti@2.6.1_jsdom@2_f7e90f889c75ea518901b8d845576f89/node_modules/vitest/dist/chunks/vi.BZvkKVkM.js
|
|
40
|
+
import { getSafeTimers as getSafeTimers2 } from "@vitest/utils/timers.js";
|
|
66
41
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from "@vitest/snapshot.js";
|
|
67
42
|
import "@vitest/utils/error.js";
|
|
68
|
-
import {
|
|
43
|
+
import { assertTypes, createSimpleStackTrace } from "@vitest/utils/helpers.js";
|
|
44
|
+
import { fn, spyOn, restoreAllMocks, resetAllMocks, clearAllMocks, isMockFunction } from "@vitest/spy.js";
|
|
45
|
+
import "@vitest/utils/offset.js";
|
|
69
46
|
import { parseSingleStack } from "@vitest/utils/source-map.js";
|
|
70
47
|
|
|
71
|
-
// ../../node_modules/.pnpm/vitest@
|
|
48
|
+
// ../../node_modules/.pnpm/vitest@4.0.1_@types+debug@4.1.12_@types+node@24.9.1_@vitest+ui@4.0.1_jiti@2.6.1_jsdom@2_f7e90f889c75ea518901b8d845576f89/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
|
|
49
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
50
|
+
|
|
51
|
+
// ../../node_modules/.pnpm/vitest@4.0.1_@types+debug@4.1.12_@types+node@24.9.1_@vitest+ui@4.0.1_jiti@2.6.1_jsdom@2_f7e90f889c75ea518901b8d845576f89/node_modules/vitest/dist/chunks/date.-jtEtIeV.js
|
|
72
52
|
var RealDate = Date;
|
|
73
53
|
var now = null;
|
|
74
54
|
var MockDate = class _MockDate extends RealDate {
|
|
@@ -84,39 +64,29 @@ var MockDate = class _MockDate extends RealDate {
|
|
|
84
64
|
date = new RealDate(y);
|
|
85
65
|
break;
|
|
86
66
|
default:
|
|
87
|
-
d = typeof d === "undefined" ? 1 : d;
|
|
88
|
-
h = h || 0;
|
|
89
|
-
M = M || 0;
|
|
90
|
-
s = s || 0;
|
|
91
|
-
ms = ms || 0;
|
|
92
|
-
date = new RealDate(y, m, d, h, M, s, ms);
|
|
67
|
+
d = typeof d === "undefined" ? 1 : d, h = h || 0, M = M || 0, s = s || 0, ms = ms || 0, date = new RealDate(y, m, d, h, M, s, ms);
|
|
93
68
|
break;
|
|
94
69
|
}
|
|
95
|
-
Object.setPrototypeOf(date, _MockDate.prototype);
|
|
96
|
-
return date;
|
|
70
|
+
return Object.setPrototypeOf(date, _MockDate.prototype), date;
|
|
97
71
|
}
|
|
98
72
|
};
|
|
99
|
-
MockDate.UTC = RealDate.UTC
|
|
100
|
-
MockDate.now = function() {
|
|
73
|
+
MockDate.UTC = RealDate.UTC, MockDate.now = function() {
|
|
101
74
|
return new MockDate().valueOf();
|
|
102
|
-
}
|
|
103
|
-
MockDate.parse = function(dateString) {
|
|
75
|
+
}, MockDate.parse = function(dateString) {
|
|
104
76
|
return RealDate.parse(dateString);
|
|
105
|
-
}
|
|
106
|
-
MockDate.toString = function() {
|
|
77
|
+
}, MockDate.toString = function() {
|
|
107
78
|
return RealDate.toString();
|
|
108
79
|
};
|
|
109
80
|
function mockDate(date) {
|
|
110
81
|
const dateObj = new RealDate(date.valueOf());
|
|
111
82
|
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
112
|
-
globalThis.Date = MockDate;
|
|
113
|
-
now = dateObj.valueOf();
|
|
83
|
+
globalThis.Date = MockDate, now = dateObj.valueOf();
|
|
114
84
|
}
|
|
115
85
|
function resetDate() {
|
|
116
86
|
globalThis.Date = RealDate;
|
|
117
87
|
}
|
|
118
88
|
|
|
119
|
-
// ../../node_modules/.pnpm/vitest@
|
|
89
|
+
// ../../node_modules/.pnpm/vitest@4.0.1_@types+debug@4.1.12_@types+node@24.9.1_@vitest+ui@4.0.1_jiti@2.6.1_jsdom@2_f7e90f889c75ea518901b8d845576f89/node_modules/vitest/dist/chunks/vi.BZvkKVkM.js
|
|
120
90
|
var unsupported = [
|
|
121
91
|
"matchSnapshot",
|
|
122
92
|
"toMatchSnapshot",
|
|
@@ -129,58 +99,42 @@ var unsupported = [
|
|
|
129
99
|
"toThrow",
|
|
130
100
|
"toThrowError"
|
|
131
101
|
];
|
|
132
|
-
function createExpectPoll(
|
|
102
|
+
function createExpectPoll(expect) {
|
|
133
103
|
return function poll(fn2, options = {}) {
|
|
134
|
-
const
|
|
135
|
-
const defaults = state.config.expect?.poll ?? {};
|
|
136
|
-
const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
|
|
137
|
-
const assertion = expect2(null, message).withContext({ poll: true });
|
|
104
|
+
const defaults = getWorkerState().config.expect?.poll ?? {}, { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options, assertion = expect(null, message).withContext({ poll: true });
|
|
138
105
|
fn2 = fn2.bind(assertion);
|
|
139
|
-
const test2 = chai
|
|
106
|
+
const test2 = chai.util.flag(assertion, "vitest-test");
|
|
140
107
|
if (!test2) throw new Error("expect.poll() must be called inside a test");
|
|
141
108
|
const proxy = new Proxy(assertion, { get(target, key, receiver) {
|
|
142
109
|
const assertionFunction = Reflect.get(target, key, receiver);
|
|
143
|
-
if (typeof assertionFunction !== "function") return assertionFunction instanceof chai
|
|
110
|
+
if (typeof assertionFunction !== "function") return assertionFunction instanceof chai.Assertion ? proxy : assertionFunction;
|
|
144
111
|
if (key === "assert") return assertionFunction;
|
|
145
112
|
if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
|
|
146
113
|
return function(...args) {
|
|
147
|
-
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR")
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let timeoutId;
|
|
151
|
-
let lastError;
|
|
152
|
-
const { setTimeout, clearTimeout } = getSafeTimers2();
|
|
153
|
-
const check = async () => {
|
|
114
|
+
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR"), promise = () => new Promise((resolve, reject) => {
|
|
115
|
+
let intervalId, timeoutId, lastError;
|
|
116
|
+
const { setTimeout, clearTimeout } = getSafeTimers2(), check = async () => {
|
|
154
117
|
try {
|
|
155
|
-
chai
|
|
118
|
+
chai.util.flag(assertion, "_name", key);
|
|
156
119
|
const obj = await fn2();
|
|
157
|
-
chai
|
|
158
|
-
resolve(await assertionFunction.call(assertion, ...args));
|
|
159
|
-
clearTimeout(intervalId);
|
|
160
|
-
clearTimeout(timeoutId);
|
|
120
|
+
chai.util.flag(assertion, "object", obj), resolve(await assertionFunction.call(assertion, ...args)), clearTimeout(intervalId), clearTimeout(timeoutId);
|
|
161
121
|
} catch (err) {
|
|
162
|
-
lastError = err;
|
|
163
|
-
if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
|
|
122
|
+
if (lastError = err, !chai.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
|
|
164
123
|
}
|
|
165
124
|
};
|
|
166
125
|
timeoutId = setTimeout(() => {
|
|
167
|
-
clearTimeout(intervalId);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
reject(copyStackTrace$1(
|
|
126
|
+
clearTimeout(intervalId), chai.util.flag(assertion, "_isLastPollAttempt", true);
|
|
127
|
+
const rejectWithCause = (error) => {
|
|
128
|
+
if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
129
|
+
reject(copyStackTrace$1(error, STACK_TRACE_ERROR));
|
|
171
130
|
};
|
|
172
131
|
check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
|
|
173
|
-
}, timeout);
|
|
174
|
-
check();
|
|
132
|
+
}, timeout), check();
|
|
175
133
|
});
|
|
176
134
|
let awaited = false;
|
|
177
|
-
test2.onFinished ??= []
|
|
178
|
-
test2.onFinished.push(() => {
|
|
135
|
+
test2.onFinished ??= [], test2.onFinished.push(() => {
|
|
179
136
|
if (!awaited) {
|
|
180
|
-
const negated = chai
|
|
181
|
-
const name = chai$1.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)";
|
|
182
|
-
const assertionString = `expect.${name}.${negated}${String(key)}()`;
|
|
183
|
-
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:
|
|
137
|
+
const negated = chai.util.flag(assertion, "negate") ? "not." : "", assertionString = `expect.${chai.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`, error = /* @__PURE__ */ new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
|
|
184
138
|
|
|
185
139
|
await ${assertionString}
|
|
186
140
|
`);
|
|
@@ -190,8 +144,7 @@ await ${assertionString}
|
|
|
190
144
|
let resultPromise;
|
|
191
145
|
return {
|
|
192
146
|
then(onFulfilled, onRejected) {
|
|
193
|
-
awaited = true;
|
|
194
|
-
return (resultPromise ||= promise()).then(onFulfilled, onRejected);
|
|
147
|
+
return awaited = true, (resultPromise ||= promise()).then(onFulfilled, onRejected);
|
|
195
148
|
},
|
|
196
149
|
catch(onRejected) {
|
|
197
150
|
return (resultPromise ||= promise()).catch(onRejected);
|
|
@@ -210,115 +163,23 @@ function copyStackTrace$1(target, source) {
|
|
|
210
163
|
if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
|
|
211
164
|
return target;
|
|
212
165
|
}
|
|
213
|
-
function
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
var chaiSubset$1 = { exports: {} };
|
|
217
|
-
var chaiSubset = chaiSubset$1.exports;
|
|
218
|
-
var hasRequiredChaiSubset;
|
|
219
|
-
function requireChaiSubset() {
|
|
220
|
-
if (hasRequiredChaiSubset) return chaiSubset$1.exports;
|
|
221
|
-
hasRequiredChaiSubset = 1;
|
|
222
|
-
(function(module, exports) {
|
|
223
|
-
(function() {
|
|
224
|
-
(function(chaiSubset2) {
|
|
225
|
-
if (typeof commonjsRequire === "function" && true && true) {
|
|
226
|
-
return module.exports = chaiSubset2;
|
|
227
|
-
} else {
|
|
228
|
-
return chai.use(chaiSubset2);
|
|
229
|
-
}
|
|
230
|
-
})(function(chai3, utils) {
|
|
231
|
-
var Assertion2 = chai3.Assertion;
|
|
232
|
-
var assertionPrototype = Assertion2.prototype;
|
|
233
|
-
Assertion2.addMethod("containSubset", function(expected) {
|
|
234
|
-
var actual = utils.flag(this, "object");
|
|
235
|
-
var showDiff = chai3.config.showDiff;
|
|
236
|
-
assertionPrototype.assert.call(
|
|
237
|
-
this,
|
|
238
|
-
compare(expected, actual),
|
|
239
|
-
"expected #{act} to contain subset #{exp}",
|
|
240
|
-
"expected #{act} to not contain subset #{exp}",
|
|
241
|
-
expected,
|
|
242
|
-
actual,
|
|
243
|
-
showDiff
|
|
244
|
-
);
|
|
245
|
-
});
|
|
246
|
-
chai3.assert.containSubset = function(val, exp, msg) {
|
|
247
|
-
new chai3.Assertion(val, msg).to.be.containSubset(exp);
|
|
248
|
-
};
|
|
249
|
-
function compare(expected, actual) {
|
|
250
|
-
if (expected === actual) {
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
253
|
-
if (typeof actual !== typeof expected) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
if (typeof expected !== "object" || expected === null) {
|
|
257
|
-
return expected === actual;
|
|
258
|
-
}
|
|
259
|
-
if (!!expected && !actual) {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
if (Array.isArray(expected)) {
|
|
263
|
-
if (typeof actual.length !== "number") {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
var aa = Array.prototype.slice.call(actual);
|
|
267
|
-
return expected.every(function(exp) {
|
|
268
|
-
return aa.some(function(act) {
|
|
269
|
-
return compare(exp, act);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
if (expected instanceof Date) {
|
|
274
|
-
if (actual instanceof Date) {
|
|
275
|
-
return expected.getTime() === actual.getTime();
|
|
276
|
-
} else {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return Object.keys(expected).every(function(key) {
|
|
281
|
-
var eo = expected[key];
|
|
282
|
-
var ao = actual[key];
|
|
283
|
-
if (typeof eo === "object" && eo !== null && ao !== null) {
|
|
284
|
-
return compare(eo, ao);
|
|
285
|
-
}
|
|
286
|
-
if (typeof eo === "function") {
|
|
287
|
-
return eo(ao);
|
|
288
|
-
}
|
|
289
|
-
return ao === eo;
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}).call(chaiSubset);
|
|
294
|
-
})(chaiSubset$1);
|
|
295
|
-
return chaiSubset$1.exports;
|
|
296
|
-
}
|
|
297
|
-
var chaiSubsetExports = requireChaiSubset();
|
|
298
|
-
var Subset = /* @__PURE__ */ getDefaultExportFromCjs(chaiSubsetExports);
|
|
299
|
-
function createAssertionMessage(util2, assertion, hasArgs) {
|
|
300
|
-
const not = util2.flag(assertion, "negate") ? "not." : "";
|
|
301
|
-
const name = `${util2.flag(assertion, "_name")}(${"expected"})`;
|
|
302
|
-
const promiseName = util2.flag(assertion, "promise");
|
|
303
|
-
const promise = promiseName ? `.${promiseName}` : "";
|
|
304
|
-
return `expect(actual)${promise}.${not}${name}`;
|
|
166
|
+
function createAssertionMessage(util, assertion, hasArgs) {
|
|
167
|
+
const not = util.flag(assertion, "negate") ? "not." : "", name = `${util.flag(assertion, "_name")}(${"expected"})`, promiseName = util.flag(assertion, "promise");
|
|
168
|
+
return `expect(actual)${promiseName ? `.${promiseName}` : ""}.${not}${name}`;
|
|
305
169
|
}
|
|
306
170
|
function recordAsyncExpect(_test, promise, assertion, error) {
|
|
307
171
|
const test2 = _test;
|
|
308
172
|
if (test2 && promise instanceof Promise) {
|
|
309
|
-
promise = promise.finally(() => {
|
|
173
|
+
if (promise = promise.finally(() => {
|
|
310
174
|
if (!test2.promises) return;
|
|
311
175
|
const index = test2.promises.indexOf(promise);
|
|
312
176
|
if (index !== -1) test2.promises.splice(index, 1);
|
|
313
|
-
});
|
|
314
|
-
if (!test2.promises) test2.promises = [];
|
|
177
|
+
}), !test2.promises) test2.promises = [];
|
|
315
178
|
test2.promises.push(promise);
|
|
316
179
|
let resolved = false;
|
|
317
|
-
test2.onFinished ??= []
|
|
318
|
-
test2.onFinished.push(() => {
|
|
180
|
+
return test2.onFinished ??= [], test2.onFinished.push(() => {
|
|
319
181
|
if (!resolved) {
|
|
320
|
-
const
|
|
321
|
-
const stack = processor(error.stack);
|
|
182
|
+
const stack = (globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || ""))(error.stack);
|
|
322
183
|
console.warn([
|
|
323
184
|
`Promise returned by \`${assertion}\` was not awaited. `,
|
|
324
185
|
"Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
|
|
@@ -326,11 +187,9 @@ function recordAsyncExpect(_test, promise, assertion, error) {
|
|
|
326
187
|
stack
|
|
327
188
|
].join(""));
|
|
328
189
|
}
|
|
329
|
-
})
|
|
330
|
-
return {
|
|
190
|
+
}), {
|
|
331
191
|
then(onFulfilled, onRejected) {
|
|
332
|
-
resolved = true;
|
|
333
|
-
return promise.then(onFulfilled, onRejected);
|
|
192
|
+
return resolved = true, promise.then(onFulfilled, onRejected);
|
|
334
193
|
},
|
|
335
194
|
catch(onRejected) {
|
|
336
195
|
return promise.catch(onRejected);
|
|
@@ -376,15 +235,9 @@ var SnapshotPlugin = (chai3, utils) => {
|
|
|
376
235
|
return test2;
|
|
377
236
|
}
|
|
378
237
|
for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai3.Assertion.prototype, key, function(properties, message) {
|
|
379
|
-
utils.flag(this, "_name", key);
|
|
380
|
-
const
|
|
381
|
-
if (
|
|
382
|
-
const expected = utils.flag(this, "object");
|
|
383
|
-
const test2 = getTest(key, this);
|
|
384
|
-
if (typeof properties === "string" && typeof message === "undefined") {
|
|
385
|
-
message = properties;
|
|
386
|
-
properties = void 0;
|
|
387
|
-
}
|
|
238
|
+
if (utils.flag(this, "_name", key), utils.flag(this, "negate")) throw new Error(`${key} cannot be used with "not"`);
|
|
239
|
+
const expected = utils.flag(this, "object"), test2 = getTest(key, this);
|
|
240
|
+
if (typeof properties === "string" && typeof message === "undefined") message = properties, properties = void 0;
|
|
388
241
|
const errorMessage = utils.flag(this, "message");
|
|
389
242
|
getSnapshotClient().assert({
|
|
390
243
|
received: expected,
|
|
@@ -396,14 +249,8 @@ var SnapshotPlugin = (chai3, utils) => {
|
|
|
396
249
|
});
|
|
397
250
|
});
|
|
398
251
|
utils.addMethod(chai3.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
|
|
399
|
-
utils.flag(this, "_name", "toMatchFileSnapshot");
|
|
400
|
-
const
|
|
401
|
-
if (isNot) throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
|
402
|
-
const error = new Error("resolves");
|
|
403
|
-
const expected = utils.flag(this, "object");
|
|
404
|
-
const test2 = getTest("toMatchFileSnapshot", this);
|
|
405
|
-
const errorMessage = utils.flag(this, "message");
|
|
406
|
-
const promise = getSnapshotClient().assertRaw({
|
|
252
|
+
if (utils.flag(this, "_name", "toMatchFileSnapshot"), utils.flag(this, "negate")) throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
|
253
|
+
const error = /* @__PURE__ */ new Error("resolves"), expected = utils.flag(this, "object"), test2 = getTest("toMatchFileSnapshot", this), errorMessage = utils.flag(this, "message"), promise = getSnapshotClient().assertRaw({
|
|
407
254
|
received: expected,
|
|
408
255
|
message,
|
|
409
256
|
isInline: false,
|
|
@@ -412,21 +259,12 @@ var SnapshotPlugin = (chai3, utils) => {
|
|
|
412
259
|
...getTestNames(test2)
|
|
413
260
|
});
|
|
414
261
|
return recordAsyncExpect(test2, promise, createAssertionMessage(utils, this), error);
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
utils.flag(this, "_name", "toMatchInlineSnapshot");
|
|
418
|
-
const isNot = utils.flag(this, "negate");
|
|
419
|
-
if (isNot) throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
|
262
|
+
}), utils.addMethod(chai3.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
263
|
+
if (utils.flag(this, "_name", "toMatchInlineSnapshot"), utils.flag(this, "negate")) throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
|
420
264
|
const test2 = getTest("toMatchInlineSnapshot", this);
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const error = utils.flag(this, "error");
|
|
425
|
-
if (typeof properties === "string") {
|
|
426
|
-
message = inlineSnapshot;
|
|
427
|
-
inlineSnapshot = properties;
|
|
428
|
-
properties = void 0;
|
|
429
|
-
}
|
|
265
|
+
if (test2.each || test2.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
266
|
+
const expected = utils.flag(this, "object"), error = utils.flag(this, "error");
|
|
267
|
+
if (typeof properties === "string") message = inlineSnapshot, inlineSnapshot = properties, properties = void 0;
|
|
430
268
|
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
431
269
|
const errorMessage = utils.flag(this, "message");
|
|
432
270
|
getSnapshotClient().assert({
|
|
@@ -439,32 +277,20 @@ var SnapshotPlugin = (chai3, utils) => {
|
|
|
439
277
|
errorMessage,
|
|
440
278
|
...getTestNames(test2)
|
|
441
279
|
});
|
|
442
|
-
})
|
|
443
|
-
|
|
444
|
-
utils.flag(this, "
|
|
445
|
-
const isNot = utils.flag(this, "negate");
|
|
446
|
-
if (isNot) throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
|
|
447
|
-
const expected = utils.flag(this, "object");
|
|
448
|
-
const test2 = getTest("toThrowErrorMatchingSnapshot", this);
|
|
449
|
-
const promise = utils.flag(this, "promise");
|
|
450
|
-
const errorMessage = utils.flag(this, "message");
|
|
280
|
+
}), utils.addMethod(chai3.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
|
|
281
|
+
if (utils.flag(this, "_name", "toThrowErrorMatchingSnapshot"), utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
|
|
282
|
+
const expected = utils.flag(this, "object"), test2 = getTest("toThrowErrorMatchingSnapshot", this), promise = utils.flag(this, "promise"), errorMessage = utils.flag(this, "message");
|
|
451
283
|
getSnapshotClient().assert({
|
|
452
284
|
received: getError(expected, promise),
|
|
453
285
|
message,
|
|
454
286
|
errorMessage,
|
|
455
287
|
...getTestNames(test2)
|
|
456
288
|
});
|
|
457
|
-
})
|
|
458
|
-
|
|
459
|
-
const isNot = utils.flag(this, "negate");
|
|
460
|
-
if (isNot) throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
|
|
289
|
+
}), utils.addMethod(chai3.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
290
|
+
if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
|
|
461
291
|
const test2 = getTest("toThrowErrorMatchingInlineSnapshot", this);
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
const expected = utils.flag(this, "object");
|
|
465
|
-
const error = utils.flag(this, "error");
|
|
466
|
-
const promise = utils.flag(this, "promise");
|
|
467
|
-
const errorMessage = utils.flag(this, "message");
|
|
292
|
+
if (test2.each || test2.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
293
|
+
const expected = utils.flag(this, "object"), error = utils.flag(this, "error"), promise = utils.flag(this, "promise"), errorMessage = utils.flag(this, "message");
|
|
468
294
|
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
469
295
|
getSnapshotClient().assert({
|
|
470
296
|
received: getError(expected, promise),
|
|
@@ -475,28 +301,17 @@ var SnapshotPlugin = (chai3, utils) => {
|
|
|
475
301
|
errorMessage,
|
|
476
302
|
...getTestNames(test2)
|
|
477
303
|
});
|
|
478
|
-
});
|
|
479
|
-
utils.addMethod(chai3.expect, "addSnapshotSerializer", addSerializer);
|
|
304
|
+
}), utils.addMethod(chai3.expect, "addSnapshotSerializer", addSerializer);
|
|
480
305
|
};
|
|
481
|
-
chai
|
|
482
|
-
chai$1.use(JestChaiExpect);
|
|
483
|
-
chai$1.use(Subset);
|
|
484
|
-
chai$1.use(SnapshotPlugin);
|
|
485
|
-
chai$1.use(JestAsymmetricMatchers);
|
|
306
|
+
chai.use(JestExtend), chai.use(JestChaiExpect), chai.use(SnapshotPlugin), chai.use(JestAsymmetricMatchers);
|
|
486
307
|
function createExpect(test2) {
|
|
487
|
-
const
|
|
488
|
-
const { assertionCalls } = getState(
|
|
489
|
-
setState({ assertionCalls: assertionCalls + 1 },
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
else return assert3;
|
|
495
|
-
};
|
|
496
|
-
Object.assign(expect2, chai$1.expect);
|
|
497
|
-
Object.assign(expect2, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
498
|
-
expect2.getState = () => getState(expect2);
|
|
499
|
-
expect2.setState = (state) => setState(state, expect2);
|
|
308
|
+
const expect = ((value, message) => {
|
|
309
|
+
const { assertionCalls } = getState(expect);
|
|
310
|
+
setState({ assertionCalls: assertionCalls + 1 }, expect);
|
|
311
|
+
const assert2 = chai.expect(value, message), _test = test2 || getCurrentTest();
|
|
312
|
+
return _test ? assert2.withTest(_test) : assert2;
|
|
313
|
+
});
|
|
314
|
+
Object.assign(expect, chai.expect), Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]), expect.getState = () => getState(expect), expect.setState = (state) => setState(state, expect);
|
|
500
315
|
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
|
|
501
316
|
setState({
|
|
502
317
|
...globalState,
|
|
@@ -505,41 +320,32 @@ function createExpect(test2) {
|
|
|
505
320
|
isExpectingAssertionsError: null,
|
|
506
321
|
expectedAssertionsNumber: null,
|
|
507
322
|
expectedAssertionsNumberErrorGen: null,
|
|
508
|
-
environment: getCurrentEnvironment(),
|
|
509
323
|
get testPath() {
|
|
510
324
|
return getWorkerState().filepath;
|
|
511
325
|
},
|
|
512
326
|
currentTestName: test2 ? getTestName(test2) : globalState.currentTestName
|
|
513
|
-
},
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return expect2(...args).withContext({ soft: true });
|
|
518
|
-
};
|
|
519
|
-
expect2.poll = createExpectPoll(expect2);
|
|
520
|
-
expect2.unreachable = (message) => {
|
|
521
|
-
chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
|
|
327
|
+
}, expect), expect.assert = chai.assert, expect.extend = (matchers) => chai.expect.extend(expect, matchers), expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters), expect.soft = (...args) => {
|
|
328
|
+
return expect(...args).withContext({ soft: true });
|
|
329
|
+
}, expect.poll = createExpectPoll(expect), expect.unreachable = (message) => {
|
|
330
|
+
chai.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
|
|
522
331
|
};
|
|
523
332
|
function assertions(expected) {
|
|
524
|
-
const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${
|
|
333
|
+
const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
|
|
525
334
|
if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
|
|
526
|
-
|
|
335
|
+
expect.setState({
|
|
527
336
|
expectedAssertionsNumber: expected,
|
|
528
337
|
expectedAssertionsNumberErrorGen: errorGen
|
|
529
338
|
});
|
|
530
339
|
}
|
|
531
340
|
function hasAssertions() {
|
|
532
|
-
const error = new Error("expected any number of assertion, but got none");
|
|
341
|
+
const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
|
|
533
342
|
if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
|
|
534
|
-
|
|
343
|
+
expect.setState({
|
|
535
344
|
isExpectingAssertions: true,
|
|
536
345
|
isExpectingAssertionsError: error
|
|
537
346
|
});
|
|
538
347
|
}
|
|
539
|
-
chai
|
|
540
|
-
chai$1.util.addMethod(expect2, "hasAssertions", hasAssertions);
|
|
541
|
-
expect2.extend(customMatchers);
|
|
542
|
-
return expect2;
|
|
348
|
+
return chai.util.addMethod(expect, "assertions", assertions), chai.util.addMethod(expect, "hasAssertions", hasAssertions), expect.extend(customMatchers), expect;
|
|
543
349
|
}
|
|
544
350
|
var globalExpect = createExpect();
|
|
545
351
|
Object.defineProperty(globalThis, GLOBAL_EXPECT, {
|
|
@@ -547,6 +353,8 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
|
|
|
547
353
|
writable: true,
|
|
548
354
|
configurable: true
|
|
549
355
|
});
|
|
356
|
+
var assert = chai.assert;
|
|
357
|
+
var should = chai.should;
|
|
550
358
|
var fakeTimersSrc = {};
|
|
551
359
|
var global2;
|
|
552
360
|
var hasRequiredGlobal;
|
|
@@ -2371,20 +2179,16 @@ var FakeTimers = class {
|
|
|
2371
2179
|
// | _fakingTime | _fakingDate |
|
|
2372
2180
|
// +-------------+-------------+
|
|
2373
2181
|
// | false | falsy | initial
|
|
2374
|
-
// | false | truthy
|
|
2182
|
+
// | false | truthy | vi.setSystemTime called first (for mocking only Date without fake timers)
|
|
2375
2183
|
// | true | falsy | vi.useFakeTimers called first
|
|
2376
|
-
// | true | truthy
|
|
2184
|
+
// | true | truthy | unreachable
|
|
2377
2185
|
_fakingTime;
|
|
2378
2186
|
_fakingDate;
|
|
2379
2187
|
_fakeTimers;
|
|
2380
2188
|
_userConfig;
|
|
2381
2189
|
_now = RealDate.now;
|
|
2382
2190
|
constructor({ global: global3, config }) {
|
|
2383
|
-
this._userConfig = config;
|
|
2384
|
-
this._fakingDate = null;
|
|
2385
|
-
this._fakingTime = false;
|
|
2386
|
-
this._fakeTimers = fakeTimersSrcExports.withGlobal(global3);
|
|
2387
|
-
this._global = global3;
|
|
2191
|
+
this._userConfig = config, this._fakingDate = null, this._fakingTime = false, this._fakeTimers = fakeTimersSrcExports.withGlobal(global3), this._global = global3;
|
|
2388
2192
|
}
|
|
2389
2193
|
clearAllTimers() {
|
|
2390
2194
|
if (this._fakingTime) this._clock.reset();
|
|
@@ -2405,17 +2209,13 @@ var FakeTimers = class {
|
|
|
2405
2209
|
if (this._checkFakeTimers()) await this._clock.runToLastAsync();
|
|
2406
2210
|
}
|
|
2407
2211
|
advanceTimersToNextTimer(steps = 1) {
|
|
2408
|
-
if (this._checkFakeTimers())
|
|
2409
|
-
this._clock.next();
|
|
2410
|
-
this._clock.tick(0);
|
|
2411
|
-
if (this._clock.countTimers() === 0) break;
|
|
2212
|
+
if (this._checkFakeTimers()) {
|
|
2213
|
+
for (let i = steps; i > 0; i--) if (this._clock.next(), this._clock.tick(0), this._clock.countTimers() === 0) break;
|
|
2412
2214
|
}
|
|
2413
2215
|
}
|
|
2414
2216
|
async advanceTimersToNextTimerAsync(steps = 1) {
|
|
2415
|
-
if (this._checkFakeTimers())
|
|
2416
|
-
await this._clock.nextAsync();
|
|
2417
|
-
this._clock.tick(0);
|
|
2418
|
-
if (this._clock.countTimers() === 0) break;
|
|
2217
|
+
if (this._checkFakeTimers()) {
|
|
2218
|
+
for (let i = steps; i > 0; i--) if (await this._clock.nextAsync(), this._clock.tick(0), this._clock.countTimers() === 0) break;
|
|
2419
2219
|
}
|
|
2420
2220
|
}
|
|
2421
2221
|
advanceTimersByTime(msToRun) {
|
|
@@ -2432,43 +2232,32 @@ var FakeTimers = class {
|
|
|
2432
2232
|
this._clock.runMicrotasks();
|
|
2433
2233
|
}
|
|
2434
2234
|
useRealTimers() {
|
|
2435
|
-
if (this._fakingDate)
|
|
2436
|
-
|
|
2437
|
-
this._fakingDate = null;
|
|
2438
|
-
}
|
|
2439
|
-
if (this._fakingTime) {
|
|
2440
|
-
this._clock.uninstall();
|
|
2441
|
-
this._fakingTime = false;
|
|
2442
|
-
}
|
|
2235
|
+
if (this._fakingDate) resetDate(), this._fakingDate = null;
|
|
2236
|
+
if (this._fakingTime) this._clock.uninstall(), this._fakingTime = false;
|
|
2443
2237
|
}
|
|
2444
2238
|
useFakeTimers() {
|
|
2445
|
-
|
|
2446
|
-
if (
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
}
|
|
2239
|
+
const fakeDate = this._fakingDate || Date.now();
|
|
2240
|
+
if (this._fakingDate) resetDate(), this._fakingDate = null;
|
|
2241
|
+
if (this._fakingTime) this._clock.uninstall();
|
|
2242
|
+
const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick" && timer !== "queueMicrotask");
|
|
2243
|
+
if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) throw new Error("process.nextTick cannot be mocked inside child_process");
|
|
2244
|
+
this._clock = this._fakeTimers.install({
|
|
2245
|
+
now: fakeDate,
|
|
2246
|
+
...this._userConfig,
|
|
2247
|
+
toFake: this._userConfig?.toFake || toFake,
|
|
2248
|
+
ignoreMissingTimers: true
|
|
2249
|
+
}), this._fakingTime = true;
|
|
2457
2250
|
}
|
|
2458
2251
|
reset() {
|
|
2459
2252
|
if (this._checkFakeTimers()) {
|
|
2460
2253
|
const { now: now2 } = this._clock;
|
|
2461
|
-
this._clock.reset();
|
|
2462
|
-
this._clock.setSystemTime(now2);
|
|
2254
|
+
this._clock.reset(), this._clock.setSystemTime(now2);
|
|
2463
2255
|
}
|
|
2464
2256
|
}
|
|
2465
2257
|
setSystemTime(now2) {
|
|
2466
2258
|
const date = typeof now2 === "undefined" || now2 instanceof Date ? now2 : new Date(now2);
|
|
2467
2259
|
if (this._fakingTime) this._clock.setSystemTime(date);
|
|
2468
|
-
else
|
|
2469
|
-
this._fakingDate = date ?? new Date(this.getRealSystemTime());
|
|
2470
|
-
mockDate(this._fakingDate);
|
|
2471
|
-
}
|
|
2260
|
+
else this._fakingDate = date ?? new Date(this.getRealSystemTime()), mockDate(this._fakingDate);
|
|
2472
2261
|
}
|
|
2473
2262
|
getMockedSystemTime() {
|
|
2474
2263
|
return this._fakingTime ? new Date(this._clock.now) : this._fakingDate;
|
|
@@ -2477,8 +2266,7 @@ var FakeTimers = class {
|
|
|
2477
2266
|
return this._now();
|
|
2478
2267
|
}
|
|
2479
2268
|
getTimerCount() {
|
|
2480
|
-
|
|
2481
|
-
return 0;
|
|
2269
|
+
return this._checkFakeTimers() ? this._clock.countTimers() : 0;
|
|
2482
2270
|
}
|
|
2483
2271
|
configure(config) {
|
|
2484
2272
|
this._userConfig = config;
|
|
@@ -2487,7 +2275,7 @@ var FakeTimers = class {
|
|
|
2487
2275
|
return this._fakingTime;
|
|
2488
2276
|
}
|
|
2489
2277
|
_checkFakeTimers() {
|
|
2490
|
-
if (!this._fakingTime) throw new Error(
|
|
2278
|
+
if (!this._fakingTime) throw new Error("A function to advance timers was called but the timers APIs are not mocked. Call `vi.useFakeTimers()` in the test file first.");
|
|
2491
2279
|
return this._fakingTime;
|
|
2492
2280
|
}
|
|
2493
2281
|
};
|
|
@@ -2496,179 +2284,134 @@ function copyStackTrace(target, source) {
|
|
|
2496
2284
|
return target;
|
|
2497
2285
|
}
|
|
2498
2286
|
function waitFor(callback, options = {}) {
|
|
2499
|
-
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers2();
|
|
2500
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
2501
|
-
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
2287
|
+
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers2(), { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options, STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
2502
2288
|
return new Promise((resolve, reject) => {
|
|
2503
|
-
let lastError;
|
|
2504
|
-
let promiseStatus = "idle";
|
|
2505
|
-
let timeoutId;
|
|
2506
|
-
let intervalId;
|
|
2289
|
+
let lastError, promiseStatus = "idle", timeoutId, intervalId;
|
|
2507
2290
|
const onResolve = (result) => {
|
|
2508
2291
|
if (timeoutId) clearTimeout(timeoutId);
|
|
2509
2292
|
if (intervalId) clearInterval(intervalId);
|
|
2510
2293
|
resolve(result);
|
|
2511
|
-
}
|
|
2512
|
-
const handleTimeout = () => {
|
|
2294
|
+
}, handleTimeout = () => {
|
|
2513
2295
|
if (intervalId) clearInterval(intervalId);
|
|
2514
2296
|
let error = lastError;
|
|
2515
|
-
if (!error) error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
|
|
2297
|
+
if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
|
|
2516
2298
|
reject(error);
|
|
2517
|
-
}
|
|
2518
|
-
const checkCallback = () => {
|
|
2299
|
+
}, checkCallback = () => {
|
|
2519
2300
|
if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
|
|
2520
|
-
if (promiseStatus
|
|
2521
|
-
try {
|
|
2301
|
+
if (promiseStatus !== "pending") try {
|
|
2522
2302
|
const result = callback();
|
|
2523
2303
|
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
2524
2304
|
const thenable = result;
|
|
2525
|
-
promiseStatus = "pending"
|
|
2526
|
-
|
|
2527
|
-
promiseStatus = "resolved";
|
|
2528
|
-
onResolve(resolvedValue);
|
|
2305
|
+
promiseStatus = "pending", thenable.then((resolvedValue) => {
|
|
2306
|
+
promiseStatus = "resolved", onResolve(resolvedValue);
|
|
2529
2307
|
}, (rejectedValue) => {
|
|
2530
|
-
promiseStatus = "rejected";
|
|
2531
|
-
lastError = rejectedValue;
|
|
2308
|
+
promiseStatus = "rejected", lastError = rejectedValue;
|
|
2532
2309
|
});
|
|
2533
|
-
} else
|
|
2534
|
-
onResolve(result);
|
|
2535
|
-
return true;
|
|
2536
|
-
}
|
|
2310
|
+
} else return onResolve(result), true;
|
|
2537
2311
|
} catch (error) {
|
|
2538
2312
|
lastError = error;
|
|
2539
2313
|
}
|
|
2540
2314
|
};
|
|
2541
|
-
|
|
2542
|
-
timeoutId = setTimeout(handleTimeout, timeout);
|
|
2543
|
-
intervalId = setInterval(checkCallback, interval);
|
|
2315
|
+
checkCallback() !== true && (timeoutId = setTimeout(handleTimeout, timeout), intervalId = setInterval(checkCallback, interval));
|
|
2544
2316
|
});
|
|
2545
2317
|
}
|
|
2546
2318
|
function waitUntil(callback, options = {}) {
|
|
2547
|
-
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers2();
|
|
2548
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
2549
|
-
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
2319
|
+
const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers2(), { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options, STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
2550
2320
|
return new Promise((resolve, reject) => {
|
|
2551
|
-
let promiseStatus = "idle";
|
|
2552
|
-
let timeoutId;
|
|
2553
|
-
let intervalId;
|
|
2321
|
+
let promiseStatus = "idle", timeoutId, intervalId;
|
|
2554
2322
|
const onReject = (error) => {
|
|
2555
2323
|
if (intervalId) clearInterval(intervalId);
|
|
2556
|
-
if (!error) error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
|
|
2324
|
+
if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
|
|
2557
2325
|
reject(error);
|
|
2558
|
-
}
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
};
|
|
2566
|
-
const checkCallback = () => {
|
|
2326
|
+
}, onResolve = (result) => {
|
|
2327
|
+
if (result) {
|
|
2328
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2329
|
+
if (intervalId) clearInterval(intervalId);
|
|
2330
|
+
return resolve(result), true;
|
|
2331
|
+
}
|
|
2332
|
+
}, checkCallback = () => {
|
|
2567
2333
|
if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
|
|
2568
|
-
if (promiseStatus
|
|
2569
|
-
try {
|
|
2334
|
+
if (promiseStatus !== "pending") try {
|
|
2570
2335
|
const result = callback();
|
|
2571
2336
|
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
2572
2337
|
const thenable = result;
|
|
2573
|
-
promiseStatus = "pending"
|
|
2574
|
-
|
|
2575
|
-
promiseStatus = "resolved";
|
|
2576
|
-
onResolve(resolvedValue);
|
|
2338
|
+
promiseStatus = "pending", thenable.then((resolvedValue) => {
|
|
2339
|
+
promiseStatus = "resolved", onResolve(resolvedValue);
|
|
2577
2340
|
}, (rejectedValue) => {
|
|
2578
|
-
promiseStatus = "rejected";
|
|
2579
|
-
onReject(rejectedValue);
|
|
2341
|
+
promiseStatus = "rejected", onReject(rejectedValue);
|
|
2580
2342
|
});
|
|
2581
2343
|
} else return onResolve(result);
|
|
2582
2344
|
} catch (error) {
|
|
2583
2345
|
onReject(error);
|
|
2584
2346
|
}
|
|
2585
2347
|
};
|
|
2586
|
-
|
|
2587
|
-
timeoutId = setTimeout(onReject, timeout);
|
|
2588
|
-
intervalId = setInterval(checkCallback, interval);
|
|
2348
|
+
checkCallback() !== true && (timeoutId = setTimeout(onReject, timeout), intervalId = setInterval(checkCallback, interval));
|
|
2589
2349
|
});
|
|
2590
2350
|
}
|
|
2591
2351
|
function createVitest() {
|
|
2592
2352
|
let _config = null;
|
|
2593
|
-
const
|
|
2353
|
+
const state = () => getWorkerState();
|
|
2594
2354
|
let _timers;
|
|
2595
2355
|
const timers = () => _timers ||= new FakeTimers({
|
|
2596
2356
|
global: globalThis,
|
|
2597
|
-
config:
|
|
2598
|
-
})
|
|
2599
|
-
const _stubsGlobal = /* @__PURE__ */ new Map();
|
|
2600
|
-
const _stubsEnv = /* @__PURE__ */ new Map();
|
|
2601
|
-
const _envBooleans = [
|
|
2357
|
+
config: state().config.fakeTimers
|
|
2358
|
+
}), _stubsGlobal = /* @__PURE__ */ new Map(), _stubsEnv = /* @__PURE__ */ new Map(), _envBooleans = [
|
|
2602
2359
|
"PROD",
|
|
2603
2360
|
"DEV",
|
|
2604
2361
|
"SSR"
|
|
2605
|
-
]
|
|
2606
|
-
const utils = {
|
|
2362
|
+
], utils = {
|
|
2607
2363
|
useFakeTimers(config) {
|
|
2608
2364
|
if (isChildProcess()) {
|
|
2609
|
-
if (config?.toFake?.includes("nextTick") ||
|
|
2365
|
+
if (config?.toFake?.includes("nextTick") || state().config?.fakeTimers?.toFake?.includes("nextTick")) throw new Error('vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.');
|
|
2610
2366
|
}
|
|
2611
2367
|
if (config) timers().configure({
|
|
2612
|
-
...
|
|
2368
|
+
...state().config.fakeTimers,
|
|
2613
2369
|
...config
|
|
2614
2370
|
});
|
|
2615
|
-
else timers().configure(
|
|
2616
|
-
timers().useFakeTimers();
|
|
2617
|
-
return utils;
|
|
2371
|
+
else timers().configure(state().config.fakeTimers);
|
|
2372
|
+
return timers().useFakeTimers(), utils;
|
|
2618
2373
|
},
|
|
2619
2374
|
isFakeTimers() {
|
|
2620
2375
|
return timers().isFakeTimers();
|
|
2621
2376
|
},
|
|
2622
2377
|
useRealTimers() {
|
|
2623
|
-
timers().useRealTimers();
|
|
2624
|
-
return utils;
|
|
2378
|
+
return timers().useRealTimers(), utils;
|
|
2625
2379
|
},
|
|
2626
2380
|
runOnlyPendingTimers() {
|
|
2627
|
-
timers().runOnlyPendingTimers();
|
|
2628
|
-
return utils;
|
|
2381
|
+
return timers().runOnlyPendingTimers(), utils;
|
|
2629
2382
|
},
|
|
2630
2383
|
async runOnlyPendingTimersAsync() {
|
|
2631
|
-
await timers().runOnlyPendingTimersAsync();
|
|
2632
|
-
return utils;
|
|
2384
|
+
return await timers().runOnlyPendingTimersAsync(), utils;
|
|
2633
2385
|
},
|
|
2634
2386
|
runAllTimers() {
|
|
2635
|
-
timers().runAllTimers();
|
|
2636
|
-
return utils;
|
|
2387
|
+
return timers().runAllTimers(), utils;
|
|
2637
2388
|
},
|
|
2638
2389
|
async runAllTimersAsync() {
|
|
2639
|
-
await timers().runAllTimersAsync();
|
|
2640
|
-
return utils;
|
|
2390
|
+
return await timers().runAllTimersAsync(), utils;
|
|
2641
2391
|
},
|
|
2642
2392
|
runAllTicks() {
|
|
2643
|
-
timers().runAllTicks();
|
|
2644
|
-
return utils;
|
|
2393
|
+
return timers().runAllTicks(), utils;
|
|
2645
2394
|
},
|
|
2646
2395
|
advanceTimersByTime(ms) {
|
|
2647
|
-
timers().advanceTimersByTime(ms);
|
|
2648
|
-
return utils;
|
|
2396
|
+
return timers().advanceTimersByTime(ms), utils;
|
|
2649
2397
|
},
|
|
2650
2398
|
async advanceTimersByTimeAsync(ms) {
|
|
2651
|
-
await timers().advanceTimersByTimeAsync(ms);
|
|
2652
|
-
return utils;
|
|
2399
|
+
return await timers().advanceTimersByTimeAsync(ms), utils;
|
|
2653
2400
|
},
|
|
2654
2401
|
advanceTimersToNextTimer() {
|
|
2655
|
-
timers().advanceTimersToNextTimer();
|
|
2656
|
-
return utils;
|
|
2402
|
+
return timers().advanceTimersToNextTimer(), utils;
|
|
2657
2403
|
},
|
|
2658
2404
|
async advanceTimersToNextTimerAsync() {
|
|
2659
|
-
await timers().advanceTimersToNextTimerAsync();
|
|
2660
|
-
return utils;
|
|
2405
|
+
return await timers().advanceTimersToNextTimerAsync(), utils;
|
|
2661
2406
|
},
|
|
2662
2407
|
advanceTimersToNextFrame() {
|
|
2663
|
-
timers().advanceTimersToNextFrame();
|
|
2664
|
-
return utils;
|
|
2408
|
+
return timers().advanceTimersToNextFrame(), utils;
|
|
2665
2409
|
},
|
|
2666
2410
|
getTimerCount() {
|
|
2667
2411
|
return timers().getTimerCount();
|
|
2668
2412
|
},
|
|
2669
2413
|
setSystemTime(time) {
|
|
2670
|
-
timers().setSystemTime(time);
|
|
2671
|
-
return utils;
|
|
2414
|
+
return timers().setSystemTime(time), utils;
|
|
2672
2415
|
},
|
|
2673
2416
|
getMockedSystemTime() {
|
|
2674
2417
|
return timers().getMockedSystemTime();
|
|
@@ -2677,16 +2420,14 @@ function createVitest() {
|
|
|
2677
2420
|
return timers().getRealSystemTime();
|
|
2678
2421
|
},
|
|
2679
2422
|
clearAllTimers() {
|
|
2680
|
-
timers().clearAllTimers();
|
|
2681
|
-
return utils;
|
|
2423
|
+
return timers().clearAllTimers(), utils;
|
|
2682
2424
|
},
|
|
2683
2425
|
spyOn,
|
|
2684
2426
|
fn,
|
|
2685
2427
|
waitFor,
|
|
2686
2428
|
waitUntil,
|
|
2687
2429
|
hoisted(factory) {
|
|
2688
|
-
assertTypes(factory, '"vi.hoisted" factory', ["function"]);
|
|
2689
|
-
return factory();
|
|
2430
|
+
return assertTypes(factory, '"vi.hoisted" factory', ["function"]), factory();
|
|
2690
2431
|
},
|
|
2691
2432
|
mock(path, factory) {
|
|
2692
2433
|
if (typeof path !== "string") throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
|
|
@@ -2704,16 +2445,19 @@ function createVitest() {
|
|
|
2704
2445
|
},
|
|
2705
2446
|
doUnmock(path) {
|
|
2706
2447
|
if (typeof path !== "string") throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
|
|
2707
|
-
|
|
2448
|
+
const importer = getImporter("doUnmock");
|
|
2449
|
+
_mocker().queueUnmock(path, importer);
|
|
2708
2450
|
},
|
|
2709
2451
|
async importActual(path) {
|
|
2710
|
-
|
|
2452
|
+
const importer = getImporter("importActual");
|
|
2453
|
+
return _mocker().importActual(path, importer, _mocker().getMockContext().callstack);
|
|
2711
2454
|
},
|
|
2712
2455
|
async importMock(path) {
|
|
2713
|
-
|
|
2456
|
+
const importer = getImporter("importMock");
|
|
2457
|
+
return _mocker().importMock(path, importer);
|
|
2714
2458
|
},
|
|
2715
|
-
mockObject(value) {
|
|
2716
|
-
return _mocker().mockObject({ value }).value;
|
|
2459
|
+
mockObject(value, options) {
|
|
2460
|
+
return _mocker().mockObject({ value }, void 0, options?.spy ? "autospy" : "automock").value;
|
|
2717
2461
|
},
|
|
2718
2462
|
mocked(item, _options = {}) {
|
|
2719
2463
|
return item;
|
|
@@ -2722,63 +2466,56 @@ function createVitest() {
|
|
|
2722
2466
|
return isMockFunction(fn2);
|
|
2723
2467
|
},
|
|
2724
2468
|
clearAllMocks() {
|
|
2725
|
-
|
|
2726
|
-
return utils;
|
|
2469
|
+
return clearAllMocks(), utils;
|
|
2727
2470
|
},
|
|
2728
2471
|
resetAllMocks() {
|
|
2729
|
-
|
|
2730
|
-
return utils;
|
|
2472
|
+
return resetAllMocks(), utils;
|
|
2731
2473
|
},
|
|
2732
2474
|
restoreAllMocks() {
|
|
2733
|
-
|
|
2734
|
-
return utils;
|
|
2475
|
+
return restoreAllMocks(), utils;
|
|
2735
2476
|
},
|
|
2736
2477
|
stubGlobal(name, value) {
|
|
2737
2478
|
if (!_stubsGlobal.has(name)) _stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
|
|
2738
|
-
Object.defineProperty(globalThis, name, {
|
|
2479
|
+
return Object.defineProperty(globalThis, name, {
|
|
2739
2480
|
value,
|
|
2740
2481
|
writable: true,
|
|
2741
2482
|
configurable: true,
|
|
2742
2483
|
enumerable: true
|
|
2743
|
-
});
|
|
2744
|
-
return utils;
|
|
2484
|
+
}), utils;
|
|
2745
2485
|
},
|
|
2746
2486
|
stubEnv(name, value) {
|
|
2747
|
-
|
|
2748
|
-
if (
|
|
2749
|
-
|
|
2750
|
-
else
|
|
2487
|
+
const env = state().metaEnv;
|
|
2488
|
+
if (!_stubsEnv.has(name)) _stubsEnv.set(name, env[name]);
|
|
2489
|
+
if (_envBooleans.includes(name)) env[name] = value ? "1" : "";
|
|
2490
|
+
else if (value === void 0) delete env[name];
|
|
2491
|
+
else env[name] = String(value);
|
|
2751
2492
|
return utils;
|
|
2752
2493
|
},
|
|
2753
2494
|
unstubAllGlobals() {
|
|
2754
|
-
_stubsGlobal.forEach((original, name) => {
|
|
2495
|
+
return _stubsGlobal.forEach((original, name) => {
|
|
2755
2496
|
if (!original) Reflect.deleteProperty(globalThis, name);
|
|
2756
2497
|
else Object.defineProperty(globalThis, name, original);
|
|
2757
|
-
});
|
|
2758
|
-
_stubsGlobal.clear();
|
|
2759
|
-
return utils;
|
|
2498
|
+
}), _stubsGlobal.clear(), utils;
|
|
2760
2499
|
},
|
|
2761
2500
|
unstubAllEnvs() {
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
_stubsEnv.clear();
|
|
2767
|
-
return utils;
|
|
2501
|
+
const env = state().metaEnv;
|
|
2502
|
+
return _stubsEnv.forEach((original, name) => {
|
|
2503
|
+
if (original === void 0) delete env[name];
|
|
2504
|
+
else env[name] = original;
|
|
2505
|
+
}), _stubsEnv.clear(), utils;
|
|
2768
2506
|
},
|
|
2769
2507
|
resetModules() {
|
|
2770
|
-
resetModules(
|
|
2771
|
-
return utils;
|
|
2508
|
+
return resetModules(state().evaluatedModules), utils;
|
|
2772
2509
|
},
|
|
2773
2510
|
async dynamicImportSettled() {
|
|
2774
2511
|
return waitForImportsToResolve();
|
|
2775
2512
|
},
|
|
2776
2513
|
setConfig(config) {
|
|
2777
|
-
if (!_config) _config = { ...
|
|
2778
|
-
Object.assign(
|
|
2514
|
+
if (!_config) _config = { ...state().config };
|
|
2515
|
+
Object.assign(state().config, config);
|
|
2779
2516
|
},
|
|
2780
2517
|
resetConfig() {
|
|
2781
|
-
if (_config) Object.assign(
|
|
2518
|
+
if (_config) Object.assign(state().config, _config);
|
|
2782
2519
|
}
|
|
2783
2520
|
};
|
|
2784
2521
|
return utils;
|
|
@@ -2791,27 +2528,26 @@ function _mocker() {
|
|
|
2791
2528
|
} });
|
|
2792
2529
|
}
|
|
2793
2530
|
function getImporter(name) {
|
|
2794
|
-
const
|
|
2795
|
-
|
|
2796
|
-
const importerStackIndex = stackArray.findIndex((stack2) => {
|
|
2797
|
-
return stack2.includes(` at Object.${name}`) || stack2.includes(`${name}@`);
|
|
2531
|
+
const stackArray = createSimpleStackTrace({ stackTraceLimit: 5 }).split("\n"), importerStackIndex = stackArray.findLastIndex((stack) => {
|
|
2532
|
+
return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
|
|
2798
2533
|
});
|
|
2799
|
-
|
|
2800
|
-
return stack?.file || "";
|
|
2534
|
+
return parseSingleStack(stackArray[importerStackIndex + 1])?.file || "";
|
|
2801
2535
|
}
|
|
2802
2536
|
|
|
2803
|
-
// ../../node_modules/.pnpm/vitest@
|
|
2537
|
+
// ../../node_modules/.pnpm/vitest@4.0.1_@types+debug@4.1.12_@types+node@24.9.1_@vitest+ui@4.0.1_jiti@2.6.1_jsdom@2_f7e90f889c75ea518901b8d845576f89/node_modules/vitest/dist/index.js
|
|
2804
2538
|
import { expectTypeOf } from "expect-type.js";
|
|
2805
2539
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from "@vitest/runner.js";
|
|
2806
|
-
import
|
|
2807
|
-
import { assert as assert2, should } from "chai.js";
|
|
2808
|
-
import "@vitest/expect.js";
|
|
2540
|
+
import { chai as chai2 } from "@vitest/expect.js";
|
|
2809
2541
|
import "@vitest/runner/utils.js";
|
|
2810
|
-
import "@vitest/utils.js";
|
|
2542
|
+
import "@vitest/utils/timers.js";
|
|
2811
2543
|
import "@vitest/snapshot.js";
|
|
2812
2544
|
import "@vitest/utils/error.js";
|
|
2545
|
+
import "@vitest/utils/helpers.js";
|
|
2813
2546
|
import "@vitest/spy.js";
|
|
2547
|
+
import "@vitest/utils/offset.js";
|
|
2814
2548
|
import "@vitest/utils/source-map.js";
|
|
2549
|
+
import "pathe.js";
|
|
2550
|
+
import "vite/module-runner.js";
|
|
2815
2551
|
|
|
2816
2552
|
// src/tests/setup.ts
|
|
2817
2553
|
var OriginalDate = global.Date;
|