@noma.to/qwik-testing-library 1.3.0 → 1.3.2

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