@assistant-ui/react 0.8.17 → 0.8.19

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