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