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