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

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