@assistant-ui/react 0.8.15 → 0.8.17
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/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.js +2 -2
- package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.js.map +1 -1
- package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.mjs +1 -1
- package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.mjs.map +1 -1
- package/dist/runtimes/edge/{EdgeChatAdapter.d.ts → EdgeModelAdapter.d.ts} +4 -4
- package/dist/runtimes/edge/EdgeModelAdapter.d.ts.map +1 -0
- package/dist/runtimes/edge/{EdgeChatAdapter.js → EdgeModelAdapter.js} +8 -8
- package/dist/runtimes/edge/EdgeModelAdapter.js.map +1 -0
- package/dist/runtimes/edge/{EdgeChatAdapter.mjs → EdgeModelAdapter.mjs} +4 -4
- package/dist/runtimes/edge/EdgeModelAdapter.mjs.map +1 -0
- package/dist/runtimes/edge/converters/toLanguageModelMessages.d.ts.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.js +1 -0
- package/dist/runtimes/edge/converters/toLanguageModelMessages.js.map +1 -1
- package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs +1 -0
- package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs.map +1 -1
- package/dist/runtimes/edge/index.d.ts +2 -1
- package/dist/runtimes/edge/index.d.ts.map +1 -1
- package/dist/runtimes/edge/index.js +5 -2
- package/dist/runtimes/edge/index.js.map +1 -1
- package/dist/runtimes/edge/index.mjs +4 -2
- package/dist/runtimes/edge/index.mjs.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.d.ts +2 -1
- package/dist/runtimes/edge/streams/toolResultStream.d.ts.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.js +60 -21
- package/dist/runtimes/edge/streams/toolResultStream.js.map +1 -1
- package/dist/runtimes/edge/streams/toolResultStream.mjs +58 -20
- package/dist/runtimes/edge/streams/toolResultStream.mjs.map +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.d.ts +2 -2
- package/dist/runtimes/edge/useEdgeRuntime.d.ts.map +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.js +2 -2
- package/dist/runtimes/edge/useEdgeRuntime.js.map +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.mjs +2 -2
- package/dist/runtimes/edge/useEdgeRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js +3 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs +3 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.mjs.map +1 -1
- package/dist/runtimes/utils/MessageRepository.d.ts +112 -0
- package/dist/runtimes/utils/MessageRepository.d.ts.map +1 -1
- package/dist/runtimes/utils/MessageRepository.js +103 -1
- package/dist/runtimes/utils/MessageRepository.js.map +1 -1
- package/dist/runtimes/utils/MessageRepository.mjs +103 -1
- package/dist/runtimes/utils/MessageRepository.mjs.map +1 -1
- package/dist/tests/MessageRepository.test.d.ts +2 -0
- package/dist/tests/MessageRepository.test.d.ts.map +1 -0
- package/dist/tests/setup.d.ts +2 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +2656 -0
- package/dist/tests/setup.js.map +1 -0
- package/dist/tests/setup.mjs +2632 -0
- package/dist/tests/setup.mjs.map +1 -0
- package/dist/types/AssistantTypes.d.ts +1 -1
- package/dist/types/AssistantTypes.d.ts.map +1 -1
- package/dist/types/AssistantTypes.js.map +1 -1
- package/package.json +12 -6
- package/src/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.ts +1 -1
- package/src/runtimes/edge/{EdgeChatAdapter.ts → EdgeModelAdapter.ts} +3 -3
- package/src/runtimes/edge/converters/toLanguageModelMessages.ts +3 -1
- package/src/runtimes/edge/index.ts +3 -1
- package/src/runtimes/edge/streams/toolResultStream.ts +76 -27
- package/src/runtimes/edge/useEdgeRuntime.ts +3 -3
- package/src/runtimes/remote-thread-list/EMPTY_THREAD_CORE.tsx +4 -0
- package/src/runtimes/utils/MessageRepository.tsx +142 -1
- package/src/tests/MessageRepository.test.ts +690 -0
- package/src/tests/setup.ts +11 -0
- package/src/types/AssistantTypes.ts +1 -1
- package/dist/runtimes/edge/EdgeChatAdapter.d.ts.map +0 -1
- package/dist/runtimes/edge/EdgeChatAdapter.js.map +0 -1
- package/dist/runtimes/edge/EdgeChatAdapter.mjs.map +0 -1
@@ -0,0 +1,2656 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
+
for (let key of __getOwnPropNames(from))
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
+
}
|
14
|
+
return to;
|
15
|
+
};
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
+
mod
|
23
|
+
));
|
24
|
+
|
25
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/index.js
|
26
|
+
var import_runner4 = require("@vitest/runner.js");
|
27
|
+
|
28
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/benchmark.yGkUTKnC.js
|
29
|
+
var import_runner = require("@vitest/runner.js");
|
30
|
+
var import_utils3 = require("@vitest/runner/utils.js");
|
31
|
+
var import_utils4 = require("@vitest/utils.js");
|
32
|
+
|
33
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/index.SMVOaj7F.js
|
34
|
+
var import_pathe = require("pathe.js");
|
35
|
+
var import_utils = require("@vitest/runner/utils.js");
|
36
|
+
var import_utils2 = require("@vitest/utils.js");
|
37
|
+
|
38
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/global.CkGT_TMy.js
|
39
|
+
function getWorkerState() {
|
40
|
+
const workerState = globalThis.__vitest_worker__;
|
41
|
+
if (!workerState) {
|
42
|
+
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- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
|
43
|
+
throw new Error(errorMsg);
|
44
|
+
}
|
45
|
+
return workerState;
|
46
|
+
}
|
47
|
+
function getCurrentEnvironment() {
|
48
|
+
const state = getWorkerState();
|
49
|
+
return state == null ? void 0 : state.environment.name;
|
50
|
+
}
|
51
|
+
|
52
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/index.SMVOaj7F.js
|
53
|
+
function getRunMode() {
|
54
|
+
return getWorkerState().config.mode;
|
55
|
+
}
|
56
|
+
function isRunningInBenchmark() {
|
57
|
+
return getRunMode() === "benchmark";
|
58
|
+
}
|
59
|
+
|
60
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/benchmark.yGkUTKnC.js
|
61
|
+
var benchFns = /* @__PURE__ */ new WeakMap();
|
62
|
+
var benchOptsMap = /* @__PURE__ */ new WeakMap();
|
63
|
+
var bench = createBenchmark(
|
64
|
+
function(name, fn2 = import_utils4.noop, options = {}) {
|
65
|
+
if (!isRunningInBenchmark())
|
66
|
+
throw new Error("`bench()` is only available in benchmark mode.");
|
67
|
+
const task = (0, import_runner.getCurrentSuite)().task(formatName(name), {
|
68
|
+
...this,
|
69
|
+
meta: {
|
70
|
+
benchmark: true
|
71
|
+
}
|
72
|
+
});
|
73
|
+
benchFns.set(task, fn2);
|
74
|
+
benchOptsMap.set(task, options);
|
75
|
+
}
|
76
|
+
);
|
77
|
+
function createBenchmark(fn2) {
|
78
|
+
const benchmark = (0, import_utils3.createChainable)(
|
79
|
+
["skip", "only", "todo"],
|
80
|
+
fn2
|
81
|
+
);
|
82
|
+
benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
|
83
|
+
benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
|
84
|
+
return benchmark;
|
85
|
+
}
|
86
|
+
function formatName(name) {
|
87
|
+
return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);
|
88
|
+
}
|
89
|
+
|
90
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/run-once.Olz_Zkd8.js
|
91
|
+
var filesCount = /* @__PURE__ */ new Map();
|
92
|
+
var cache = /* @__PURE__ */ new Map();
|
93
|
+
function runOnce(fn2, key) {
|
94
|
+
const filepath = getWorkerState().filepath || "__unknown_files__";
|
95
|
+
if (!key) {
|
96
|
+
filesCount.set(filepath, (filesCount.get(filepath) || 0) + 1);
|
97
|
+
key = String(filesCount.get(filepath));
|
98
|
+
}
|
99
|
+
const id = `${filepath}:${key}`;
|
100
|
+
if (!cache.has(id))
|
101
|
+
cache.set(id, fn2());
|
102
|
+
return cache.get(id);
|
103
|
+
}
|
104
|
+
function isFirstRun() {
|
105
|
+
let firstRun = false;
|
106
|
+
runOnce(() => {
|
107
|
+
firstRun = true;
|
108
|
+
}, "__vitest_first_run__");
|
109
|
+
return firstRun;
|
110
|
+
}
|
111
|
+
|
112
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/vi.YFlodzP_.js
|
113
|
+
var chai$1 = __toESM(require("chai.js"), 1);
|
114
|
+
|
115
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/_commonjsHelpers.jjO7Zipk.js
|
116
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
117
|
+
function getDefaultExportFromCjs(x) {
|
118
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
119
|
+
}
|
120
|
+
|
121
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/vi.YFlodzP_.js
|
122
|
+
var import_expect = require("@vitest/expect.js");
|
123
|
+
var import_snapshot = require("@vitest/snapshot.js");
|
124
|
+
var import_utils8 = require("@vitest/runner/utils.js");
|
125
|
+
var import_error = require("@vitest/utils/error.js");
|
126
|
+
var import_runner2 = require("@vitest/runner.js");
|
127
|
+
|
128
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/tasks.IknbGB2n.js
|
129
|
+
var import_utils5 = require("@vitest/runner/utils.js");
|
130
|
+
var import_utils6 = require("@vitest/utils.js");
|
131
|
+
function getFullName(task, separator = " > ") {
|
132
|
+
return (0, import_utils5.getNames)(task).join(separator);
|
133
|
+
}
|
134
|
+
|
135
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/vi.YFlodzP_.js
|
136
|
+
var import_utils9 = require("@vitest/utils.js");
|
137
|
+
var import_source_map = require("@vitest/utils/source-map.js");
|
138
|
+
|
139
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/base.5NT-gWu5.js
|
140
|
+
var import_utils7 = require("@vitest/utils.js");
|
141
|
+
function isChildProcess() {
|
142
|
+
return typeof process !== "undefined" && !!process.send;
|
143
|
+
}
|
144
|
+
|
145
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/date.Ns1pGd_X.js
|
146
|
+
var RealDate = Date;
|
147
|
+
var now = null;
|
148
|
+
var MockDate = class _MockDate extends RealDate {
|
149
|
+
constructor(y, m, d, h, M, s, ms) {
|
150
|
+
super();
|
151
|
+
let date;
|
152
|
+
switch (arguments.length) {
|
153
|
+
case 0:
|
154
|
+
if (now !== null)
|
155
|
+
date = new RealDate(now.valueOf());
|
156
|
+
else
|
157
|
+
date = new RealDate();
|
158
|
+
break;
|
159
|
+
case 1:
|
160
|
+
date = new RealDate(y);
|
161
|
+
break;
|
162
|
+
default:
|
163
|
+
d = typeof d === "undefined" ? 1 : d;
|
164
|
+
h = h || 0;
|
165
|
+
M = M || 0;
|
166
|
+
s = s || 0;
|
167
|
+
ms = ms || 0;
|
168
|
+
date = new RealDate(y, m, d, h, M, s, ms);
|
169
|
+
break;
|
170
|
+
}
|
171
|
+
Object.setPrototypeOf(date, _MockDate.prototype);
|
172
|
+
return date;
|
173
|
+
}
|
174
|
+
};
|
175
|
+
MockDate.UTC = RealDate.UTC;
|
176
|
+
MockDate.now = function() {
|
177
|
+
return new MockDate().valueOf();
|
178
|
+
};
|
179
|
+
MockDate.parse = function(dateString) {
|
180
|
+
return RealDate.parse(dateString);
|
181
|
+
};
|
182
|
+
MockDate.toString = function() {
|
183
|
+
return RealDate.toString();
|
184
|
+
};
|
185
|
+
function mockDate(date) {
|
186
|
+
const dateObj = new RealDate(date.valueOf());
|
187
|
+
if (Number.isNaN(dateObj.getTime()))
|
188
|
+
throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
189
|
+
globalThis.Date = MockDate;
|
190
|
+
now = dateObj.valueOf();
|
191
|
+
}
|
192
|
+
function resetDate() {
|
193
|
+
globalThis.Date = RealDate;
|
194
|
+
}
|
195
|
+
|
196
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/vi.YFlodzP_.js
|
197
|
+
var import_spy = require("@vitest/spy.js");
|
198
|
+
function resetModules(modules, resetMocks = false) {
|
199
|
+
const skipPaths = [
|
200
|
+
// Vitest
|
201
|
+
/\/vitest\/dist\//,
|
202
|
+
/\/vite-node\/dist\//,
|
203
|
+
// yarn's .store folder
|
204
|
+
/vitest-virtual-\w+\/dist/,
|
205
|
+
// cnpm
|
206
|
+
/@vitest\/dist/,
|
207
|
+
// don't clear mocks
|
208
|
+
...!resetMocks ? [/^mock:/] : []
|
209
|
+
];
|
210
|
+
modules.forEach((mod, path) => {
|
211
|
+
if (skipPaths.some((re) => re.test(path)))
|
212
|
+
return;
|
213
|
+
modules.invalidateModule(mod);
|
214
|
+
});
|
215
|
+
}
|
216
|
+
function waitNextTick() {
|
217
|
+
const { setTimeout } = (0, import_utils9.getSafeTimers)();
|
218
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
219
|
+
}
|
220
|
+
async function waitForImportsToResolve() {
|
221
|
+
await waitNextTick();
|
222
|
+
const state = getWorkerState();
|
223
|
+
const promises = [];
|
224
|
+
let resolvingCount = 0;
|
225
|
+
for (const mod of state.moduleCache.values()) {
|
226
|
+
if (mod.promise && !mod.evaluated)
|
227
|
+
promises.push(mod.promise);
|
228
|
+
if (mod.resolving)
|
229
|
+
resolvingCount++;
|
230
|
+
}
|
231
|
+
if (!promises.length && !resolvingCount)
|
232
|
+
return;
|
233
|
+
await Promise.allSettled(promises);
|
234
|
+
await waitForImportsToResolve();
|
235
|
+
}
|
236
|
+
function commonjsRequire(path) {
|
237
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
238
|
+
}
|
239
|
+
var chaiSubset = { exports: {} };
|
240
|
+
(function(module2, exports2) {
|
241
|
+
(function() {
|
242
|
+
(function(chaiSubset2) {
|
243
|
+
if (typeof commonjsRequire === "function" && true && true) {
|
244
|
+
return module2.exports = chaiSubset2;
|
245
|
+
} else {
|
246
|
+
return chai.use(chaiSubset2);
|
247
|
+
}
|
248
|
+
})(function(chai4, utils) {
|
249
|
+
var Assertion = chai4.Assertion;
|
250
|
+
var assertionPrototype = Assertion.prototype;
|
251
|
+
Assertion.addMethod("containSubset", function(expected) {
|
252
|
+
var actual = utils.flag(this, "object");
|
253
|
+
var showDiff = chai4.config.showDiff;
|
254
|
+
assertionPrototype.assert.call(
|
255
|
+
this,
|
256
|
+
compare(expected, actual),
|
257
|
+
"expected #{act} to contain subset #{exp}",
|
258
|
+
"expected #{act} to not contain subset #{exp}",
|
259
|
+
expected,
|
260
|
+
actual,
|
261
|
+
showDiff
|
262
|
+
);
|
263
|
+
});
|
264
|
+
chai4.assert.containSubset = function(val, exp, msg) {
|
265
|
+
new chai4.Assertion(val, msg).to.be.containSubset(exp);
|
266
|
+
};
|
267
|
+
function compare(expected, actual) {
|
268
|
+
if (expected === actual) {
|
269
|
+
return true;
|
270
|
+
}
|
271
|
+
if (typeof actual !== typeof expected) {
|
272
|
+
return false;
|
273
|
+
}
|
274
|
+
if (typeof expected !== "object" || expected === null) {
|
275
|
+
return expected === actual;
|
276
|
+
}
|
277
|
+
if (!!expected && !actual) {
|
278
|
+
return false;
|
279
|
+
}
|
280
|
+
if (Array.isArray(expected)) {
|
281
|
+
if (typeof actual.length !== "number") {
|
282
|
+
return false;
|
283
|
+
}
|
284
|
+
var aa = Array.prototype.slice.call(actual);
|
285
|
+
return expected.every(function(exp) {
|
286
|
+
return aa.some(function(act) {
|
287
|
+
return compare(exp, act);
|
288
|
+
});
|
289
|
+
});
|
290
|
+
}
|
291
|
+
if (expected instanceof Date) {
|
292
|
+
if (actual instanceof Date) {
|
293
|
+
return expected.getTime() === actual.getTime();
|
294
|
+
} else {
|
295
|
+
return false;
|
296
|
+
}
|
297
|
+
}
|
298
|
+
return Object.keys(expected).every(function(key) {
|
299
|
+
var eo = expected[key];
|
300
|
+
var ao = actual[key];
|
301
|
+
if (typeof eo === "object" && eo !== null && ao !== null) {
|
302
|
+
return compare(eo, ao);
|
303
|
+
}
|
304
|
+
if (typeof eo === "function") {
|
305
|
+
return eo(ao);
|
306
|
+
}
|
307
|
+
return ao === eo;
|
308
|
+
});
|
309
|
+
}
|
310
|
+
});
|
311
|
+
}).call(commonjsGlobal);
|
312
|
+
})(chaiSubset);
|
313
|
+
var chaiSubsetExports = chaiSubset.exports;
|
314
|
+
var Subset = /* @__PURE__ */ getDefaultExportFromCjs(chaiSubsetExports);
|
315
|
+
var MATCHERS_OBJECT = Symbol.for("matchers-object");
|
316
|
+
var JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
|
317
|
+
var GLOBAL_EXPECT = Symbol.for("expect-global");
|
318
|
+
var ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
|
319
|
+
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
320
|
+
const globalState = /* @__PURE__ */ new WeakMap();
|
321
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
322
|
+
const customEqualityTesters = [];
|
323
|
+
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
|
324
|
+
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
325
|
+
get: () => globalState
|
326
|
+
});
|
327
|
+
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
|
328
|
+
configurable: true,
|
329
|
+
get: () => ({
|
330
|
+
state: globalState.get(globalThis[GLOBAL_EXPECT]),
|
331
|
+
matchers,
|
332
|
+
customEqualityTesters
|
333
|
+
})
|
334
|
+
});
|
335
|
+
Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
|
336
|
+
get: () => assymetricMatchers
|
337
|
+
});
|
338
|
+
}
|
339
|
+
function recordAsyncExpect(test3, promise) {
|
340
|
+
if (test3 && promise instanceof Promise) {
|
341
|
+
promise = promise.finally(() => {
|
342
|
+
const index = test3.promises.indexOf(promise);
|
343
|
+
if (index !== -1)
|
344
|
+
test3.promises.splice(index, 1);
|
345
|
+
});
|
346
|
+
if (!test3.promises)
|
347
|
+
test3.promises = [];
|
348
|
+
test3.promises.push(promise);
|
349
|
+
}
|
350
|
+
return promise;
|
351
|
+
}
|
352
|
+
var _client;
|
353
|
+
function getSnapshotClient() {
|
354
|
+
if (!_client) {
|
355
|
+
_client = new import_snapshot.SnapshotClient({
|
356
|
+
isEqual: (received, expected) => {
|
357
|
+
return (0, import_expect.equals)(received, expected, [import_expect.iterableEquality, import_expect.subsetEquality]);
|
358
|
+
}
|
359
|
+
});
|
360
|
+
}
|
361
|
+
return _client;
|
362
|
+
}
|
363
|
+
function getError(expected, promise) {
|
364
|
+
if (typeof expected !== "function") {
|
365
|
+
if (!promise)
|
366
|
+
throw new Error(`expected must be a function, received ${typeof expected}`);
|
367
|
+
return expected;
|
368
|
+
}
|
369
|
+
try {
|
370
|
+
expected();
|
371
|
+
} catch (e) {
|
372
|
+
return e;
|
373
|
+
}
|
374
|
+
throw new Error("snapshot function didn't throw");
|
375
|
+
}
|
376
|
+
var SnapshotPlugin = (chai4, utils) => {
|
377
|
+
const getTestNames = (test3) => {
|
378
|
+
var _a;
|
379
|
+
if (!test3)
|
380
|
+
return {};
|
381
|
+
return {
|
382
|
+
filepath: (_a = test3.file) == null ? void 0 : _a.filepath,
|
383
|
+
name: (0, import_utils8.getNames)(test3).slice(1).join(" > ")
|
384
|
+
};
|
385
|
+
};
|
386
|
+
for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
|
387
|
+
utils.addMethod(
|
388
|
+
chai4.Assertion.prototype,
|
389
|
+
key,
|
390
|
+
function(properties, message) {
|
391
|
+
const isNot = utils.flag(this, "negate");
|
392
|
+
if (isNot)
|
393
|
+
throw new Error(`${key} cannot be used with "not"`);
|
394
|
+
const expected = utils.flag(this, "object");
|
395
|
+
const test3 = utils.flag(this, "vitest-test");
|
396
|
+
if (typeof properties === "string" && typeof message === "undefined") {
|
397
|
+
message = properties;
|
398
|
+
properties = void 0;
|
399
|
+
}
|
400
|
+
const errorMessage = utils.flag(this, "message");
|
401
|
+
getSnapshotClient().assert({
|
402
|
+
received: expected,
|
403
|
+
message,
|
404
|
+
isInline: false,
|
405
|
+
properties,
|
406
|
+
errorMessage,
|
407
|
+
...getTestNames(test3)
|
408
|
+
});
|
409
|
+
}
|
410
|
+
);
|
411
|
+
}
|
412
|
+
utils.addMethod(
|
413
|
+
chai4.Assertion.prototype,
|
414
|
+
"toMatchFileSnapshot",
|
415
|
+
function(file, message) {
|
416
|
+
const isNot = utils.flag(this, "negate");
|
417
|
+
if (isNot)
|
418
|
+
throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
419
|
+
const expected = utils.flag(this, "object");
|
420
|
+
const test3 = utils.flag(this, "vitest-test");
|
421
|
+
const errorMessage = utils.flag(this, "message");
|
422
|
+
const promise = getSnapshotClient().assertRaw({
|
423
|
+
received: expected,
|
424
|
+
message,
|
425
|
+
isInline: false,
|
426
|
+
rawSnapshot: {
|
427
|
+
file
|
428
|
+
},
|
429
|
+
errorMessage,
|
430
|
+
...getTestNames(test3)
|
431
|
+
});
|
432
|
+
return recordAsyncExpect(test3, promise);
|
433
|
+
}
|
434
|
+
);
|
435
|
+
utils.addMethod(
|
436
|
+
chai4.Assertion.prototype,
|
437
|
+
"toMatchInlineSnapshot",
|
438
|
+
function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
439
|
+
var _a;
|
440
|
+
const isNot = utils.flag(this, "negate");
|
441
|
+
if (isNot)
|
442
|
+
throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
443
|
+
const test3 = utils.flag(this, "vitest-test");
|
444
|
+
const isInsideEach = test3 && (test3.each || ((_a = test3.suite) == null ? void 0 : _a.each));
|
445
|
+
if (isInsideEach)
|
446
|
+
throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
447
|
+
const expected = utils.flag(this, "object");
|
448
|
+
const error = utils.flag(this, "error");
|
449
|
+
if (typeof properties === "string") {
|
450
|
+
message = inlineSnapshot;
|
451
|
+
inlineSnapshot = properties;
|
452
|
+
properties = void 0;
|
453
|
+
}
|
454
|
+
if (inlineSnapshot)
|
455
|
+
inlineSnapshot = (0, import_snapshot.stripSnapshotIndentation)(inlineSnapshot);
|
456
|
+
const errorMessage = utils.flag(this, "message");
|
457
|
+
getSnapshotClient().assert({
|
458
|
+
received: expected,
|
459
|
+
message,
|
460
|
+
isInline: true,
|
461
|
+
properties,
|
462
|
+
inlineSnapshot,
|
463
|
+
error,
|
464
|
+
errorMessage,
|
465
|
+
...getTestNames(test3)
|
466
|
+
});
|
467
|
+
}
|
468
|
+
);
|
469
|
+
utils.addMethod(
|
470
|
+
chai4.Assertion.prototype,
|
471
|
+
"toThrowErrorMatchingSnapshot",
|
472
|
+
function(message) {
|
473
|
+
const isNot = utils.flag(this, "negate");
|
474
|
+
if (isNot)
|
475
|
+
throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
|
476
|
+
const expected = utils.flag(this, "object");
|
477
|
+
const test3 = utils.flag(this, "vitest-test");
|
478
|
+
const promise = utils.flag(this, "promise");
|
479
|
+
const errorMessage = utils.flag(this, "message");
|
480
|
+
getSnapshotClient().assert({
|
481
|
+
received: getError(expected, promise),
|
482
|
+
message,
|
483
|
+
errorMessage,
|
484
|
+
...getTestNames(test3)
|
485
|
+
});
|
486
|
+
}
|
487
|
+
);
|
488
|
+
utils.addMethod(
|
489
|
+
chai4.Assertion.prototype,
|
490
|
+
"toThrowErrorMatchingInlineSnapshot",
|
491
|
+
function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
492
|
+
var _a;
|
493
|
+
const isNot = utils.flag(this, "negate");
|
494
|
+
if (isNot)
|
495
|
+
throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
|
496
|
+
const test3 = utils.flag(this, "vitest-test");
|
497
|
+
const isInsideEach = test3 && (test3.each || ((_a = test3.suite) == null ? void 0 : _a.each));
|
498
|
+
if (isInsideEach)
|
499
|
+
throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
500
|
+
const expected = utils.flag(this, "object");
|
501
|
+
const error = utils.flag(this, "error");
|
502
|
+
const promise = utils.flag(this, "promise");
|
503
|
+
const errorMessage = utils.flag(this, "message");
|
504
|
+
if (inlineSnapshot)
|
505
|
+
inlineSnapshot = (0, import_snapshot.stripSnapshotIndentation)(inlineSnapshot);
|
506
|
+
getSnapshotClient().assert({
|
507
|
+
received: getError(expected, promise),
|
508
|
+
message,
|
509
|
+
inlineSnapshot,
|
510
|
+
isInline: true,
|
511
|
+
error,
|
512
|
+
errorMessage,
|
513
|
+
...getTestNames(test3)
|
514
|
+
});
|
515
|
+
}
|
516
|
+
);
|
517
|
+
utils.addMethod(
|
518
|
+
chai4.expect,
|
519
|
+
"addSnapshotSerializer",
|
520
|
+
import_snapshot.addSerializer
|
521
|
+
);
|
522
|
+
};
|
523
|
+
chai$1.use(import_expect.JestExtend);
|
524
|
+
chai$1.use(import_expect.JestChaiExpect);
|
525
|
+
chai$1.use(Subset);
|
526
|
+
chai$1.use(SnapshotPlugin);
|
527
|
+
chai$1.use(import_expect.JestAsymmetricMatchers);
|
528
|
+
function createExpect(test3) {
|
529
|
+
var _a;
|
530
|
+
const expect2 = (value, message) => {
|
531
|
+
const { assertionCalls } = (0, import_expect.getState)(expect2);
|
532
|
+
(0, import_expect.setState)({ assertionCalls: assertionCalls + 1, soft: false }, expect2);
|
533
|
+
const assert22 = chai$1.expect(value, message);
|
534
|
+
const _test = test3 || (0, import_runner2.getCurrentTest)();
|
535
|
+
if (_test)
|
536
|
+
return assert22.withTest(_test);
|
537
|
+
else
|
538
|
+
return assert22;
|
539
|
+
};
|
540
|
+
Object.assign(expect2, chai$1.expect);
|
541
|
+
Object.assign(expect2, globalThis[import_expect.ASYMMETRIC_MATCHERS_OBJECT]);
|
542
|
+
expect2.getState = () => (0, import_expect.getState)(expect2);
|
543
|
+
expect2.setState = (state) => (0, import_expect.setState)(state, expect2);
|
544
|
+
const globalState = (0, import_expect.getState)(globalThis[import_expect.GLOBAL_EXPECT]) || {};
|
545
|
+
(0, import_expect.setState)({
|
546
|
+
// this should also add "snapshotState" that is added conditionally
|
547
|
+
...globalState,
|
548
|
+
assertionCalls: 0,
|
549
|
+
isExpectingAssertions: false,
|
550
|
+
isExpectingAssertionsError: null,
|
551
|
+
expectedAssertionsNumber: null,
|
552
|
+
expectedAssertionsNumberErrorGen: null,
|
553
|
+
environment: getCurrentEnvironment(),
|
554
|
+
testPath: test3 ? (_a = test3.suite.file) == null ? void 0 : _a.filepath : globalState.testPath,
|
555
|
+
currentTestName: test3 ? getFullName(test3) : globalState.currentTestName
|
556
|
+
}, expect2);
|
557
|
+
expect2.extend = (matchers) => chai$1.expect.extend(expect2, matchers);
|
558
|
+
expect2.addEqualityTesters = (customTesters) => (0, import_expect.addCustomEqualityTesters)(customTesters);
|
559
|
+
expect2.soft = (...args) => {
|
560
|
+
const assert22 = expect2(...args);
|
561
|
+
expect2.setState({
|
562
|
+
soft: true
|
563
|
+
});
|
564
|
+
return assert22;
|
565
|
+
};
|
566
|
+
expect2.unreachable = (message) => {
|
567
|
+
chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
|
568
|
+
};
|
569
|
+
function assertions(expected) {
|
570
|
+
const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect2.getState().assertionCalls}`);
|
571
|
+
if (Error.captureStackTrace)
|
572
|
+
Error.captureStackTrace(errorGen(), assertions);
|
573
|
+
expect2.setState({
|
574
|
+
expectedAssertionsNumber: expected,
|
575
|
+
expectedAssertionsNumberErrorGen: errorGen
|
576
|
+
});
|
577
|
+
}
|
578
|
+
function hasAssertions() {
|
579
|
+
const error = new Error("expected any number of assertion, but got none");
|
580
|
+
if (Error.captureStackTrace)
|
581
|
+
Error.captureStackTrace(error, hasAssertions);
|
582
|
+
expect2.setState({
|
583
|
+
isExpectingAssertions: true,
|
584
|
+
isExpectingAssertionsError: error
|
585
|
+
});
|
586
|
+
}
|
587
|
+
chai$1.util.addMethod(expect2, "assertions", assertions);
|
588
|
+
chai$1.util.addMethod(expect2, "hasAssertions", hasAssertions);
|
589
|
+
return expect2;
|
590
|
+
}
|
591
|
+
var globalExpect = createExpect();
|
592
|
+
Object.defineProperty(globalThis, import_expect.GLOBAL_EXPECT, {
|
593
|
+
value: globalExpect,
|
594
|
+
writable: true,
|
595
|
+
configurable: true
|
596
|
+
});
|
597
|
+
var globalObject$1;
|
598
|
+
if (typeof commonjsGlobal !== "undefined") {
|
599
|
+
globalObject$1 = commonjsGlobal;
|
600
|
+
} else if (typeof window !== "undefined") {
|
601
|
+
globalObject$1 = window;
|
602
|
+
} else {
|
603
|
+
globalObject$1 = self;
|
604
|
+
}
|
605
|
+
var global2 = globalObject$1;
|
606
|
+
var throwsOnProto$1;
|
607
|
+
try {
|
608
|
+
const object2 = {};
|
609
|
+
object2.__proto__;
|
610
|
+
throwsOnProto$1 = false;
|
611
|
+
} catch (_) {
|
612
|
+
throwsOnProto$1 = true;
|
613
|
+
}
|
614
|
+
var throwsOnProto_1 = throwsOnProto$1;
|
615
|
+
var call = Function.call;
|
616
|
+
var throwsOnProto = throwsOnProto_1;
|
617
|
+
var disallowedProperties = [
|
618
|
+
// ignore size because it throws from Map
|
619
|
+
"size",
|
620
|
+
"caller",
|
621
|
+
"callee",
|
622
|
+
"arguments"
|
623
|
+
];
|
624
|
+
if (throwsOnProto) {
|
625
|
+
disallowedProperties.push("__proto__");
|
626
|
+
}
|
627
|
+
var copyPrototypeMethods = function copyPrototypeMethods2(prototype) {
|
628
|
+
return Object.getOwnPropertyNames(prototype).reduce(
|
629
|
+
function(result, name) {
|
630
|
+
if (disallowedProperties.includes(name)) {
|
631
|
+
return result;
|
632
|
+
}
|
633
|
+
if (typeof prototype[name] !== "function") {
|
634
|
+
return result;
|
635
|
+
}
|
636
|
+
result[name] = call.bind(prototype[name]);
|
637
|
+
return result;
|
638
|
+
},
|
639
|
+
/* @__PURE__ */ Object.create(null)
|
640
|
+
);
|
641
|
+
};
|
642
|
+
var copyPrototype$5 = copyPrototypeMethods;
|
643
|
+
var array = copyPrototype$5(Array.prototype);
|
644
|
+
var every$1 = array.every;
|
645
|
+
function hasCallsLeft(callMap, spy) {
|
646
|
+
if (callMap[spy.id] === void 0) {
|
647
|
+
callMap[spy.id] = 0;
|
648
|
+
}
|
649
|
+
return callMap[spy.id] < spy.callCount;
|
650
|
+
}
|
651
|
+
function checkAdjacentCalls(callMap, spy, index, spies) {
|
652
|
+
var calledBeforeNext = true;
|
653
|
+
if (index !== spies.length - 1) {
|
654
|
+
calledBeforeNext = spy.calledBefore(spies[index + 1]);
|
655
|
+
}
|
656
|
+
if (hasCallsLeft(callMap, spy) && calledBeforeNext) {
|
657
|
+
callMap[spy.id] += 1;
|
658
|
+
return true;
|
659
|
+
}
|
660
|
+
return false;
|
661
|
+
}
|
662
|
+
function calledInOrder(spies) {
|
663
|
+
var callMap = {};
|
664
|
+
var _spies = arguments.length > 1 ? arguments : spies;
|
665
|
+
return every$1(_spies, checkAdjacentCalls.bind(null, callMap));
|
666
|
+
}
|
667
|
+
var calledInOrder_1 = calledInOrder;
|
668
|
+
var functionName$1 = function functionName(func) {
|
669
|
+
if (!func) {
|
670
|
+
return "";
|
671
|
+
}
|
672
|
+
try {
|
673
|
+
return func.displayName || func.name || // Use function decomposition as a last resort to get function
|
674
|
+
// name. Does not rely on function decomposition to work - if it
|
675
|
+
// doesn't debugging will be slightly less informative
|
676
|
+
// (i.e. toString will say 'spy' rather than 'myFunc').
|
677
|
+
(String(func).match(/function ([^\s(]+)/) || [])[1];
|
678
|
+
} catch (e) {
|
679
|
+
return "";
|
680
|
+
}
|
681
|
+
};
|
682
|
+
var functionName2 = functionName$1;
|
683
|
+
function className(value) {
|
684
|
+
return value.constructor && value.constructor.name || // The next branch is for IE11 support only:
|
685
|
+
// Because the name property is not set on the prototype
|
686
|
+
// of the Function object, we finally try to grab the
|
687
|
+
// name from its definition. This will never be reached
|
688
|
+
// in node, so we are not able to test this properly.
|
689
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
|
690
|
+
typeof value.constructor === "function" && /* istanbul ignore next */
|
691
|
+
functionName2(value.constructor) || null;
|
692
|
+
}
|
693
|
+
var className_1 = className;
|
694
|
+
var deprecated = {};
|
695
|
+
(function(exports2) {
|
696
|
+
exports2.wrap = function(func, msg) {
|
697
|
+
var wrapped = function() {
|
698
|
+
exports2.printWarning(msg);
|
699
|
+
return func.apply(this, arguments);
|
700
|
+
};
|
701
|
+
if (func.prototype) {
|
702
|
+
wrapped.prototype = func.prototype;
|
703
|
+
}
|
704
|
+
return wrapped;
|
705
|
+
};
|
706
|
+
exports2.defaultMsg = function(packageName, funcName) {
|
707
|
+
return `${packageName}.${funcName} is deprecated and will be removed from the public API in a future version of ${packageName}.`;
|
708
|
+
};
|
709
|
+
exports2.printWarning = function(msg) {
|
710
|
+
if (typeof process === "object" && process.emitWarning) {
|
711
|
+
process.emitWarning(msg);
|
712
|
+
} else if (console.info) {
|
713
|
+
console.info(msg);
|
714
|
+
} else {
|
715
|
+
console.log(msg);
|
716
|
+
}
|
717
|
+
};
|
718
|
+
})(deprecated);
|
719
|
+
var every = function every2(obj, fn2) {
|
720
|
+
var pass = true;
|
721
|
+
try {
|
722
|
+
obj.forEach(function() {
|
723
|
+
if (!fn2.apply(this, arguments)) {
|
724
|
+
throw new Error();
|
725
|
+
}
|
726
|
+
});
|
727
|
+
} catch (e) {
|
728
|
+
pass = false;
|
729
|
+
}
|
730
|
+
return pass;
|
731
|
+
};
|
732
|
+
var sort = array.sort;
|
733
|
+
var slice = array.slice;
|
734
|
+
function comparator(a, b) {
|
735
|
+
var aCall = a.getCall(0);
|
736
|
+
var bCall = b.getCall(0);
|
737
|
+
var aId = aCall && aCall.callId || -1;
|
738
|
+
var bId = bCall && bCall.callId || -1;
|
739
|
+
return aId < bId ? -1 : 1;
|
740
|
+
}
|
741
|
+
function orderByFirstCall(spies) {
|
742
|
+
return sort(slice(spies), comparator);
|
743
|
+
}
|
744
|
+
var orderByFirstCall_1 = orderByFirstCall;
|
745
|
+
var copyPrototype$4 = copyPrototypeMethods;
|
746
|
+
var _function = copyPrototype$4(Function.prototype);
|
747
|
+
var copyPrototype$3 = copyPrototypeMethods;
|
748
|
+
var map = copyPrototype$3(Map.prototype);
|
749
|
+
var copyPrototype$2 = copyPrototypeMethods;
|
750
|
+
var object = copyPrototype$2(Object.prototype);
|
751
|
+
var copyPrototype$1 = copyPrototypeMethods;
|
752
|
+
var set = copyPrototype$1(Set.prototype);
|
753
|
+
var copyPrototype = copyPrototypeMethods;
|
754
|
+
var string = copyPrototype(String.prototype);
|
755
|
+
var prototypes = {
|
756
|
+
array,
|
757
|
+
function: _function,
|
758
|
+
map,
|
759
|
+
object,
|
760
|
+
set,
|
761
|
+
string
|
762
|
+
};
|
763
|
+
var typeDetect = { exports: {} };
|
764
|
+
(function(module2, exports2) {
|
765
|
+
(function(global3, factory) {
|
766
|
+
module2.exports = factory();
|
767
|
+
})(commonjsGlobal, function() {
|
768
|
+
var promiseExists = typeof Promise === "function";
|
769
|
+
var globalObject2 = typeof self === "object" ? self : commonjsGlobal;
|
770
|
+
var symbolExists = typeof Symbol !== "undefined";
|
771
|
+
var mapExists = typeof Map !== "undefined";
|
772
|
+
var setExists = typeof Set !== "undefined";
|
773
|
+
var weakMapExists = typeof WeakMap !== "undefined";
|
774
|
+
var weakSetExists = typeof WeakSet !== "undefined";
|
775
|
+
var dataViewExists = typeof DataView !== "undefined";
|
776
|
+
var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== "undefined";
|
777
|
+
var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== "undefined";
|
778
|
+
var setEntriesExists = setExists && typeof Set.prototype.entries === "function";
|
779
|
+
var mapEntriesExists = mapExists && typeof Map.prototype.entries === "function";
|
780
|
+
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf((/* @__PURE__ */ new Set()).entries());
|
781
|
+
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf((/* @__PURE__ */ new Map()).entries());
|
782
|
+
var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === "function";
|
783
|
+
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
|
784
|
+
var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === "function";
|
785
|
+
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(""[Symbol.iterator]());
|
786
|
+
var toStringLeftSliceLength = 8;
|
787
|
+
var toStringRightSliceLength = -1;
|
788
|
+
function typeDetect2(obj) {
|
789
|
+
var typeofObj = typeof obj;
|
790
|
+
if (typeofObj !== "object") {
|
791
|
+
return typeofObj;
|
792
|
+
}
|
793
|
+
if (obj === null) {
|
794
|
+
return "null";
|
795
|
+
}
|
796
|
+
if (obj === globalObject2) {
|
797
|
+
return "global";
|
798
|
+
}
|
799
|
+
if (Array.isArray(obj) && (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))) {
|
800
|
+
return "Array";
|
801
|
+
}
|
802
|
+
if (typeof window === "object" && window !== null) {
|
803
|
+
if (typeof window.location === "object" && obj === window.location) {
|
804
|
+
return "Location";
|
805
|
+
}
|
806
|
+
if (typeof window.document === "object" && obj === window.document) {
|
807
|
+
return "Document";
|
808
|
+
}
|
809
|
+
if (typeof window.navigator === "object") {
|
810
|
+
if (typeof window.navigator.mimeTypes === "object" && obj === window.navigator.mimeTypes) {
|
811
|
+
return "MimeTypeArray";
|
812
|
+
}
|
813
|
+
if (typeof window.navigator.plugins === "object" && obj === window.navigator.plugins) {
|
814
|
+
return "PluginArray";
|
815
|
+
}
|
816
|
+
}
|
817
|
+
if ((typeof window.HTMLElement === "function" || typeof window.HTMLElement === "object") && obj instanceof window.HTMLElement) {
|
818
|
+
if (obj.tagName === "BLOCKQUOTE") {
|
819
|
+
return "HTMLQuoteElement";
|
820
|
+
}
|
821
|
+
if (obj.tagName === "TD") {
|
822
|
+
return "HTMLTableDataCellElement";
|
823
|
+
}
|
824
|
+
if (obj.tagName === "TH") {
|
825
|
+
return "HTMLTableHeaderCellElement";
|
826
|
+
}
|
827
|
+
}
|
828
|
+
}
|
829
|
+
var stringTag = symbolToStringTagExists && obj[Symbol.toStringTag];
|
830
|
+
if (typeof stringTag === "string") {
|
831
|
+
return stringTag;
|
832
|
+
}
|
833
|
+
var objPrototype = Object.getPrototypeOf(obj);
|
834
|
+
if (objPrototype === RegExp.prototype) {
|
835
|
+
return "RegExp";
|
836
|
+
}
|
837
|
+
if (objPrototype === Date.prototype) {
|
838
|
+
return "Date";
|
839
|
+
}
|
840
|
+
if (promiseExists && objPrototype === Promise.prototype) {
|
841
|
+
return "Promise";
|
842
|
+
}
|
843
|
+
if (setExists && objPrototype === Set.prototype) {
|
844
|
+
return "Set";
|
845
|
+
}
|
846
|
+
if (mapExists && objPrototype === Map.prototype) {
|
847
|
+
return "Map";
|
848
|
+
}
|
849
|
+
if (weakSetExists && objPrototype === WeakSet.prototype) {
|
850
|
+
return "WeakSet";
|
851
|
+
}
|
852
|
+
if (weakMapExists && objPrototype === WeakMap.prototype) {
|
853
|
+
return "WeakMap";
|
854
|
+
}
|
855
|
+
if (dataViewExists && objPrototype === DataView.prototype) {
|
856
|
+
return "DataView";
|
857
|
+
}
|
858
|
+
if (mapExists && objPrototype === mapIteratorPrototype) {
|
859
|
+
return "Map Iterator";
|
860
|
+
}
|
861
|
+
if (setExists && objPrototype === setIteratorPrototype) {
|
862
|
+
return "Set Iterator";
|
863
|
+
}
|
864
|
+
if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
|
865
|
+
return "Array Iterator";
|
866
|
+
}
|
867
|
+
if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
|
868
|
+
return "String Iterator";
|
869
|
+
}
|
870
|
+
if (objPrototype === null) {
|
871
|
+
return "Object";
|
872
|
+
}
|
873
|
+
return Object.prototype.toString.call(obj).slice(toStringLeftSliceLength, toStringRightSliceLength);
|
874
|
+
}
|
875
|
+
return typeDetect2;
|
876
|
+
});
|
877
|
+
})(typeDetect);
|
878
|
+
var typeDetectExports = typeDetect.exports;
|
879
|
+
var type = typeDetectExports;
|
880
|
+
var typeOf = function typeOf2(value) {
|
881
|
+
return type(value).toLowerCase();
|
882
|
+
};
|
883
|
+
function valueToString(value) {
|
884
|
+
if (value && value.toString) {
|
885
|
+
return value.toString();
|
886
|
+
}
|
887
|
+
return String(value);
|
888
|
+
}
|
889
|
+
var valueToString_1 = valueToString;
|
890
|
+
var lib = {
|
891
|
+
global: global2,
|
892
|
+
calledInOrder: calledInOrder_1,
|
893
|
+
className: className_1,
|
894
|
+
deprecated,
|
895
|
+
every,
|
896
|
+
functionName: functionName$1,
|
897
|
+
orderByFirstCall: orderByFirstCall_1,
|
898
|
+
prototypes,
|
899
|
+
typeOf,
|
900
|
+
valueToString: valueToString_1
|
901
|
+
};
|
902
|
+
var globalObject = lib.global;
|
903
|
+
var timersModule;
|
904
|
+
if (typeof __vitest_required__ !== "undefined") {
|
905
|
+
try {
|
906
|
+
timersModule = __vitest_required__.timers;
|
907
|
+
} catch (e) {
|
908
|
+
}
|
909
|
+
}
|
910
|
+
function withGlobal(_global) {
|
911
|
+
const maxTimeout = Math.pow(2, 31) - 1;
|
912
|
+
const idCounterStart = 1e12;
|
913
|
+
const NOOP = function() {
|
914
|
+
return void 0;
|
915
|
+
};
|
916
|
+
const NOOP_ARRAY = function() {
|
917
|
+
return [];
|
918
|
+
};
|
919
|
+
const timeoutResult = _global.setTimeout(NOOP, 0);
|
920
|
+
const addTimerReturnsObject = typeof timeoutResult === "object";
|
921
|
+
const hrtimePresent = _global.process && typeof _global.process.hrtime === "function";
|
922
|
+
const hrtimeBigintPresent = hrtimePresent && typeof _global.process.hrtime.bigint === "function";
|
923
|
+
const nextTickPresent = _global.process && typeof _global.process.nextTick === "function";
|
924
|
+
const utilPromisify = _global.process && _global.__vitest_required__ && _global.__vitest_required__.util.promisify;
|
925
|
+
const performancePresent = _global.performance && typeof _global.performance.now === "function";
|
926
|
+
const hasPerformancePrototype = _global.Performance && (typeof _global.Performance).match(/^(function|object)$/);
|
927
|
+
const hasPerformanceConstructorPrototype = _global.performance && _global.performance.constructor && _global.performance.constructor.prototype;
|
928
|
+
const queueMicrotaskPresent = _global.hasOwnProperty("queueMicrotask");
|
929
|
+
const requestAnimationFramePresent = _global.requestAnimationFrame && typeof _global.requestAnimationFrame === "function";
|
930
|
+
const cancelAnimationFramePresent = _global.cancelAnimationFrame && typeof _global.cancelAnimationFrame === "function";
|
931
|
+
const requestIdleCallbackPresent = _global.requestIdleCallback && typeof _global.requestIdleCallback === "function";
|
932
|
+
const cancelIdleCallbackPresent = _global.cancelIdleCallback && typeof _global.cancelIdleCallback === "function";
|
933
|
+
const setImmediatePresent = _global.setImmediate && typeof _global.setImmediate === "function";
|
934
|
+
const intlPresent = _global.Intl && typeof _global.Intl === "object";
|
935
|
+
_global.clearTimeout(timeoutResult);
|
936
|
+
const NativeDate = _global.Date;
|
937
|
+
const NativeIntl = _global.Intl;
|
938
|
+
let uniqueTimerId = idCounterStart;
|
939
|
+
function isNumberFinite(num) {
|
940
|
+
if (Number.isFinite) {
|
941
|
+
return Number.isFinite(num);
|
942
|
+
}
|
943
|
+
return isFinite(num);
|
944
|
+
}
|
945
|
+
let isNearInfiniteLimit = false;
|
946
|
+
function checkIsNearInfiniteLimit(clock, i) {
|
947
|
+
if (clock.loopLimit && i === clock.loopLimit - 1) {
|
948
|
+
isNearInfiniteLimit = true;
|
949
|
+
}
|
950
|
+
}
|
951
|
+
function resetIsNearInfiniteLimit() {
|
952
|
+
isNearInfiniteLimit = false;
|
953
|
+
}
|
954
|
+
function parseTime(str) {
|
955
|
+
if (!str) {
|
956
|
+
return 0;
|
957
|
+
}
|
958
|
+
const strings = str.split(":");
|
959
|
+
const l = strings.length;
|
960
|
+
let i = l;
|
961
|
+
let ms = 0;
|
962
|
+
let parsed;
|
963
|
+
if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
|
964
|
+
throw new Error(
|
965
|
+
"tick only understands numbers, 'm:s' and 'h:m:s'. Each part must be two digits"
|
966
|
+
);
|
967
|
+
}
|
968
|
+
while (i--) {
|
969
|
+
parsed = parseInt(strings[i], 10);
|
970
|
+
if (parsed >= 60) {
|
971
|
+
throw new Error(`Invalid time ${str}`);
|
972
|
+
}
|
973
|
+
ms += parsed * Math.pow(60, l - i - 1);
|
974
|
+
}
|
975
|
+
return ms * 1e3;
|
976
|
+
}
|
977
|
+
function nanoRemainder(msFloat) {
|
978
|
+
const modulo = 1e6;
|
979
|
+
const remainder = msFloat * 1e6 % modulo;
|
980
|
+
const positiveRemainder = remainder < 0 ? remainder + modulo : remainder;
|
981
|
+
return Math.floor(positiveRemainder);
|
982
|
+
}
|
983
|
+
function getEpoch(epoch) {
|
984
|
+
if (!epoch) {
|
985
|
+
return 0;
|
986
|
+
}
|
987
|
+
if (typeof epoch.getTime === "function") {
|
988
|
+
return epoch.getTime();
|
989
|
+
}
|
990
|
+
if (typeof epoch === "number") {
|
991
|
+
return epoch;
|
992
|
+
}
|
993
|
+
throw new TypeError("now should be milliseconds since UNIX epoch");
|
994
|
+
}
|
995
|
+
function inRange(from, to, timer) {
|
996
|
+
return timer && timer.callAt >= from && timer.callAt <= to;
|
997
|
+
}
|
998
|
+
function getInfiniteLoopError(clock, job) {
|
999
|
+
const infiniteLoopError = new Error(
|
1000
|
+
`Aborting after running ${clock.loopLimit} timers, assuming an infinite loop!`
|
1001
|
+
);
|
1002
|
+
if (!job.error) {
|
1003
|
+
return infiniteLoopError;
|
1004
|
+
}
|
1005
|
+
const computedTargetPattern = /target\.*[<|(|[].*?[>|\]|)]\s*/;
|
1006
|
+
let clockMethodPattern = new RegExp(
|
1007
|
+
String(Object.keys(clock).join("|"))
|
1008
|
+
);
|
1009
|
+
if (addTimerReturnsObject) {
|
1010
|
+
clockMethodPattern = new RegExp(
|
1011
|
+
`\\s+at (Object\\.)?(?:${Object.keys(clock).join("|")})\\s+`
|
1012
|
+
);
|
1013
|
+
}
|
1014
|
+
let matchedLineIndex = -1;
|
1015
|
+
job.error.stack.split("\n").some(function(line, i) {
|
1016
|
+
const matchedComputedTarget = line.match(computedTargetPattern);
|
1017
|
+
if (matchedComputedTarget) {
|
1018
|
+
matchedLineIndex = i;
|
1019
|
+
return true;
|
1020
|
+
}
|
1021
|
+
const matchedClockMethod = line.match(clockMethodPattern);
|
1022
|
+
if (matchedClockMethod) {
|
1023
|
+
matchedLineIndex = i;
|
1024
|
+
return false;
|
1025
|
+
}
|
1026
|
+
return matchedLineIndex >= 0;
|
1027
|
+
});
|
1028
|
+
const stack = `${infiniteLoopError}
|
1029
|
+
${job.type || "Microtask"} - ${job.func.name || "anonymous"}
|
1030
|
+
${job.error.stack.split("\n").slice(matchedLineIndex + 1).join("\n")}`;
|
1031
|
+
try {
|
1032
|
+
Object.defineProperty(infiniteLoopError, "stack", {
|
1033
|
+
value: stack
|
1034
|
+
});
|
1035
|
+
} catch (e) {
|
1036
|
+
}
|
1037
|
+
return infiniteLoopError;
|
1038
|
+
}
|
1039
|
+
function mirrorDateProperties(target, source) {
|
1040
|
+
let prop;
|
1041
|
+
for (prop in source) {
|
1042
|
+
if (source.hasOwnProperty(prop)) {
|
1043
|
+
target[prop] = source[prop];
|
1044
|
+
}
|
1045
|
+
}
|
1046
|
+
if (source.now) {
|
1047
|
+
target.now = function now2() {
|
1048
|
+
return target.clock.now;
|
1049
|
+
};
|
1050
|
+
} else {
|
1051
|
+
delete target.now;
|
1052
|
+
}
|
1053
|
+
if (source.toSource) {
|
1054
|
+
target.toSource = function toSource() {
|
1055
|
+
return source.toSource();
|
1056
|
+
};
|
1057
|
+
} else {
|
1058
|
+
delete target.toSource;
|
1059
|
+
}
|
1060
|
+
target.toString = function toString() {
|
1061
|
+
return source.toString();
|
1062
|
+
};
|
1063
|
+
target.prototype = source.prototype;
|
1064
|
+
target.parse = source.parse;
|
1065
|
+
target.UTC = source.UTC;
|
1066
|
+
target.prototype.toUTCString = source.prototype.toUTCString;
|
1067
|
+
target.isFake = true;
|
1068
|
+
return target;
|
1069
|
+
}
|
1070
|
+
function createDate() {
|
1071
|
+
function ClockDate(year, month, date, hour, minute, second, ms) {
|
1072
|
+
if (!(this instanceof ClockDate)) {
|
1073
|
+
return new NativeDate(ClockDate.clock.now).toString();
|
1074
|
+
}
|
1075
|
+
switch (arguments.length) {
|
1076
|
+
case 0:
|
1077
|
+
return new NativeDate(ClockDate.clock.now);
|
1078
|
+
case 1:
|
1079
|
+
return new NativeDate(year);
|
1080
|
+
case 2:
|
1081
|
+
return new NativeDate(year, month);
|
1082
|
+
case 3:
|
1083
|
+
return new NativeDate(year, month, date);
|
1084
|
+
case 4:
|
1085
|
+
return new NativeDate(year, month, date, hour);
|
1086
|
+
case 5:
|
1087
|
+
return new NativeDate(year, month, date, hour, minute);
|
1088
|
+
case 6:
|
1089
|
+
return new NativeDate(
|
1090
|
+
year,
|
1091
|
+
month,
|
1092
|
+
date,
|
1093
|
+
hour,
|
1094
|
+
minute,
|
1095
|
+
second
|
1096
|
+
);
|
1097
|
+
default:
|
1098
|
+
return new NativeDate(
|
1099
|
+
year,
|
1100
|
+
month,
|
1101
|
+
date,
|
1102
|
+
hour,
|
1103
|
+
minute,
|
1104
|
+
second,
|
1105
|
+
ms
|
1106
|
+
);
|
1107
|
+
}
|
1108
|
+
}
|
1109
|
+
return mirrorDateProperties(ClockDate, NativeDate);
|
1110
|
+
}
|
1111
|
+
function createIntl() {
|
1112
|
+
const ClockIntl = { ...NativeIntl };
|
1113
|
+
ClockIntl.DateTimeFormat = function(...args) {
|
1114
|
+
const realFormatter = new NativeIntl.DateTimeFormat(...args);
|
1115
|
+
const formatter = {};
|
1116
|
+
["formatRange", "formatRangeToParts", "resolvedOptions"].forEach(
|
1117
|
+
(method) => {
|
1118
|
+
formatter[method] = realFormatter[method].bind(realFormatter);
|
1119
|
+
}
|
1120
|
+
);
|
1121
|
+
["format", "formatToParts"].forEach((method) => {
|
1122
|
+
formatter[method] = function(date) {
|
1123
|
+
return realFormatter[method](date || ClockIntl.clock.now);
|
1124
|
+
};
|
1125
|
+
});
|
1126
|
+
return formatter;
|
1127
|
+
};
|
1128
|
+
ClockIntl.DateTimeFormat.prototype = Object.create(
|
1129
|
+
NativeIntl.DateTimeFormat.prototype
|
1130
|
+
);
|
1131
|
+
ClockIntl.DateTimeFormat.supportedLocalesOf = NativeIntl.DateTimeFormat.supportedLocalesOf;
|
1132
|
+
return ClockIntl;
|
1133
|
+
}
|
1134
|
+
function enqueueJob(clock, job) {
|
1135
|
+
if (!clock.jobs) {
|
1136
|
+
clock.jobs = [];
|
1137
|
+
}
|
1138
|
+
clock.jobs.push(job);
|
1139
|
+
}
|
1140
|
+
function runJobs(clock) {
|
1141
|
+
if (!clock.jobs) {
|
1142
|
+
return;
|
1143
|
+
}
|
1144
|
+
for (let i = 0; i < clock.jobs.length; i++) {
|
1145
|
+
const job = clock.jobs[i];
|
1146
|
+
job.func.apply(null, job.args);
|
1147
|
+
checkIsNearInfiniteLimit(clock, i);
|
1148
|
+
if (clock.loopLimit && i > clock.loopLimit) {
|
1149
|
+
throw getInfiniteLoopError(clock, job);
|
1150
|
+
}
|
1151
|
+
}
|
1152
|
+
resetIsNearInfiniteLimit();
|
1153
|
+
clock.jobs = [];
|
1154
|
+
}
|
1155
|
+
function addTimer(clock, timer) {
|
1156
|
+
if (timer.func === void 0) {
|
1157
|
+
throw new Error("Callback must be provided to timer calls");
|
1158
|
+
}
|
1159
|
+
if (addTimerReturnsObject) {
|
1160
|
+
if (typeof timer.func !== "function") {
|
1161
|
+
throw new TypeError(
|
1162
|
+
`[ERR_INVALID_CALLBACK]: Callback must be a function. Received ${timer.func} of type ${typeof timer.func}`
|
1163
|
+
);
|
1164
|
+
}
|
1165
|
+
}
|
1166
|
+
if (isNearInfiniteLimit) {
|
1167
|
+
timer.error = new Error();
|
1168
|
+
}
|
1169
|
+
timer.type = timer.immediate ? "Immediate" : "Timeout";
|
1170
|
+
if (timer.hasOwnProperty("delay")) {
|
1171
|
+
if (typeof timer.delay !== "number") {
|
1172
|
+
timer.delay = parseInt(timer.delay, 10);
|
1173
|
+
}
|
1174
|
+
if (!isNumberFinite(timer.delay)) {
|
1175
|
+
timer.delay = 0;
|
1176
|
+
}
|
1177
|
+
timer.delay = timer.delay > maxTimeout ? 1 : timer.delay;
|
1178
|
+
timer.delay = Math.max(0, timer.delay);
|
1179
|
+
}
|
1180
|
+
if (timer.hasOwnProperty("interval")) {
|
1181
|
+
timer.type = "Interval";
|
1182
|
+
timer.interval = timer.interval > maxTimeout ? 1 : timer.interval;
|
1183
|
+
}
|
1184
|
+
if (timer.hasOwnProperty("animation")) {
|
1185
|
+
timer.type = "AnimationFrame";
|
1186
|
+
timer.animation = true;
|
1187
|
+
}
|
1188
|
+
if (timer.hasOwnProperty("idleCallback")) {
|
1189
|
+
timer.type = "IdleCallback";
|
1190
|
+
timer.idleCallback = true;
|
1191
|
+
}
|
1192
|
+
if (!clock.timers) {
|
1193
|
+
clock.timers = {};
|
1194
|
+
}
|
1195
|
+
timer.id = uniqueTimerId++;
|
1196
|
+
timer.createdAt = clock.now;
|
1197
|
+
timer.callAt = clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));
|
1198
|
+
clock.timers[timer.id] = timer;
|
1199
|
+
if (addTimerReturnsObject) {
|
1200
|
+
const res = {
|
1201
|
+
refed: true,
|
1202
|
+
ref: function() {
|
1203
|
+
this.refed = true;
|
1204
|
+
return res;
|
1205
|
+
},
|
1206
|
+
unref: function() {
|
1207
|
+
this.refed = false;
|
1208
|
+
return res;
|
1209
|
+
},
|
1210
|
+
hasRef: function() {
|
1211
|
+
return this.refed;
|
1212
|
+
},
|
1213
|
+
refresh: function() {
|
1214
|
+
timer.callAt = clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));
|
1215
|
+
clock.timers[timer.id] = timer;
|
1216
|
+
return res;
|
1217
|
+
},
|
1218
|
+
[Symbol.toPrimitive]: function() {
|
1219
|
+
return timer.id;
|
1220
|
+
}
|
1221
|
+
};
|
1222
|
+
return res;
|
1223
|
+
}
|
1224
|
+
return timer.id;
|
1225
|
+
}
|
1226
|
+
function compareTimers(a, b) {
|
1227
|
+
if (a.callAt < b.callAt) {
|
1228
|
+
return -1;
|
1229
|
+
}
|
1230
|
+
if (a.callAt > b.callAt) {
|
1231
|
+
return 1;
|
1232
|
+
}
|
1233
|
+
if (a.immediate && !b.immediate) {
|
1234
|
+
return -1;
|
1235
|
+
}
|
1236
|
+
if (!a.immediate && b.immediate) {
|
1237
|
+
return 1;
|
1238
|
+
}
|
1239
|
+
if (a.createdAt < b.createdAt) {
|
1240
|
+
return -1;
|
1241
|
+
}
|
1242
|
+
if (a.createdAt > b.createdAt) {
|
1243
|
+
return 1;
|
1244
|
+
}
|
1245
|
+
if (a.id < b.id) {
|
1246
|
+
return -1;
|
1247
|
+
}
|
1248
|
+
if (a.id > b.id) {
|
1249
|
+
return 1;
|
1250
|
+
}
|
1251
|
+
}
|
1252
|
+
function firstTimerInRange(clock, from, to) {
|
1253
|
+
const timers2 = clock.timers;
|
1254
|
+
let timer = null;
|
1255
|
+
let id, isInRange;
|
1256
|
+
for (id in timers2) {
|
1257
|
+
if (timers2.hasOwnProperty(id)) {
|
1258
|
+
isInRange = inRange(from, to, timers2[id]);
|
1259
|
+
if (isInRange && (!timer || compareTimers(timer, timers2[id]) === 1)) {
|
1260
|
+
timer = timers2[id];
|
1261
|
+
}
|
1262
|
+
}
|
1263
|
+
}
|
1264
|
+
return timer;
|
1265
|
+
}
|
1266
|
+
function firstTimer(clock) {
|
1267
|
+
const timers2 = clock.timers;
|
1268
|
+
let timer = null;
|
1269
|
+
let id;
|
1270
|
+
for (id in timers2) {
|
1271
|
+
if (timers2.hasOwnProperty(id)) {
|
1272
|
+
if (!timer || compareTimers(timer, timers2[id]) === 1) {
|
1273
|
+
timer = timers2[id];
|
1274
|
+
}
|
1275
|
+
}
|
1276
|
+
}
|
1277
|
+
return timer;
|
1278
|
+
}
|
1279
|
+
function lastTimer(clock) {
|
1280
|
+
const timers2 = clock.timers;
|
1281
|
+
let timer = null;
|
1282
|
+
let id;
|
1283
|
+
for (id in timers2) {
|
1284
|
+
if (timers2.hasOwnProperty(id)) {
|
1285
|
+
if (!timer || compareTimers(timer, timers2[id]) === -1) {
|
1286
|
+
timer = timers2[id];
|
1287
|
+
}
|
1288
|
+
}
|
1289
|
+
}
|
1290
|
+
return timer;
|
1291
|
+
}
|
1292
|
+
function callTimer(clock, timer) {
|
1293
|
+
if (typeof timer.interval === "number") {
|
1294
|
+
clock.timers[timer.id].callAt += timer.interval;
|
1295
|
+
} else {
|
1296
|
+
delete clock.timers[timer.id];
|
1297
|
+
}
|
1298
|
+
if (typeof timer.func === "function") {
|
1299
|
+
timer.func.apply(null, timer.args);
|
1300
|
+
} else {
|
1301
|
+
const eval2 = eval;
|
1302
|
+
(function() {
|
1303
|
+
eval2(timer.func);
|
1304
|
+
})();
|
1305
|
+
}
|
1306
|
+
}
|
1307
|
+
function getClearHandler(ttype) {
|
1308
|
+
if (ttype === "IdleCallback" || ttype === "AnimationFrame") {
|
1309
|
+
return `cancel${ttype}`;
|
1310
|
+
}
|
1311
|
+
return `clear${ttype}`;
|
1312
|
+
}
|
1313
|
+
function getScheduleHandler(ttype) {
|
1314
|
+
if (ttype === "IdleCallback" || ttype === "AnimationFrame") {
|
1315
|
+
return `request${ttype}`;
|
1316
|
+
}
|
1317
|
+
return `set${ttype}`;
|
1318
|
+
}
|
1319
|
+
function createWarnOnce() {
|
1320
|
+
let calls = 0;
|
1321
|
+
return function(msg) {
|
1322
|
+
!calls++ && console.warn(msg);
|
1323
|
+
};
|
1324
|
+
}
|
1325
|
+
const warnOnce = createWarnOnce();
|
1326
|
+
function clearTimer(clock, timerId, ttype) {
|
1327
|
+
if (!timerId) {
|
1328
|
+
return;
|
1329
|
+
}
|
1330
|
+
if (!clock.timers) {
|
1331
|
+
clock.timers = {};
|
1332
|
+
}
|
1333
|
+
const id = Number(timerId);
|
1334
|
+
if (Number.isNaN(id) || id < idCounterStart) {
|
1335
|
+
const handlerName = getClearHandler(ttype);
|
1336
|
+
if (clock.shouldClearNativeTimers === true) {
|
1337
|
+
const nativeHandler = clock[`_${handlerName}`];
|
1338
|
+
return typeof nativeHandler === "function" ? nativeHandler(timerId) : void 0;
|
1339
|
+
}
|
1340
|
+
warnOnce(
|
1341
|
+
`FakeTimers: ${handlerName} was invoked to clear a native timer instead of one created by this library.
|
1342
|
+
To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
1343
|
+
);
|
1344
|
+
}
|
1345
|
+
if (clock.timers.hasOwnProperty(id)) {
|
1346
|
+
const timer = clock.timers[id];
|
1347
|
+
if (timer.type === ttype || timer.type === "Timeout" && ttype === "Interval" || timer.type === "Interval" && ttype === "Timeout") {
|
1348
|
+
delete clock.timers[id];
|
1349
|
+
} else {
|
1350
|
+
const clear = getClearHandler(ttype);
|
1351
|
+
const schedule = getScheduleHandler(timer.type);
|
1352
|
+
throw new Error(
|
1353
|
+
`Cannot clear timer: timer created with ${schedule}() but cleared with ${clear}()`
|
1354
|
+
);
|
1355
|
+
}
|
1356
|
+
}
|
1357
|
+
}
|
1358
|
+
function uninstall(clock, config) {
|
1359
|
+
let method, i, l;
|
1360
|
+
const installedHrTime = "_hrtime";
|
1361
|
+
const installedNextTick = "_nextTick";
|
1362
|
+
for (i = 0, l = clock.methods.length; i < l; i++) {
|
1363
|
+
method = clock.methods[i];
|
1364
|
+
if (method === "hrtime" && _global.process) {
|
1365
|
+
_global.process.hrtime = clock[installedHrTime];
|
1366
|
+
} else if (method === "nextTick" && _global.process) {
|
1367
|
+
_global.process.nextTick = clock[installedNextTick];
|
1368
|
+
} else if (method === "performance") {
|
1369
|
+
const originalPerfDescriptor = Object.getOwnPropertyDescriptor(
|
1370
|
+
clock,
|
1371
|
+
`_${method}`
|
1372
|
+
);
|
1373
|
+
if (originalPerfDescriptor && originalPerfDescriptor.get && !originalPerfDescriptor.set) {
|
1374
|
+
Object.defineProperty(
|
1375
|
+
_global,
|
1376
|
+
method,
|
1377
|
+
originalPerfDescriptor
|
1378
|
+
);
|
1379
|
+
} else if (originalPerfDescriptor.configurable) {
|
1380
|
+
_global[method] = clock[`_${method}`];
|
1381
|
+
}
|
1382
|
+
} else {
|
1383
|
+
if (_global[method] && _global[method].hadOwnProperty) {
|
1384
|
+
_global[method] = clock[`_${method}`];
|
1385
|
+
} else {
|
1386
|
+
try {
|
1387
|
+
delete _global[method];
|
1388
|
+
} catch (ignore) {
|
1389
|
+
}
|
1390
|
+
}
|
1391
|
+
}
|
1392
|
+
if (clock.timersModuleMethods !== void 0) {
|
1393
|
+
for (let j = 0; j < clock.timersModuleMethods.length; j++) {
|
1394
|
+
const entry = clock.timersModuleMethods[j];
|
1395
|
+
timersModule[entry.methodName] = entry.original;
|
1396
|
+
}
|
1397
|
+
}
|
1398
|
+
}
|
1399
|
+
if (config.shouldAdvanceTime === true) {
|
1400
|
+
_global.clearInterval(clock.attachedInterval);
|
1401
|
+
}
|
1402
|
+
clock.methods = [];
|
1403
|
+
if (!clock.timers) {
|
1404
|
+
return [];
|
1405
|
+
}
|
1406
|
+
return Object.keys(clock.timers).map(function mapper(key) {
|
1407
|
+
return clock.timers[key];
|
1408
|
+
});
|
1409
|
+
}
|
1410
|
+
function hijackMethod(target, method, clock) {
|
1411
|
+
clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(
|
1412
|
+
target,
|
1413
|
+
method
|
1414
|
+
);
|
1415
|
+
clock[`_${method}`] = target[method];
|
1416
|
+
if (method === "Date") {
|
1417
|
+
const date = mirrorDateProperties(clock[method], target[method]);
|
1418
|
+
target[method] = date;
|
1419
|
+
} else if (method === "Intl") {
|
1420
|
+
target[method] = clock[method];
|
1421
|
+
} else if (method === "performance") {
|
1422
|
+
const originalPerfDescriptor = Object.getOwnPropertyDescriptor(
|
1423
|
+
target,
|
1424
|
+
method
|
1425
|
+
);
|
1426
|
+
if (originalPerfDescriptor && originalPerfDescriptor.get && !originalPerfDescriptor.set) {
|
1427
|
+
Object.defineProperty(
|
1428
|
+
clock,
|
1429
|
+
`_${method}`,
|
1430
|
+
originalPerfDescriptor
|
1431
|
+
);
|
1432
|
+
const perfDescriptor = Object.getOwnPropertyDescriptor(
|
1433
|
+
clock,
|
1434
|
+
method
|
1435
|
+
);
|
1436
|
+
Object.defineProperty(target, method, perfDescriptor);
|
1437
|
+
} else {
|
1438
|
+
target[method] = clock[method];
|
1439
|
+
}
|
1440
|
+
} else {
|
1441
|
+
target[method] = function() {
|
1442
|
+
return clock[method].apply(clock, arguments);
|
1443
|
+
};
|
1444
|
+
Object.defineProperties(
|
1445
|
+
target[method],
|
1446
|
+
Object.getOwnPropertyDescriptors(clock[method])
|
1447
|
+
);
|
1448
|
+
}
|
1449
|
+
target[method].clock = clock;
|
1450
|
+
}
|
1451
|
+
function doIntervalTick(clock, advanceTimeDelta) {
|
1452
|
+
clock.tick(advanceTimeDelta);
|
1453
|
+
}
|
1454
|
+
const timers = {
|
1455
|
+
setTimeout: _global.setTimeout,
|
1456
|
+
clearTimeout: _global.clearTimeout,
|
1457
|
+
setInterval: _global.setInterval,
|
1458
|
+
clearInterval: _global.clearInterval,
|
1459
|
+
Date: _global.Date
|
1460
|
+
};
|
1461
|
+
if (setImmediatePresent) {
|
1462
|
+
timers.setImmediate = _global.setImmediate;
|
1463
|
+
timers.clearImmediate = _global.clearImmediate;
|
1464
|
+
}
|
1465
|
+
if (hrtimePresent) {
|
1466
|
+
timers.hrtime = _global.process.hrtime;
|
1467
|
+
}
|
1468
|
+
if (nextTickPresent) {
|
1469
|
+
timers.nextTick = _global.process.nextTick;
|
1470
|
+
}
|
1471
|
+
if (performancePresent) {
|
1472
|
+
timers.performance = _global.performance;
|
1473
|
+
}
|
1474
|
+
if (requestAnimationFramePresent) {
|
1475
|
+
timers.requestAnimationFrame = _global.requestAnimationFrame;
|
1476
|
+
}
|
1477
|
+
if (queueMicrotaskPresent) {
|
1478
|
+
timers.queueMicrotask = true;
|
1479
|
+
}
|
1480
|
+
if (cancelAnimationFramePresent) {
|
1481
|
+
timers.cancelAnimationFrame = _global.cancelAnimationFrame;
|
1482
|
+
}
|
1483
|
+
if (requestIdleCallbackPresent) {
|
1484
|
+
timers.requestIdleCallback = _global.requestIdleCallback;
|
1485
|
+
}
|
1486
|
+
if (cancelIdleCallbackPresent) {
|
1487
|
+
timers.cancelIdleCallback = _global.cancelIdleCallback;
|
1488
|
+
}
|
1489
|
+
if (intlPresent) {
|
1490
|
+
timers.Intl = _global.Intl;
|
1491
|
+
}
|
1492
|
+
const originalSetTimeout = _global.setImmediate || _global.setTimeout;
|
1493
|
+
function createClock(start, loopLimit) {
|
1494
|
+
start = Math.floor(getEpoch(start));
|
1495
|
+
loopLimit = loopLimit || 1e3;
|
1496
|
+
let nanos = 0;
|
1497
|
+
const adjustedSystemTime = [0, 0];
|
1498
|
+
if (NativeDate === void 0) {
|
1499
|
+
throw new Error(
|
1500
|
+
"The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
|
1501
|
+
);
|
1502
|
+
}
|
1503
|
+
const clock = {
|
1504
|
+
now: start,
|
1505
|
+
Date: createDate(),
|
1506
|
+
loopLimit
|
1507
|
+
};
|
1508
|
+
clock.Date.clock = clock;
|
1509
|
+
function getTimeToNextFrame() {
|
1510
|
+
return 16 - (clock.now - start) % 16;
|
1511
|
+
}
|
1512
|
+
function hrtime(prev) {
|
1513
|
+
const millisSinceStart = clock.now - adjustedSystemTime[0] - start;
|
1514
|
+
const secsSinceStart = Math.floor(millisSinceStart / 1e3);
|
1515
|
+
const remainderInNanos = (millisSinceStart - secsSinceStart * 1e3) * 1e6 + nanos - adjustedSystemTime[1];
|
1516
|
+
if (Array.isArray(prev)) {
|
1517
|
+
if (prev[1] > 1e9) {
|
1518
|
+
throw new TypeError(
|
1519
|
+
"Number of nanoseconds can't exceed a billion"
|
1520
|
+
);
|
1521
|
+
}
|
1522
|
+
const oldSecs = prev[0];
|
1523
|
+
let nanoDiff = remainderInNanos - prev[1];
|
1524
|
+
let secDiff = secsSinceStart - oldSecs;
|
1525
|
+
if (nanoDiff < 0) {
|
1526
|
+
nanoDiff += 1e9;
|
1527
|
+
secDiff -= 1;
|
1528
|
+
}
|
1529
|
+
return [secDiff, nanoDiff];
|
1530
|
+
}
|
1531
|
+
return [secsSinceStart, remainderInNanos];
|
1532
|
+
}
|
1533
|
+
function fakePerformanceNow() {
|
1534
|
+
const hrt = hrtime();
|
1535
|
+
const millis = hrt[0] * 1e3 + hrt[1] / 1e6;
|
1536
|
+
return millis;
|
1537
|
+
}
|
1538
|
+
if (hrtimeBigintPresent) {
|
1539
|
+
hrtime.bigint = function() {
|
1540
|
+
const parts = hrtime();
|
1541
|
+
return BigInt(parts[0]) * BigInt(1e9) + BigInt(parts[1]);
|
1542
|
+
};
|
1543
|
+
}
|
1544
|
+
if (intlPresent) {
|
1545
|
+
clock.Intl = createIntl();
|
1546
|
+
clock.Intl.clock = clock;
|
1547
|
+
}
|
1548
|
+
clock.requestIdleCallback = function requestIdleCallback(func, timeout) {
|
1549
|
+
let timeToNextIdlePeriod = 0;
|
1550
|
+
if (clock.countTimers() > 0) {
|
1551
|
+
timeToNextIdlePeriod = 50;
|
1552
|
+
}
|
1553
|
+
const result = addTimer(clock, {
|
1554
|
+
func,
|
1555
|
+
args: Array.prototype.slice.call(arguments, 2),
|
1556
|
+
delay: typeof timeout === "undefined" ? timeToNextIdlePeriod : Math.min(timeout, timeToNextIdlePeriod),
|
1557
|
+
idleCallback: true
|
1558
|
+
});
|
1559
|
+
return Number(result);
|
1560
|
+
};
|
1561
|
+
clock.cancelIdleCallback = function cancelIdleCallback(timerId) {
|
1562
|
+
return clearTimer(clock, timerId, "IdleCallback");
|
1563
|
+
};
|
1564
|
+
clock.setTimeout = function setTimeout(func, timeout) {
|
1565
|
+
return addTimer(clock, {
|
1566
|
+
func,
|
1567
|
+
args: Array.prototype.slice.call(arguments, 2),
|
1568
|
+
delay: timeout
|
1569
|
+
});
|
1570
|
+
};
|
1571
|
+
if (typeof _global.Promise !== "undefined" && utilPromisify) {
|
1572
|
+
clock.setTimeout[utilPromisify.custom] = function promisifiedSetTimeout(timeout, arg) {
|
1573
|
+
return new _global.Promise(function setTimeoutExecutor(resolve) {
|
1574
|
+
addTimer(clock, {
|
1575
|
+
func: resolve,
|
1576
|
+
args: [arg],
|
1577
|
+
delay: timeout
|
1578
|
+
});
|
1579
|
+
});
|
1580
|
+
};
|
1581
|
+
}
|
1582
|
+
clock.clearTimeout = function clearTimeout(timerId) {
|
1583
|
+
return clearTimer(clock, timerId, "Timeout");
|
1584
|
+
};
|
1585
|
+
clock.nextTick = function nextTick(func) {
|
1586
|
+
return enqueueJob(clock, {
|
1587
|
+
func,
|
1588
|
+
args: Array.prototype.slice.call(arguments, 1),
|
1589
|
+
error: isNearInfiniteLimit ? new Error() : null
|
1590
|
+
});
|
1591
|
+
};
|
1592
|
+
clock.queueMicrotask = function queueMicrotask(func) {
|
1593
|
+
return clock.nextTick(func);
|
1594
|
+
};
|
1595
|
+
clock.setInterval = function setInterval(func, timeout) {
|
1596
|
+
timeout = parseInt(timeout, 10);
|
1597
|
+
return addTimer(clock, {
|
1598
|
+
func,
|
1599
|
+
args: Array.prototype.slice.call(arguments, 2),
|
1600
|
+
delay: timeout,
|
1601
|
+
interval: timeout
|
1602
|
+
});
|
1603
|
+
};
|
1604
|
+
clock.clearInterval = function clearInterval(timerId) {
|
1605
|
+
return clearTimer(clock, timerId, "Interval");
|
1606
|
+
};
|
1607
|
+
if (setImmediatePresent) {
|
1608
|
+
clock.setImmediate = function setImmediate(func) {
|
1609
|
+
return addTimer(clock, {
|
1610
|
+
func,
|
1611
|
+
args: Array.prototype.slice.call(arguments, 1),
|
1612
|
+
immediate: true
|
1613
|
+
});
|
1614
|
+
};
|
1615
|
+
if (typeof _global.Promise !== "undefined" && utilPromisify) {
|
1616
|
+
clock.setImmediate[utilPromisify.custom] = function promisifiedSetImmediate(arg) {
|
1617
|
+
return new _global.Promise(
|
1618
|
+
function setImmediateExecutor(resolve) {
|
1619
|
+
addTimer(clock, {
|
1620
|
+
func: resolve,
|
1621
|
+
args: [arg],
|
1622
|
+
immediate: true
|
1623
|
+
});
|
1624
|
+
}
|
1625
|
+
);
|
1626
|
+
};
|
1627
|
+
}
|
1628
|
+
clock.clearImmediate = function clearImmediate(timerId) {
|
1629
|
+
return clearTimer(clock, timerId, "Immediate");
|
1630
|
+
};
|
1631
|
+
}
|
1632
|
+
clock.countTimers = function countTimers() {
|
1633
|
+
return Object.keys(clock.timers || {}).length + (clock.jobs || []).length;
|
1634
|
+
};
|
1635
|
+
clock.requestAnimationFrame = function requestAnimationFrame(func) {
|
1636
|
+
const result = addTimer(clock, {
|
1637
|
+
func,
|
1638
|
+
delay: getTimeToNextFrame(),
|
1639
|
+
get args() {
|
1640
|
+
return [fakePerformanceNow()];
|
1641
|
+
},
|
1642
|
+
animation: true
|
1643
|
+
});
|
1644
|
+
return Number(result);
|
1645
|
+
};
|
1646
|
+
clock.cancelAnimationFrame = function cancelAnimationFrame(timerId) {
|
1647
|
+
return clearTimer(clock, timerId, "AnimationFrame");
|
1648
|
+
};
|
1649
|
+
clock.runMicrotasks = function runMicrotasks() {
|
1650
|
+
runJobs(clock);
|
1651
|
+
};
|
1652
|
+
function doTick(tickValue, isAsync, resolve, reject) {
|
1653
|
+
const msFloat = typeof tickValue === "number" ? tickValue : parseTime(tickValue);
|
1654
|
+
const ms = Math.floor(msFloat);
|
1655
|
+
const remainder = nanoRemainder(msFloat);
|
1656
|
+
let nanosTotal = nanos + remainder;
|
1657
|
+
let tickTo = clock.now + ms;
|
1658
|
+
if (msFloat < 0) {
|
1659
|
+
throw new TypeError("Negative ticks are not supported");
|
1660
|
+
}
|
1661
|
+
if (nanosTotal >= 1e6) {
|
1662
|
+
tickTo += 1;
|
1663
|
+
nanosTotal -= 1e6;
|
1664
|
+
}
|
1665
|
+
nanos = nanosTotal;
|
1666
|
+
let tickFrom = clock.now;
|
1667
|
+
let previous = clock.now;
|
1668
|
+
let timer, firstException, oldNow, nextPromiseTick, compensationCheck, postTimerCall;
|
1669
|
+
clock.duringTick = true;
|
1670
|
+
oldNow = clock.now;
|
1671
|
+
runJobs(clock);
|
1672
|
+
if (oldNow !== clock.now) {
|
1673
|
+
tickFrom += clock.now - oldNow;
|
1674
|
+
tickTo += clock.now - oldNow;
|
1675
|
+
}
|
1676
|
+
function doTickInner() {
|
1677
|
+
timer = firstTimerInRange(clock, tickFrom, tickTo);
|
1678
|
+
while (timer && tickFrom <= tickTo) {
|
1679
|
+
if (clock.timers[timer.id]) {
|
1680
|
+
tickFrom = timer.callAt;
|
1681
|
+
clock.now = timer.callAt;
|
1682
|
+
oldNow = clock.now;
|
1683
|
+
try {
|
1684
|
+
runJobs(clock);
|
1685
|
+
callTimer(clock, timer);
|
1686
|
+
} catch (e) {
|
1687
|
+
firstException = firstException || e;
|
1688
|
+
}
|
1689
|
+
if (isAsync) {
|
1690
|
+
originalSetTimeout(nextPromiseTick);
|
1691
|
+
return;
|
1692
|
+
}
|
1693
|
+
compensationCheck();
|
1694
|
+
}
|
1695
|
+
postTimerCall();
|
1696
|
+
}
|
1697
|
+
oldNow = clock.now;
|
1698
|
+
runJobs(clock);
|
1699
|
+
if (oldNow !== clock.now) {
|
1700
|
+
tickFrom += clock.now - oldNow;
|
1701
|
+
tickTo += clock.now - oldNow;
|
1702
|
+
}
|
1703
|
+
clock.duringTick = false;
|
1704
|
+
timer = firstTimerInRange(clock, tickFrom, tickTo);
|
1705
|
+
if (timer) {
|
1706
|
+
try {
|
1707
|
+
clock.tick(tickTo - clock.now);
|
1708
|
+
} catch (e) {
|
1709
|
+
firstException = firstException || e;
|
1710
|
+
}
|
1711
|
+
} else {
|
1712
|
+
clock.now = tickTo;
|
1713
|
+
nanos = nanosTotal;
|
1714
|
+
}
|
1715
|
+
if (firstException) {
|
1716
|
+
throw firstException;
|
1717
|
+
}
|
1718
|
+
if (isAsync) {
|
1719
|
+
resolve(clock.now);
|
1720
|
+
} else {
|
1721
|
+
return clock.now;
|
1722
|
+
}
|
1723
|
+
}
|
1724
|
+
nextPromiseTick = isAsync && function() {
|
1725
|
+
try {
|
1726
|
+
compensationCheck();
|
1727
|
+
postTimerCall();
|
1728
|
+
doTickInner();
|
1729
|
+
} catch (e) {
|
1730
|
+
reject(e);
|
1731
|
+
}
|
1732
|
+
};
|
1733
|
+
compensationCheck = function() {
|
1734
|
+
if (oldNow !== clock.now) {
|
1735
|
+
tickFrom += clock.now - oldNow;
|
1736
|
+
tickTo += clock.now - oldNow;
|
1737
|
+
previous += clock.now - oldNow;
|
1738
|
+
}
|
1739
|
+
};
|
1740
|
+
postTimerCall = function() {
|
1741
|
+
timer = firstTimerInRange(clock, previous, tickTo);
|
1742
|
+
previous = tickFrom;
|
1743
|
+
};
|
1744
|
+
return doTickInner();
|
1745
|
+
}
|
1746
|
+
clock.tick = function tick(tickValue) {
|
1747
|
+
return doTick(tickValue, false);
|
1748
|
+
};
|
1749
|
+
if (typeof _global.Promise !== "undefined") {
|
1750
|
+
clock.tickAsync = function tickAsync(tickValue) {
|
1751
|
+
return new _global.Promise(function(resolve, reject) {
|
1752
|
+
originalSetTimeout(function() {
|
1753
|
+
try {
|
1754
|
+
doTick(tickValue, true, resolve, reject);
|
1755
|
+
} catch (e) {
|
1756
|
+
reject(e);
|
1757
|
+
}
|
1758
|
+
});
|
1759
|
+
});
|
1760
|
+
};
|
1761
|
+
}
|
1762
|
+
clock.next = function next() {
|
1763
|
+
runJobs(clock);
|
1764
|
+
const timer = firstTimer(clock);
|
1765
|
+
if (!timer) {
|
1766
|
+
return clock.now;
|
1767
|
+
}
|
1768
|
+
clock.duringTick = true;
|
1769
|
+
try {
|
1770
|
+
clock.now = timer.callAt;
|
1771
|
+
callTimer(clock, timer);
|
1772
|
+
runJobs(clock);
|
1773
|
+
return clock.now;
|
1774
|
+
} finally {
|
1775
|
+
clock.duringTick = false;
|
1776
|
+
}
|
1777
|
+
};
|
1778
|
+
if (typeof _global.Promise !== "undefined") {
|
1779
|
+
clock.nextAsync = function nextAsync() {
|
1780
|
+
return new _global.Promise(function(resolve, reject) {
|
1781
|
+
originalSetTimeout(function() {
|
1782
|
+
try {
|
1783
|
+
const timer = firstTimer(clock);
|
1784
|
+
if (!timer) {
|
1785
|
+
resolve(clock.now);
|
1786
|
+
return;
|
1787
|
+
}
|
1788
|
+
let err;
|
1789
|
+
clock.duringTick = true;
|
1790
|
+
clock.now = timer.callAt;
|
1791
|
+
try {
|
1792
|
+
callTimer(clock, timer);
|
1793
|
+
} catch (e) {
|
1794
|
+
err = e;
|
1795
|
+
}
|
1796
|
+
clock.duringTick = false;
|
1797
|
+
originalSetTimeout(function() {
|
1798
|
+
if (err) {
|
1799
|
+
reject(err);
|
1800
|
+
} else {
|
1801
|
+
resolve(clock.now);
|
1802
|
+
}
|
1803
|
+
});
|
1804
|
+
} catch (e) {
|
1805
|
+
reject(e);
|
1806
|
+
}
|
1807
|
+
});
|
1808
|
+
});
|
1809
|
+
};
|
1810
|
+
}
|
1811
|
+
clock.runAll = function runAll() {
|
1812
|
+
let numTimers, i;
|
1813
|
+
runJobs(clock);
|
1814
|
+
for (i = 0; i < clock.loopLimit; i++) {
|
1815
|
+
if (!clock.timers) {
|
1816
|
+
resetIsNearInfiniteLimit();
|
1817
|
+
return clock.now;
|
1818
|
+
}
|
1819
|
+
numTimers = Object.keys(clock.timers).length;
|
1820
|
+
if (numTimers === 0) {
|
1821
|
+
resetIsNearInfiniteLimit();
|
1822
|
+
return clock.now;
|
1823
|
+
}
|
1824
|
+
clock.next();
|
1825
|
+
checkIsNearInfiniteLimit(clock, i);
|
1826
|
+
}
|
1827
|
+
const excessJob = firstTimer(clock);
|
1828
|
+
throw getInfiniteLoopError(clock, excessJob);
|
1829
|
+
};
|
1830
|
+
clock.runToFrame = function runToFrame() {
|
1831
|
+
return clock.tick(getTimeToNextFrame());
|
1832
|
+
};
|
1833
|
+
if (typeof _global.Promise !== "undefined") {
|
1834
|
+
clock.runAllAsync = function runAllAsync() {
|
1835
|
+
return new _global.Promise(function(resolve, reject) {
|
1836
|
+
let i = 0;
|
1837
|
+
function doRun() {
|
1838
|
+
originalSetTimeout(function() {
|
1839
|
+
try {
|
1840
|
+
let numTimers;
|
1841
|
+
if (i < clock.loopLimit) {
|
1842
|
+
if (!clock.timers) {
|
1843
|
+
resetIsNearInfiniteLimit();
|
1844
|
+
resolve(clock.now);
|
1845
|
+
return;
|
1846
|
+
}
|
1847
|
+
numTimers = Object.keys(
|
1848
|
+
clock.timers
|
1849
|
+
).length;
|
1850
|
+
if (numTimers === 0) {
|
1851
|
+
resetIsNearInfiniteLimit();
|
1852
|
+
resolve(clock.now);
|
1853
|
+
return;
|
1854
|
+
}
|
1855
|
+
clock.next();
|
1856
|
+
i++;
|
1857
|
+
doRun();
|
1858
|
+
checkIsNearInfiniteLimit(clock, i);
|
1859
|
+
return;
|
1860
|
+
}
|
1861
|
+
const excessJob = firstTimer(clock);
|
1862
|
+
reject(getInfiniteLoopError(clock, excessJob));
|
1863
|
+
} catch (e) {
|
1864
|
+
reject(e);
|
1865
|
+
}
|
1866
|
+
});
|
1867
|
+
}
|
1868
|
+
doRun();
|
1869
|
+
});
|
1870
|
+
};
|
1871
|
+
}
|
1872
|
+
clock.runToLast = function runToLast() {
|
1873
|
+
const timer = lastTimer(clock);
|
1874
|
+
if (!timer) {
|
1875
|
+
runJobs(clock);
|
1876
|
+
return clock.now;
|
1877
|
+
}
|
1878
|
+
return clock.tick(timer.callAt - clock.now);
|
1879
|
+
};
|
1880
|
+
if (typeof _global.Promise !== "undefined") {
|
1881
|
+
clock.runToLastAsync = function runToLastAsync() {
|
1882
|
+
return new _global.Promise(function(resolve, reject) {
|
1883
|
+
originalSetTimeout(function() {
|
1884
|
+
try {
|
1885
|
+
const timer = lastTimer(clock);
|
1886
|
+
if (!timer) {
|
1887
|
+
resolve(clock.now);
|
1888
|
+
}
|
1889
|
+
resolve(clock.tickAsync(timer.callAt - clock.now));
|
1890
|
+
} catch (e) {
|
1891
|
+
reject(e);
|
1892
|
+
}
|
1893
|
+
});
|
1894
|
+
});
|
1895
|
+
};
|
1896
|
+
}
|
1897
|
+
clock.reset = function reset() {
|
1898
|
+
nanos = 0;
|
1899
|
+
clock.timers = {};
|
1900
|
+
clock.jobs = [];
|
1901
|
+
clock.now = start;
|
1902
|
+
};
|
1903
|
+
clock.setSystemTime = function setSystemTime(systemTime) {
|
1904
|
+
const newNow = getEpoch(systemTime);
|
1905
|
+
const difference = newNow - clock.now;
|
1906
|
+
let id, timer;
|
1907
|
+
adjustedSystemTime[0] = adjustedSystemTime[0] + difference;
|
1908
|
+
adjustedSystemTime[1] = adjustedSystemTime[1] + nanos;
|
1909
|
+
clock.now = newNow;
|
1910
|
+
nanos = 0;
|
1911
|
+
for (id in clock.timers) {
|
1912
|
+
if (clock.timers.hasOwnProperty(id)) {
|
1913
|
+
timer = clock.timers[id];
|
1914
|
+
timer.createdAt += difference;
|
1915
|
+
timer.callAt += difference;
|
1916
|
+
}
|
1917
|
+
}
|
1918
|
+
};
|
1919
|
+
clock.jump = function jump(tickValue) {
|
1920
|
+
const msFloat = typeof tickValue === "number" ? tickValue : parseTime(tickValue);
|
1921
|
+
const ms = Math.floor(msFloat);
|
1922
|
+
for (const timer of Object.values(clock.timers)) {
|
1923
|
+
if (clock.now + ms > timer.callAt) {
|
1924
|
+
timer.callAt = clock.now + ms;
|
1925
|
+
}
|
1926
|
+
}
|
1927
|
+
clock.tick(ms);
|
1928
|
+
};
|
1929
|
+
if (performancePresent) {
|
1930
|
+
clock.performance = /* @__PURE__ */ Object.create(null);
|
1931
|
+
clock.performance.now = fakePerformanceNow;
|
1932
|
+
}
|
1933
|
+
if (hrtimePresent) {
|
1934
|
+
clock.hrtime = hrtime;
|
1935
|
+
}
|
1936
|
+
return clock;
|
1937
|
+
}
|
1938
|
+
function install(config) {
|
1939
|
+
if (arguments.length > 1 || config instanceof Date || Array.isArray(config) || typeof config === "number") {
|
1940
|
+
throw new TypeError(
|
1941
|
+
`FakeTimers.install called with ${String(
|
1942
|
+
config
|
1943
|
+
)} install requires an object parameter`
|
1944
|
+
);
|
1945
|
+
}
|
1946
|
+
if (_global.Date.isFake === true) {
|
1947
|
+
throw new TypeError(
|
1948
|
+
"Can't install fake timers twice on the same global object."
|
1949
|
+
);
|
1950
|
+
}
|
1951
|
+
config = typeof config !== "undefined" ? config : {};
|
1952
|
+
config.shouldAdvanceTime = config.shouldAdvanceTime || false;
|
1953
|
+
config.advanceTimeDelta = config.advanceTimeDelta || 20;
|
1954
|
+
config.shouldClearNativeTimers = config.shouldClearNativeTimers || false;
|
1955
|
+
if (config.target) {
|
1956
|
+
throw new TypeError(
|
1957
|
+
"config.target is no longer supported. Use `withGlobal(target)` instead."
|
1958
|
+
);
|
1959
|
+
}
|
1960
|
+
let i, l;
|
1961
|
+
const clock = createClock(config.now, config.loopLimit);
|
1962
|
+
clock.shouldClearNativeTimers = config.shouldClearNativeTimers;
|
1963
|
+
clock.uninstall = function() {
|
1964
|
+
return uninstall(clock, config);
|
1965
|
+
};
|
1966
|
+
clock.methods = config.toFake || [];
|
1967
|
+
if (clock.methods.length === 0) {
|
1968
|
+
clock.methods = Object.keys(timers).filter(function(key) {
|
1969
|
+
return key !== "nextTick" && key !== "queueMicrotask";
|
1970
|
+
});
|
1971
|
+
}
|
1972
|
+
if (config.shouldAdvanceTime === true) {
|
1973
|
+
const intervalTick = doIntervalTick.bind(
|
1974
|
+
null,
|
1975
|
+
clock,
|
1976
|
+
config.advanceTimeDelta
|
1977
|
+
);
|
1978
|
+
const intervalId = _global.setInterval(
|
1979
|
+
intervalTick,
|
1980
|
+
config.advanceTimeDelta
|
1981
|
+
);
|
1982
|
+
clock.attachedInterval = intervalId;
|
1983
|
+
}
|
1984
|
+
if (clock.methods.includes("performance")) {
|
1985
|
+
const proto = (() => {
|
1986
|
+
if (hasPerformanceConstructorPrototype) {
|
1987
|
+
return _global.performance.constructor.prototype;
|
1988
|
+
}
|
1989
|
+
if (hasPerformancePrototype) {
|
1990
|
+
return _global.Performance.prototype;
|
1991
|
+
}
|
1992
|
+
})();
|
1993
|
+
if (proto) {
|
1994
|
+
Object.getOwnPropertyNames(proto).forEach(function(name) {
|
1995
|
+
if (name !== "now") {
|
1996
|
+
clock.performance[name] = name.indexOf("getEntries") === 0 ? NOOP_ARRAY : NOOP;
|
1997
|
+
}
|
1998
|
+
});
|
1999
|
+
} else if ((config.toFake || []).includes("performance")) {
|
2000
|
+
throw new ReferenceError(
|
2001
|
+
"non-existent performance object cannot be faked"
|
2002
|
+
);
|
2003
|
+
}
|
2004
|
+
}
|
2005
|
+
if (_global === globalObject && timersModule) {
|
2006
|
+
clock.timersModuleMethods = [];
|
2007
|
+
}
|
2008
|
+
for (i = 0, l = clock.methods.length; i < l; i++) {
|
2009
|
+
const nameOfMethodToReplace = clock.methods[i];
|
2010
|
+
if (nameOfMethodToReplace === "hrtime") {
|
2011
|
+
if (_global.process && typeof _global.process.hrtime === "function") {
|
2012
|
+
hijackMethod(_global.process, nameOfMethodToReplace, clock);
|
2013
|
+
}
|
2014
|
+
} else if (nameOfMethodToReplace === "nextTick") {
|
2015
|
+
if (_global.process && typeof _global.process.nextTick === "function") {
|
2016
|
+
hijackMethod(_global.process, nameOfMethodToReplace, clock);
|
2017
|
+
}
|
2018
|
+
} else {
|
2019
|
+
hijackMethod(_global, nameOfMethodToReplace, clock);
|
2020
|
+
}
|
2021
|
+
if (clock.timersModuleMethods !== void 0 && timersModule[nameOfMethodToReplace]) {
|
2022
|
+
const original = timersModule[nameOfMethodToReplace];
|
2023
|
+
clock.timersModuleMethods.push({
|
2024
|
+
methodName: nameOfMethodToReplace,
|
2025
|
+
original
|
2026
|
+
});
|
2027
|
+
timersModule[nameOfMethodToReplace] = _global[nameOfMethodToReplace];
|
2028
|
+
}
|
2029
|
+
}
|
2030
|
+
return clock;
|
2031
|
+
}
|
2032
|
+
return {
|
2033
|
+
timers,
|
2034
|
+
createClock,
|
2035
|
+
install,
|
2036
|
+
withGlobal
|
2037
|
+
};
|
2038
|
+
}
|
2039
|
+
var defaultImplementation = withGlobal(globalObject);
|
2040
|
+
defaultImplementation.timers;
|
2041
|
+
defaultImplementation.createClock;
|
2042
|
+
defaultImplementation.install;
|
2043
|
+
var withGlobal_1 = withGlobal;
|
2044
|
+
var FakeTimers = class {
|
2045
|
+
_global;
|
2046
|
+
_clock;
|
2047
|
+
_fakingTime;
|
2048
|
+
_fakingDate;
|
2049
|
+
_fakeTimers;
|
2050
|
+
_userConfig;
|
2051
|
+
_now = RealDate.now;
|
2052
|
+
constructor({
|
2053
|
+
global: global3,
|
2054
|
+
config
|
2055
|
+
}) {
|
2056
|
+
this._userConfig = config;
|
2057
|
+
this._fakingDate = false;
|
2058
|
+
this._fakingTime = false;
|
2059
|
+
this._fakeTimers = withGlobal_1(global3);
|
2060
|
+
this._global = global3;
|
2061
|
+
}
|
2062
|
+
clearAllTimers() {
|
2063
|
+
if (this._fakingTime)
|
2064
|
+
this._clock.reset();
|
2065
|
+
}
|
2066
|
+
dispose() {
|
2067
|
+
this.useRealTimers();
|
2068
|
+
}
|
2069
|
+
runAllTimers() {
|
2070
|
+
if (this._checkFakeTimers())
|
2071
|
+
this._clock.runAll();
|
2072
|
+
}
|
2073
|
+
async runAllTimersAsync() {
|
2074
|
+
if (this._checkFakeTimers())
|
2075
|
+
await this._clock.runAllAsync();
|
2076
|
+
}
|
2077
|
+
runOnlyPendingTimers() {
|
2078
|
+
if (this._checkFakeTimers())
|
2079
|
+
this._clock.runToLast();
|
2080
|
+
}
|
2081
|
+
async runOnlyPendingTimersAsync() {
|
2082
|
+
if (this._checkFakeTimers())
|
2083
|
+
await this._clock.runToLastAsync();
|
2084
|
+
}
|
2085
|
+
advanceTimersToNextTimer(steps = 1) {
|
2086
|
+
if (this._checkFakeTimers()) {
|
2087
|
+
for (let i = steps; i > 0; i--) {
|
2088
|
+
this._clock.next();
|
2089
|
+
this._clock.tick(0);
|
2090
|
+
if (this._clock.countTimers() === 0)
|
2091
|
+
break;
|
2092
|
+
}
|
2093
|
+
}
|
2094
|
+
}
|
2095
|
+
async advanceTimersToNextTimerAsync(steps = 1) {
|
2096
|
+
if (this._checkFakeTimers()) {
|
2097
|
+
for (let i = steps; i > 0; i--) {
|
2098
|
+
await this._clock.nextAsync();
|
2099
|
+
this._clock.tick(0);
|
2100
|
+
if (this._clock.countTimers() === 0)
|
2101
|
+
break;
|
2102
|
+
}
|
2103
|
+
}
|
2104
|
+
}
|
2105
|
+
advanceTimersByTime(msToRun) {
|
2106
|
+
if (this._checkFakeTimers())
|
2107
|
+
this._clock.tick(msToRun);
|
2108
|
+
}
|
2109
|
+
async advanceTimersByTimeAsync(msToRun) {
|
2110
|
+
if (this._checkFakeTimers())
|
2111
|
+
await this._clock.tickAsync(msToRun);
|
2112
|
+
}
|
2113
|
+
runAllTicks() {
|
2114
|
+
if (this._checkFakeTimers()) {
|
2115
|
+
this._clock.runMicrotasks();
|
2116
|
+
}
|
2117
|
+
}
|
2118
|
+
useRealTimers() {
|
2119
|
+
if (this._fakingDate) {
|
2120
|
+
resetDate();
|
2121
|
+
this._fakingDate = false;
|
2122
|
+
}
|
2123
|
+
if (this._fakingTime) {
|
2124
|
+
this._clock.uninstall();
|
2125
|
+
this._fakingTime = false;
|
2126
|
+
}
|
2127
|
+
}
|
2128
|
+
useFakeTimers() {
|
2129
|
+
var _a, _b, _c;
|
2130
|
+
if (this._fakingDate) {
|
2131
|
+
throw new Error(
|
2132
|
+
'"setSystemTime" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.'
|
2133
|
+
);
|
2134
|
+
}
|
2135
|
+
if (!this._fakingTime) {
|
2136
|
+
const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick");
|
2137
|
+
if (((_b = (_a = this._userConfig) == null ? void 0 : _a.toFake) == null ? void 0 : _b.includes("nextTick")) && isChildProcess())
|
2138
|
+
throw new Error("process.nextTick cannot be mocked inside child_process");
|
2139
|
+
const existingFakedMethods = (((_c = this._userConfig) == null ? void 0 : _c.toFake) || toFake).filter((method) => {
|
2140
|
+
switch (method) {
|
2141
|
+
case "setImmediate":
|
2142
|
+
case "clearImmediate":
|
2143
|
+
return method in this._global && this._global[method];
|
2144
|
+
default:
|
2145
|
+
return true;
|
2146
|
+
}
|
2147
|
+
});
|
2148
|
+
this._clock = this._fakeTimers.install({
|
2149
|
+
now: Date.now(),
|
2150
|
+
...this._userConfig,
|
2151
|
+
toFake: existingFakedMethods
|
2152
|
+
});
|
2153
|
+
this._fakingTime = true;
|
2154
|
+
}
|
2155
|
+
}
|
2156
|
+
reset() {
|
2157
|
+
if (this._checkFakeTimers()) {
|
2158
|
+
const { now: now2 } = this._clock;
|
2159
|
+
this._clock.reset();
|
2160
|
+
this._clock.setSystemTime(now2);
|
2161
|
+
}
|
2162
|
+
}
|
2163
|
+
setSystemTime(now2) {
|
2164
|
+
if (this._fakingTime) {
|
2165
|
+
this._clock.setSystemTime(now2);
|
2166
|
+
} else {
|
2167
|
+
mockDate(now2 ?? this.getRealSystemTime());
|
2168
|
+
this._fakingDate = true;
|
2169
|
+
}
|
2170
|
+
}
|
2171
|
+
getRealSystemTime() {
|
2172
|
+
return this._now();
|
2173
|
+
}
|
2174
|
+
getTimerCount() {
|
2175
|
+
if (this._checkFakeTimers())
|
2176
|
+
return this._clock.countTimers();
|
2177
|
+
return 0;
|
2178
|
+
}
|
2179
|
+
configure(config) {
|
2180
|
+
this._userConfig = config;
|
2181
|
+
}
|
2182
|
+
isFakeTimers() {
|
2183
|
+
return this._fakingTime;
|
2184
|
+
}
|
2185
|
+
_checkFakeTimers() {
|
2186
|
+
if (!this._fakingTime) {
|
2187
|
+
throw new Error(
|
2188
|
+
'Timers are not mocked. Try calling "vi.useFakeTimers()" first.'
|
2189
|
+
);
|
2190
|
+
}
|
2191
|
+
return this._fakingTime;
|
2192
|
+
}
|
2193
|
+
};
|
2194
|
+
function copyStackTrace(target, source) {
|
2195
|
+
if (source.stack !== void 0)
|
2196
|
+
target.stack = source.stack.replace(source.message, target.message);
|
2197
|
+
return target;
|
2198
|
+
}
|
2199
|
+
function waitFor(callback, options = {}) {
|
2200
|
+
const { setTimeout, setInterval, clearTimeout, clearInterval } = (0, import_utils9.getSafeTimers)();
|
2201
|
+
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
2202
|
+
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
2203
|
+
return new Promise((resolve, reject) => {
|
2204
|
+
let lastError;
|
2205
|
+
let promiseStatus = "idle";
|
2206
|
+
let timeoutId;
|
2207
|
+
let intervalId;
|
2208
|
+
const onResolve = (result) => {
|
2209
|
+
if (timeoutId)
|
2210
|
+
clearTimeout(timeoutId);
|
2211
|
+
if (intervalId)
|
2212
|
+
clearInterval(intervalId);
|
2213
|
+
resolve(result);
|
2214
|
+
};
|
2215
|
+
const handleTimeout = () => {
|
2216
|
+
let error = lastError;
|
2217
|
+
if (!error)
|
2218
|
+
error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
|
2219
|
+
reject(error);
|
2220
|
+
};
|
2221
|
+
const checkCallback = () => {
|
2222
|
+
if (vi.isFakeTimers())
|
2223
|
+
vi.advanceTimersByTime(interval);
|
2224
|
+
if (promiseStatus === "pending")
|
2225
|
+
return;
|
2226
|
+
try {
|
2227
|
+
const result = callback();
|
2228
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
2229
|
+
const thenable = result;
|
2230
|
+
promiseStatus = "pending";
|
2231
|
+
thenable.then(
|
2232
|
+
(resolvedValue) => {
|
2233
|
+
promiseStatus = "resolved";
|
2234
|
+
onResolve(resolvedValue);
|
2235
|
+
},
|
2236
|
+
(rejectedValue) => {
|
2237
|
+
promiseStatus = "rejected";
|
2238
|
+
lastError = rejectedValue;
|
2239
|
+
}
|
2240
|
+
);
|
2241
|
+
} else {
|
2242
|
+
onResolve(result);
|
2243
|
+
return true;
|
2244
|
+
}
|
2245
|
+
} catch (error) {
|
2246
|
+
lastError = error;
|
2247
|
+
}
|
2248
|
+
};
|
2249
|
+
if (checkCallback() === true)
|
2250
|
+
return;
|
2251
|
+
timeoutId = setTimeout(handleTimeout, timeout);
|
2252
|
+
intervalId = setInterval(checkCallback, interval);
|
2253
|
+
});
|
2254
|
+
}
|
2255
|
+
function waitUntil(callback, options = {}) {
|
2256
|
+
const { setTimeout, setInterval, clearTimeout, clearInterval } = (0, import_utils9.getSafeTimers)();
|
2257
|
+
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
2258
|
+
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
2259
|
+
return new Promise((resolve, reject) => {
|
2260
|
+
let promiseStatus = "idle";
|
2261
|
+
let timeoutId;
|
2262
|
+
let intervalId;
|
2263
|
+
const onReject = (error) => {
|
2264
|
+
if (!error)
|
2265
|
+
error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
|
2266
|
+
reject(error);
|
2267
|
+
};
|
2268
|
+
const onResolve = (result) => {
|
2269
|
+
if (!result)
|
2270
|
+
return;
|
2271
|
+
if (timeoutId)
|
2272
|
+
clearTimeout(timeoutId);
|
2273
|
+
if (intervalId)
|
2274
|
+
clearInterval(intervalId);
|
2275
|
+
resolve(result);
|
2276
|
+
return true;
|
2277
|
+
};
|
2278
|
+
const checkCallback = () => {
|
2279
|
+
if (vi.isFakeTimers())
|
2280
|
+
vi.advanceTimersByTime(interval);
|
2281
|
+
if (promiseStatus === "pending")
|
2282
|
+
return;
|
2283
|
+
try {
|
2284
|
+
const result = callback();
|
2285
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
2286
|
+
const thenable = result;
|
2287
|
+
promiseStatus = "pending";
|
2288
|
+
thenable.then(
|
2289
|
+
(resolvedValue) => {
|
2290
|
+
promiseStatus = "resolved";
|
2291
|
+
onResolve(resolvedValue);
|
2292
|
+
},
|
2293
|
+
(rejectedValue) => {
|
2294
|
+
promiseStatus = "rejected";
|
2295
|
+
onReject(rejectedValue);
|
2296
|
+
}
|
2297
|
+
);
|
2298
|
+
} else {
|
2299
|
+
return onResolve(result);
|
2300
|
+
}
|
2301
|
+
} catch (error) {
|
2302
|
+
onReject(error);
|
2303
|
+
}
|
2304
|
+
};
|
2305
|
+
if (checkCallback() === true)
|
2306
|
+
return;
|
2307
|
+
timeoutId = setTimeout(onReject, timeout);
|
2308
|
+
intervalId = setInterval(checkCallback, interval);
|
2309
|
+
});
|
2310
|
+
}
|
2311
|
+
function createVitest() {
|
2312
|
+
const _mocker = typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, {
|
2313
|
+
get(_, name) {
|
2314
|
+
throw new Error(
|
2315
|
+
`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
|
2316
|
+
);
|
2317
|
+
}
|
2318
|
+
});
|
2319
|
+
let _mockedDate = null;
|
2320
|
+
let _config = null;
|
2321
|
+
const workerState = getWorkerState();
|
2322
|
+
let _timers;
|
2323
|
+
const timers = () => _timers || (_timers = new FakeTimers({
|
2324
|
+
global: globalThis,
|
2325
|
+
config: workerState.config.fakeTimers
|
2326
|
+
}));
|
2327
|
+
const _stubsGlobal = /* @__PURE__ */ new Map();
|
2328
|
+
const _stubsEnv = /* @__PURE__ */ new Map();
|
2329
|
+
const _envBooleans = ["PROD", "DEV", "SSR"];
|
2330
|
+
const getImporter = () => {
|
2331
|
+
const stackTrace = (0, import_utils9.createSimpleStackTrace)({ stackTraceLimit: 4 });
|
2332
|
+
const importerStack = stackTrace.split("\n")[4];
|
2333
|
+
const stack = (0, import_source_map.parseSingleStack)(importerStack);
|
2334
|
+
return (stack == null ? void 0 : stack.file) || "";
|
2335
|
+
};
|
2336
|
+
const utils = {
|
2337
|
+
useFakeTimers(config) {
|
2338
|
+
var _a, _b, _c, _d;
|
2339
|
+
if (isChildProcess()) {
|
2340
|
+
if (((_a = config == null ? void 0 : config.toFake) == null ? void 0 : _a.includes("nextTick")) || ((_d = (_c = (_b = workerState.config) == null ? void 0 : _b.fakeTimers) == null ? void 0 : _c.toFake) == null ? void 0 : _d.includes("nextTick"))) {
|
2341
|
+
throw new Error(
|
2342
|
+
'vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.'
|
2343
|
+
);
|
2344
|
+
}
|
2345
|
+
}
|
2346
|
+
if (config)
|
2347
|
+
timers().configure({ ...workerState.config.fakeTimers, ...config });
|
2348
|
+
else
|
2349
|
+
timers().configure(workerState.config.fakeTimers);
|
2350
|
+
timers().useFakeTimers();
|
2351
|
+
return utils;
|
2352
|
+
},
|
2353
|
+
isFakeTimers() {
|
2354
|
+
return timers().isFakeTimers();
|
2355
|
+
},
|
2356
|
+
useRealTimers() {
|
2357
|
+
timers().useRealTimers();
|
2358
|
+
_mockedDate = null;
|
2359
|
+
return utils;
|
2360
|
+
},
|
2361
|
+
runOnlyPendingTimers() {
|
2362
|
+
timers().runOnlyPendingTimers();
|
2363
|
+
return utils;
|
2364
|
+
},
|
2365
|
+
async runOnlyPendingTimersAsync() {
|
2366
|
+
await timers().runOnlyPendingTimersAsync();
|
2367
|
+
return utils;
|
2368
|
+
},
|
2369
|
+
runAllTimers() {
|
2370
|
+
timers().runAllTimers();
|
2371
|
+
return utils;
|
2372
|
+
},
|
2373
|
+
async runAllTimersAsync() {
|
2374
|
+
await timers().runAllTimersAsync();
|
2375
|
+
return utils;
|
2376
|
+
},
|
2377
|
+
runAllTicks() {
|
2378
|
+
timers().runAllTicks();
|
2379
|
+
return utils;
|
2380
|
+
},
|
2381
|
+
advanceTimersByTime(ms) {
|
2382
|
+
timers().advanceTimersByTime(ms);
|
2383
|
+
return utils;
|
2384
|
+
},
|
2385
|
+
async advanceTimersByTimeAsync(ms) {
|
2386
|
+
await timers().advanceTimersByTimeAsync(ms);
|
2387
|
+
return utils;
|
2388
|
+
},
|
2389
|
+
advanceTimersToNextTimer() {
|
2390
|
+
timers().advanceTimersToNextTimer();
|
2391
|
+
return utils;
|
2392
|
+
},
|
2393
|
+
async advanceTimersToNextTimerAsync() {
|
2394
|
+
await timers().advanceTimersToNextTimerAsync();
|
2395
|
+
return utils;
|
2396
|
+
},
|
2397
|
+
getTimerCount() {
|
2398
|
+
return timers().getTimerCount();
|
2399
|
+
},
|
2400
|
+
setSystemTime(time) {
|
2401
|
+
const date = time instanceof Date ? time : new Date(time);
|
2402
|
+
_mockedDate = date;
|
2403
|
+
timers().setSystemTime(date);
|
2404
|
+
return utils;
|
2405
|
+
},
|
2406
|
+
getMockedSystemTime() {
|
2407
|
+
return _mockedDate;
|
2408
|
+
},
|
2409
|
+
getRealSystemTime() {
|
2410
|
+
return timers().getRealSystemTime();
|
2411
|
+
},
|
2412
|
+
clearAllTimers() {
|
2413
|
+
timers().clearAllTimers();
|
2414
|
+
return utils;
|
2415
|
+
},
|
2416
|
+
// mocks
|
2417
|
+
spyOn: import_spy.spyOn,
|
2418
|
+
fn: import_spy.fn,
|
2419
|
+
waitFor,
|
2420
|
+
waitUntil,
|
2421
|
+
hoisted(factory) {
|
2422
|
+
(0, import_utils9.assertTypes)(factory, '"vi.hoisted" factory', ["function"]);
|
2423
|
+
return factory();
|
2424
|
+
},
|
2425
|
+
mock(path, factory) {
|
2426
|
+
const importer = getImporter();
|
2427
|
+
_mocker.queueMock(
|
2428
|
+
path,
|
2429
|
+
importer,
|
2430
|
+
factory ? () => factory(() => _mocker.importActual(path, importer, _mocker.getMockContext().callstack)) : void 0,
|
2431
|
+
true
|
2432
|
+
);
|
2433
|
+
},
|
2434
|
+
unmock(path) {
|
2435
|
+
_mocker.queueUnmock(path, getImporter());
|
2436
|
+
},
|
2437
|
+
doMock(path, factory) {
|
2438
|
+
const importer = getImporter();
|
2439
|
+
_mocker.queueMock(
|
2440
|
+
path,
|
2441
|
+
importer,
|
2442
|
+
factory ? () => factory(() => _mocker.importActual(path, importer, _mocker.getMockContext().callstack)) : void 0,
|
2443
|
+
false
|
2444
|
+
);
|
2445
|
+
},
|
2446
|
+
doUnmock(path) {
|
2447
|
+
_mocker.queueUnmock(path, getImporter());
|
2448
|
+
},
|
2449
|
+
async importActual(path) {
|
2450
|
+
return _mocker.importActual(
|
2451
|
+
path,
|
2452
|
+
getImporter(),
|
2453
|
+
_mocker.getMockContext().callstack
|
2454
|
+
);
|
2455
|
+
},
|
2456
|
+
async importMock(path) {
|
2457
|
+
return _mocker.importMock(path, getImporter());
|
2458
|
+
},
|
2459
|
+
// this is typed in the interface so it's not necessary to type it here
|
2460
|
+
mocked(item, _options = {}) {
|
2461
|
+
return item;
|
2462
|
+
},
|
2463
|
+
isMockFunction(fn2) {
|
2464
|
+
return (0, import_spy.isMockFunction)(fn2);
|
2465
|
+
},
|
2466
|
+
clearAllMocks() {
|
2467
|
+
import_spy.mocks.forEach((spy) => spy.mockClear());
|
2468
|
+
return utils;
|
2469
|
+
},
|
2470
|
+
resetAllMocks() {
|
2471
|
+
import_spy.mocks.forEach((spy) => spy.mockReset());
|
2472
|
+
return utils;
|
2473
|
+
},
|
2474
|
+
restoreAllMocks() {
|
2475
|
+
import_spy.mocks.forEach((spy) => spy.mockRestore());
|
2476
|
+
return utils;
|
2477
|
+
},
|
2478
|
+
stubGlobal(name, value) {
|
2479
|
+
if (!_stubsGlobal.has(name))
|
2480
|
+
_stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
|
2481
|
+
Object.defineProperty(globalThis, name, {
|
2482
|
+
value,
|
2483
|
+
writable: true,
|
2484
|
+
configurable: true,
|
2485
|
+
enumerable: true
|
2486
|
+
});
|
2487
|
+
return utils;
|
2488
|
+
},
|
2489
|
+
stubEnv(name, value) {
|
2490
|
+
if (!_stubsEnv.has(name))
|
2491
|
+
_stubsEnv.set(name, process.env[name]);
|
2492
|
+
if (_envBooleans.includes(name))
|
2493
|
+
process.env[name] = value ? "1" : "";
|
2494
|
+
else
|
2495
|
+
process.env[name] = String(value);
|
2496
|
+
return utils;
|
2497
|
+
},
|
2498
|
+
unstubAllGlobals() {
|
2499
|
+
_stubsGlobal.forEach((original, name) => {
|
2500
|
+
if (!original)
|
2501
|
+
Reflect.deleteProperty(globalThis, name);
|
2502
|
+
else
|
2503
|
+
Object.defineProperty(globalThis, name, original);
|
2504
|
+
});
|
2505
|
+
_stubsGlobal.clear();
|
2506
|
+
return utils;
|
2507
|
+
},
|
2508
|
+
unstubAllEnvs() {
|
2509
|
+
_stubsEnv.forEach((original, name) => {
|
2510
|
+
if (original === void 0)
|
2511
|
+
delete process.env[name];
|
2512
|
+
else
|
2513
|
+
process.env[name] = original;
|
2514
|
+
});
|
2515
|
+
_stubsEnv.clear();
|
2516
|
+
return utils;
|
2517
|
+
},
|
2518
|
+
resetModules() {
|
2519
|
+
resetModules(workerState.moduleCache);
|
2520
|
+
return utils;
|
2521
|
+
},
|
2522
|
+
async dynamicImportSettled() {
|
2523
|
+
return waitForImportsToResolve();
|
2524
|
+
},
|
2525
|
+
setConfig(config) {
|
2526
|
+
if (!_config)
|
2527
|
+
_config = { ...workerState.config };
|
2528
|
+
Object.assign(workerState.config, config);
|
2529
|
+
},
|
2530
|
+
resetConfig() {
|
2531
|
+
if (_config)
|
2532
|
+
Object.assign(workerState.config, _config);
|
2533
|
+
}
|
2534
|
+
};
|
2535
|
+
return utils;
|
2536
|
+
}
|
2537
|
+
var vitest = createVitest();
|
2538
|
+
var vi = vitest;
|
2539
|
+
|
2540
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/vendor/index.dI9lHwVn.js
|
2541
|
+
var import_runner3 = require("@vitest/runner.js");
|
2542
|
+
var chai2 = __toESM(require("chai.js"), 1);
|
2543
|
+
var import_chai = require("chai.js");
|
2544
|
+
function getRunningMode() {
|
2545
|
+
return process.env.VITEST_MODE === "WATCH" ? "watch" : "run";
|
2546
|
+
}
|
2547
|
+
function isWatchMode() {
|
2548
|
+
return getRunningMode() === "watch";
|
2549
|
+
}
|
2550
|
+
function inject(key) {
|
2551
|
+
const workerState = getWorkerState();
|
2552
|
+
return workerState.providedContext[key];
|
2553
|
+
}
|
2554
|
+
var dist = {};
|
2555
|
+
(function(exports2) {
|
2556
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
2557
|
+
exports2.expectTypeOf = void 0;
|
2558
|
+
const fn2 = () => true;
|
2559
|
+
const expectTypeOf2 = (_actual) => {
|
2560
|
+
const nonFunctionProperties = [
|
2561
|
+
"parameters",
|
2562
|
+
"returns",
|
2563
|
+
"resolves",
|
2564
|
+
"not",
|
2565
|
+
"items",
|
2566
|
+
"constructorParameters",
|
2567
|
+
"thisParameter",
|
2568
|
+
"instance",
|
2569
|
+
"guards",
|
2570
|
+
"asserts",
|
2571
|
+
"branded"
|
2572
|
+
];
|
2573
|
+
const obj = {
|
2574
|
+
/* eslint-disable mmkal/@typescript-eslint/no-unsafe-assignment */
|
2575
|
+
toBeAny: fn2,
|
2576
|
+
toBeUnknown: fn2,
|
2577
|
+
toBeNever: fn2,
|
2578
|
+
toBeFunction: fn2,
|
2579
|
+
toBeObject: fn2,
|
2580
|
+
toBeArray: fn2,
|
2581
|
+
toBeString: fn2,
|
2582
|
+
toBeNumber: fn2,
|
2583
|
+
toBeBoolean: fn2,
|
2584
|
+
toBeVoid: fn2,
|
2585
|
+
toBeSymbol: fn2,
|
2586
|
+
toBeNull: fn2,
|
2587
|
+
toBeUndefined: fn2,
|
2588
|
+
toBeNullable: fn2,
|
2589
|
+
toMatchTypeOf: fn2,
|
2590
|
+
toEqualTypeOf: fn2,
|
2591
|
+
toBeCallableWith: fn2,
|
2592
|
+
toBeConstructibleWith: fn2,
|
2593
|
+
/* eslint-enable mmkal/@typescript-eslint/no-unsafe-assignment */
|
2594
|
+
extract: exports2.expectTypeOf,
|
2595
|
+
exclude: exports2.expectTypeOf,
|
2596
|
+
toHaveProperty: exports2.expectTypeOf,
|
2597
|
+
parameter: exports2.expectTypeOf
|
2598
|
+
};
|
2599
|
+
const getterProperties = nonFunctionProperties;
|
2600
|
+
getterProperties.forEach((prop) => Object.defineProperty(obj, prop, { get: () => (0, exports2.expectTypeOf)({}) }));
|
2601
|
+
return obj;
|
2602
|
+
};
|
2603
|
+
exports2.expectTypeOf = expectTypeOf2;
|
2604
|
+
})(dist);
|
2605
|
+
function noop2() {
|
2606
|
+
}
|
2607
|
+
var assertType = noop2;
|
2608
|
+
var VitestIndex = /* @__PURE__ */ Object.freeze({
|
2609
|
+
__proto__: null,
|
2610
|
+
afterAll: import_runner3.afterAll,
|
2611
|
+
afterEach: import_runner3.afterEach,
|
2612
|
+
assert: import_chai.assert,
|
2613
|
+
assertType,
|
2614
|
+
beforeAll: import_runner3.beforeAll,
|
2615
|
+
beforeEach: import_runner3.beforeEach,
|
2616
|
+
bench,
|
2617
|
+
chai: chai2,
|
2618
|
+
createExpect,
|
2619
|
+
describe: import_runner3.describe,
|
2620
|
+
expect: globalExpect,
|
2621
|
+
expectTypeOf: dist.expectTypeOf,
|
2622
|
+
getRunningMode,
|
2623
|
+
inject,
|
2624
|
+
isFirstRun,
|
2625
|
+
isWatchMode,
|
2626
|
+
it: import_runner3.it,
|
2627
|
+
onTestFailed: import_runner3.onTestFailed,
|
2628
|
+
onTestFinished: import_runner3.onTestFinished,
|
2629
|
+
runOnce,
|
2630
|
+
should: import_chai.should,
|
2631
|
+
suite: import_runner3.suite,
|
2632
|
+
test: import_runner3.test,
|
2633
|
+
vi,
|
2634
|
+
vitest
|
2635
|
+
});
|
2636
|
+
|
2637
|
+
// ../../node_modules/.pnpm/vitest@1.6.1_@types+node@22.13.1_lightningcss@1.29.1_terser@5.38.1/node_modules/vitest/dist/index.js
|
2638
|
+
var chai3 = __toESM(require("chai.js"), 1);
|
2639
|
+
var import_chai2 = require("chai.js");
|
2640
|
+
var import_utils10 = require("@vitest/runner/utils.js");
|
2641
|
+
var import_utils11 = require("@vitest/utils.js");
|
2642
|
+
var import_pathe2 = require("pathe.js");
|
2643
|
+
var import_std_env = require("std-env.js");
|
2644
|
+
var import_expect2 = require("@vitest/expect.js");
|
2645
|
+
var import_snapshot2 = require("@vitest/snapshot.js");
|
2646
|
+
var import_error2 = require("@vitest/utils/error.js");
|
2647
|
+
var import_source_map2 = require("@vitest/utils/source-map.js");
|
2648
|
+
var import_spy2 = require("@vitest/spy.js");
|
2649
|
+
var expectTypeOf = dist.expectTypeOf;
|
2650
|
+
|
2651
|
+
// src/tests/setup.ts
|
2652
|
+
var OriginalDate = global.Date;
|
2653
|
+
var fixedDate = new OriginalDate("2023-01-01");
|
2654
|
+
global.Date = vi.fn(() => fixedDate);
|
2655
|
+
global.Date.now = vi.fn(() => fixedDate.getTime());
|
2656
|
+
//# sourceMappingURL=setup.js.map
|