@accelint/design-system 1.1.4 → 1.1.6
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/components/button/button.css.d.ts +1 -0
- package/dist/components/button/index.d.ts +9 -40
- package/dist/components/button/index.js +23 -17
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button/types.d.ts +3 -2
- package/dist/components/collection/index.d.ts +2 -2
- package/dist/components/collection/index.js.map +1 -1
- package/dist/components/date-input/index.js +4 -1
- package/dist/components/date-input/index.js.map +1 -1
- package/dist/components/dialog/dialog.css.d.ts +1 -0
- package/dist/components/dialog/index.d.ts +1 -0
- package/dist/components/dialog/types.d.ts +1 -0
- package/dist/components/drawer/drawer.css.d.ts +1 -1
- package/dist/components/drawer/index.d.ts +1 -1
- package/dist/components/drawer/types.d.ts +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/menu/index.d.ts +2 -2
- package/dist/components/menu/index.js +1 -1
- package/dist/components/menu/index.js.map +1 -1
- package/dist/components/merge-provider/index.js +15 -7
- package/dist/components/merge-provider/index.js.map +1 -1
- package/dist/components/number-field/index.d.ts +1 -1
- package/dist/components/number-field/number-field.css.d.ts +1 -1
- package/dist/components/number-field/types.d.ts +1 -1
- package/dist/components/options/index.js +1 -1
- package/dist/components/options/index.js.map +1 -1
- package/dist/components/picker/index.js.map +1 -1
- package/dist/components/text-field/index.d.ts +3 -128
- package/dist/components/text-field/index.js +3 -3
- package/dist/components/text-field/index.js.map +1 -1
- package/dist/components/tree/index.js +5 -2
- package/dist/components/tree/index.js.map +1 -1
- package/dist/hooks/index.d.ts +11 -11
- package/dist/hooks/use-collection-render/index.d.ts +1 -1
- package/dist/hooks/use-collection-render/index.js +2 -3
- package/dist/hooks/use-collection-render/index.js.map +1 -1
- package/dist/hooks/use-context-props/index.js.map +1 -1
- package/dist/hooks/use-defaults/index.d.ts +32 -80
- package/dist/hooks/use-defaults/index.js +1 -4
- package/dist/hooks/use-defaults/index.js.map +1 -1
- package/dist/hooks/use-defaults/types.d.ts +1 -1
- package/dist/hooks/use-theme/index.d.ts +1 -1
- package/dist/hooks/use-theme/types.d.ts +1 -1
- package/dist/hooks/use-tree/index.js +3 -2
- package/dist/hooks/use-tree/index.js.map +1 -1
- package/dist/hooks/use-tree/utils.js +6 -9
- package/dist/hooks/use-tree/utils.js.map +1 -1
- package/dist/hooks/use-update-effect/index.js.map +1 -1
- package/dist/index.css +32 -32
- package/dist/index.d.ts +5 -5
- package/dist/ladle/actions.js.map +1 -1
- package/dist/test/setup.js +630 -1249
- package/dist/test/setup.js.map +1 -1
- package/dist/utils/props/index.d.ts +1 -2
- package/dist/utils/props/index.js.map +1 -1
- package/package.json +29 -29
package/dist/test/setup.js
CHANGED
|
@@ -12,16 +12,18 @@ import 'react-dom';
|
|
|
12
12
|
import 'react-dom/client';
|
|
13
13
|
import * as prettyFormat from 'pretty-format.js';
|
|
14
14
|
import lzString from 'lz-string.js';
|
|
15
|
-
import { JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, equals, iterableEquality, subsetEquality } from '@vitest/expect.js';
|
|
15
|
+
import { chai, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers, equals, iterableEquality, subsetEquality } from '@vitest/expect.js';
|
|
16
16
|
import { afterEach as afterEach$1, getCurrentTest } from '@vitest/runner.js';
|
|
17
|
+
import { getSafeTimers, delay } from '@vitest/utils/timers.js';
|
|
17
18
|
import { getNames } from '@vitest/runner/utils.js';
|
|
18
|
-
import * as chai$1 from 'chai.js';
|
|
19
|
-
import { assertTypes, getSafeTimers, createSimpleStackTrace } from '@vitest/utils.js';
|
|
20
19
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot.js';
|
|
21
20
|
import '@vitest/utils/error.js';
|
|
22
|
-
import
|
|
23
|
-
import
|
|
21
|
+
import '@vitest/utils/helpers.js';
|
|
22
|
+
import '@vitest/spy.js';
|
|
23
|
+
import '@vitest/utils/offset.js';
|
|
24
|
+
import '@vitest/utils/source-map.js';
|
|
24
25
|
import 'expect-type.js';
|
|
26
|
+
import 'pathe.js';
|
|
25
27
|
|
|
26
28
|
// ../node_modules/.pnpm/@testing-library+jest-dom@6.6.3/node_modules/@testing-library/jest-dom/dist/matchers.mjs
|
|
27
29
|
var matchers_exports = {};
|
|
@@ -3877,7 +3879,7 @@ typeof document !== "undefined" && document.body ? getQueriesForElement(document
|
|
|
3877
3879
|
return helpers;
|
|
3878
3880
|
}, initialValue);
|
|
3879
3881
|
|
|
3880
|
-
// ../node_modules/.pnpm/@testing-library+react@16.3.0_@testing-library+dom@10.4.0_@types+react-dom@19.
|
|
3882
|
+
// ../node_modules/.pnpm/@testing-library+react@16.3.0_@testing-library+dom@10.4.0_@types+react-dom@19.0.0_@type_c73dee9f0e611c0cf8e2f38a680966d7/node_modules/@testing-library/react/dist/@testing-library/react.esm.js
|
|
3881
3883
|
var reactAct = typeof React.act === "function" ? React.act : DeprecatedReactTestUtils.act;
|
|
3882
3884
|
function getGlobalThis() {
|
|
3883
3885
|
if (typeof globalThis !== "undefined") {
|
|
@@ -4025,82 +4027,22 @@ if (typeof process === "undefined" || !process.env?.RTL_SKIP_AUTO_CLEANUP) {
|
|
|
4025
4027
|
var NAME_WORKER_STATE = "__vitest_worker__";
|
|
4026
4028
|
function getWorkerState() {
|
|
4027
4029
|
const workerState = globalThis[NAME_WORKER_STATE];
|
|
4028
|
-
if (!workerState)
|
|
4029
|
-
const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
|
|
4030
|
-
throw new Error(errorMsg);
|
|
4031
|
-
}
|
|
4030
|
+
if (!workerState) throw new Error('Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- "vitest" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n');
|
|
4032
4031
|
return workerState;
|
|
4033
4032
|
}
|
|
4034
|
-
function getCurrentEnvironment() {
|
|
4035
|
-
const state = getWorkerState();
|
|
4036
|
-
return state?.environment.name;
|
|
4037
|
-
}
|
|
4038
|
-
function isChildProcess() {
|
|
4039
|
-
return typeof process !== "undefined" && !!process.send;
|
|
4040
|
-
}
|
|
4041
|
-
function resetModules(modules, resetMocks = false) {
|
|
4042
|
-
const skipPaths = [
|
|
4043
|
-
// Vitest
|
|
4044
|
-
/\/vitest\/dist\//,
|
|
4045
|
-
/\/vite-node\/dist\//,
|
|
4046
|
-
// yarn's .store folder
|
|
4047
|
-
/vitest-virtual-\w+\/dist/,
|
|
4048
|
-
// cnpm
|
|
4049
|
-
/@vitest\/dist/,
|
|
4050
|
-
// don't clear mocks
|
|
4051
|
-
...!resetMocks ? [/^mock:/] : []
|
|
4052
|
-
];
|
|
4053
|
-
modules.forEach((mod, path) => {
|
|
4054
|
-
if (skipPaths.some((re) => re.test(path))) {
|
|
4055
|
-
return;
|
|
4056
|
-
}
|
|
4057
|
-
modules.invalidateModule(mod);
|
|
4058
|
-
});
|
|
4059
|
-
}
|
|
4060
|
-
function waitNextTick() {
|
|
4061
|
-
const { setTimeout: setTimeout2 } = getSafeTimers();
|
|
4062
|
-
return new Promise((resolve) => setTimeout2(resolve, 0));
|
|
4063
|
-
}
|
|
4064
|
-
async function waitForImportsToResolve() {
|
|
4065
|
-
await waitNextTick();
|
|
4066
|
-
const state = getWorkerState();
|
|
4067
|
-
const promises = [];
|
|
4068
|
-
let resolvingCount = 0;
|
|
4069
|
-
for (const mod of state.moduleCache.values()) {
|
|
4070
|
-
if (mod.promise && !mod.evaluated) {
|
|
4071
|
-
promises.push(mod.promise);
|
|
4072
|
-
}
|
|
4073
|
-
if (mod.resolving) {
|
|
4074
|
-
resolvingCount++;
|
|
4075
|
-
}
|
|
4076
|
-
}
|
|
4077
|
-
if (!promises.length && !resolvingCount) {
|
|
4078
|
-
return;
|
|
4079
|
-
}
|
|
4080
|
-
await Promise.allSettled(promises);
|
|
4081
|
-
await waitForImportsToResolve();
|
|
4082
|
-
}
|
|
4083
4033
|
|
|
4084
|
-
// ../node_modules/.pnpm/vitest@
|
|
4034
|
+
// ../node_modules/.pnpm/vitest@4.0.16_@types+node@25.0.3_jiti@2.6.1_jsdom@25.0.1_msw@2.12.7_@types+node@25.0.3_typescript@5.9.3__tsx@4.21.0/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js
|
|
4085
4035
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
4086
|
-
function getDefaultExportFromCjs(x) {
|
|
4087
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
4088
|
-
}
|
|
4089
4036
|
|
|
4090
|
-
// ../node_modules/.pnpm/vitest@
|
|
4037
|
+
// ../node_modules/.pnpm/vitest@4.0.16_@types+node@25.0.3_jiti@2.6.1_jsdom@25.0.1_msw@2.12.7_@types+node@25.0.3_typescript@5.9.3__tsx@4.21.0/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js
|
|
4091
4038
|
var RealDate = Date;
|
|
4092
|
-
var now = null;
|
|
4093
4039
|
var MockDate = class _MockDate extends RealDate {
|
|
4094
4040
|
constructor(y, m, d, h, M, s, ms) {
|
|
4095
4041
|
super();
|
|
4096
4042
|
let date;
|
|
4097
4043
|
switch (arguments.length) {
|
|
4098
4044
|
case 0:
|
|
4099
|
-
|
|
4100
|
-
date = new RealDate(now.valueOf());
|
|
4101
|
-
} else {
|
|
4102
|
-
date = new RealDate();
|
|
4103
|
-
}
|
|
4045
|
+
date = new RealDate();
|
|
4104
4046
|
break;
|
|
4105
4047
|
case 1:
|
|
4106
4048
|
date = new RealDate(y);
|
|
@@ -4128,257 +4070,122 @@ MockDate.parse = function(dateString) {
|
|
|
4128
4070
|
MockDate.toString = function() {
|
|
4129
4071
|
return RealDate.toString();
|
|
4130
4072
|
};
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
if (Number.isNaN(dateObj.getTime())) {
|
|
4134
|
-
throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
4135
|
-
}
|
|
4136
|
-
globalThis.Date = MockDate;
|
|
4137
|
-
now = dateObj.valueOf();
|
|
4138
|
-
}
|
|
4139
|
-
function resetDate() {
|
|
4140
|
-
globalThis.Date = RealDate;
|
|
4141
|
-
}
|
|
4073
|
+
|
|
4074
|
+
// ../node_modules/.pnpm/vitest@4.0.16_@types+node@25.0.3_jiti@2.6.1_jsdom@25.0.1_msw@2.12.7_@types+node@25.0.3_typescript@5.9.3__tsx@4.21.0/node_modules/vitest/dist/chunks/vi.2VT5v0um.js
|
|
4142
4075
|
var unsupported = [
|
|
4143
|
-
// .poll is meant to retry matchers until they succeed, and
|
|
4144
|
-
// snapshots will always succeed as long as the poll method doesn't thow an error
|
|
4145
|
-
// in this case using the `vi.waitFor` method is more appropriate
|
|
4146
4076
|
"matchSnapshot",
|
|
4147
4077
|
"toMatchSnapshot",
|
|
4148
4078
|
"toMatchInlineSnapshot",
|
|
4149
4079
|
"toThrowErrorMatchingSnapshot",
|
|
4150
4080
|
"toThrowErrorMatchingInlineSnapshot",
|
|
4151
|
-
// toThrow will never succeed because we call the poll callback until it doesn't throw
|
|
4152
4081
|
"throws",
|
|
4153
4082
|
"Throw",
|
|
4154
4083
|
"throw",
|
|
4155
4084
|
"toThrow",
|
|
4156
4085
|
"toThrowError"
|
|
4157
|
-
// these are not supported because you can call them without `.poll`,
|
|
4158
|
-
// we throw an error inside the rejects/resolves methods to prevent this
|
|
4159
|
-
// rejects,
|
|
4160
|
-
// resolves
|
|
4161
4086
|
];
|
|
4162
|
-
function
|
|
4087
|
+
function throwWithCause(error, source) {
|
|
4088
|
+
if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
4089
|
+
throw copyStackTrace$1(error, source);
|
|
4090
|
+
}
|
|
4091
|
+
function createExpectPoll(expect) {
|
|
4163
4092
|
return function poll(fn2, options = {}) {
|
|
4164
|
-
const
|
|
4165
|
-
const defaults =
|
|
4166
|
-
const {
|
|
4167
|
-
interval = defaults.interval ?? 50,
|
|
4168
|
-
timeout = defaults.timeout ?? 1e3,
|
|
4169
|
-
message
|
|
4170
|
-
} = options;
|
|
4171
|
-
const assertion = expect2(null, message).withContext({
|
|
4172
|
-
poll: true
|
|
4173
|
-
});
|
|
4093
|
+
const defaults = getWorkerState().config.expect?.poll ?? {};
|
|
4094
|
+
const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
|
|
4095
|
+
const assertion = expect(null, message).withContext({ poll: true });
|
|
4174
4096
|
fn2 = fn2.bind(assertion);
|
|
4175
|
-
const test2 = chai
|
|
4176
|
-
if (!test2)
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
);
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
let intervalId;
|
|
4197
|
-
let lastError;
|
|
4198
|
-
const { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = getSafeTimers();
|
|
4199
|
-
const timeoutId = setTimeout2(() => {
|
|
4200
|
-
clearTimeout2(intervalId);
|
|
4201
|
-
reject(
|
|
4202
|
-
copyStackTrace$1(
|
|
4203
|
-
new Error(`Matcher did not succeed in ${timeout}ms`, {
|
|
4204
|
-
cause: lastError
|
|
4205
|
-
}),
|
|
4206
|
-
STACK_TRACE_ERROR
|
|
4207
|
-
)
|
|
4208
|
-
);
|
|
4209
|
-
}, timeout);
|
|
4210
|
-
const check = async () => {
|
|
4097
|
+
const test2 = chai.util.flag(assertion, "vitest-test");
|
|
4098
|
+
if (!test2) throw new Error("expect.poll() must be called inside a test");
|
|
4099
|
+
const proxy = new Proxy(assertion, { get(target, key, receiver) {
|
|
4100
|
+
const assertionFunction = Reflect.get(target, key, receiver);
|
|
4101
|
+
if (typeof assertionFunction !== "function") return assertionFunction instanceof chai.Assertion ? proxy : assertionFunction;
|
|
4102
|
+
if (key === "assert") return assertionFunction;
|
|
4103
|
+
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.`);
|
|
4104
|
+
return function(...args) {
|
|
4105
|
+
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
4106
|
+
const promise = async () => {
|
|
4107
|
+
const { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = getSafeTimers();
|
|
4108
|
+
let executionPhase = "fn";
|
|
4109
|
+
let hasTimedOut = false;
|
|
4110
|
+
const timerId = setTimeout2(() => {
|
|
4111
|
+
hasTimedOut = true;
|
|
4112
|
+
}, timeout);
|
|
4113
|
+
chai.util.flag(assertion, "_name", key);
|
|
4114
|
+
try {
|
|
4115
|
+
while (true) {
|
|
4116
|
+
const isLastAttempt = hasTimedOut;
|
|
4117
|
+
if (isLastAttempt) chai.util.flag(assertion, "_isLastPollAttempt", true);
|
|
4211
4118
|
try {
|
|
4212
|
-
|
|
4119
|
+
executionPhase = "fn";
|
|
4213
4120
|
const obj = await fn2();
|
|
4214
|
-
chai
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
clearTimeout2(timeoutId);
|
|
4121
|
+
chai.util.flag(assertion, "object", obj);
|
|
4122
|
+
executionPhase = "assertion";
|
|
4123
|
+
return await assertionFunction.call(assertion, ...args);
|
|
4218
4124
|
} catch (err) {
|
|
4219
|
-
|
|
4220
|
-
|
|
4125
|
+
if (isLastAttempt || executionPhase === "assertion" && chai.util.flag(assertion, "_poll.assert_once")) throwWithCause(err, STACK_TRACE_ERROR);
|
|
4126
|
+
await delay(interval, setTimeout2);
|
|
4221
4127
|
}
|
|
4222
|
-
}
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4128
|
+
}
|
|
4129
|
+
} finally {
|
|
4130
|
+
clearTimeout2(timerId);
|
|
4131
|
+
}
|
|
4132
|
+
};
|
|
4133
|
+
let awaited = false;
|
|
4134
|
+
test2.onFinished ??= [];
|
|
4135
|
+
test2.onFinished.push(() => {
|
|
4136
|
+
if (!awaited) {
|
|
4137
|
+
const negated = chai.util.flag(assertion, "negate") ? "not." : "";
|
|
4138
|
+
const assertionString = `expect.${chai.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`;
|
|
4139
|
+
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:
|
|
4234
4140
|
|
|
4235
4141
|
await ${assertionString}
|
|
4236
|
-
`
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
then(onFulfilled, onRejected)
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
},
|
|
4253
|
-
[Symbol.toStringTag]: "Promise"
|
|
4254
|
-
};
|
|
4142
|
+
`), STACK_TRACE_ERROR);
|
|
4143
|
+
}
|
|
4144
|
+
});
|
|
4145
|
+
let resultPromise;
|
|
4146
|
+
return {
|
|
4147
|
+
then(onFulfilled, onRejected) {
|
|
4148
|
+
awaited = true;
|
|
4149
|
+
return (resultPromise ||= promise()).then(onFulfilled, onRejected);
|
|
4150
|
+
},
|
|
4151
|
+
catch(onRejected) {
|
|
4152
|
+
return (resultPromise ||= promise()).catch(onRejected);
|
|
4153
|
+
},
|
|
4154
|
+
finally(onFinally) {
|
|
4155
|
+
return (resultPromise ||= promise()).finally(onFinally);
|
|
4156
|
+
},
|
|
4157
|
+
[Symbol.toStringTag]: "Promise"
|
|
4255
4158
|
};
|
|
4256
|
-
}
|
|
4257
|
-
});
|
|
4159
|
+
};
|
|
4160
|
+
} });
|
|
4258
4161
|
return proxy;
|
|
4259
4162
|
};
|
|
4260
4163
|
}
|
|
4261
4164
|
function copyStackTrace$1(target, source) {
|
|
4262
|
-
if (source.stack !== void 0)
|
|
4263
|
-
target.stack = source.stack.replace(source.message, target.message);
|
|
4264
|
-
}
|
|
4165
|
+
if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
|
|
4265
4166
|
return target;
|
|
4266
4167
|
}
|
|
4267
|
-
function
|
|
4268
|
-
|
|
4269
|
-
}
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
var hasRequiredChaiSubset;
|
|
4273
|
-
function requireChaiSubset() {
|
|
4274
|
-
if (hasRequiredChaiSubset) return chaiSubset$1.exports;
|
|
4275
|
-
hasRequiredChaiSubset = 1;
|
|
4276
|
-
(function(module2, exports$1) {
|
|
4277
|
-
(function() {
|
|
4278
|
-
(function(chaiSubset2) {
|
|
4279
|
-
if (typeof commonjsRequire === "function" && true && true) {
|
|
4280
|
-
return module2.exports = chaiSubset2;
|
|
4281
|
-
} else {
|
|
4282
|
-
return chai.use(chaiSubset2);
|
|
4283
|
-
}
|
|
4284
|
-
})(function(chai3, utils) {
|
|
4285
|
-
var Assertion2 = chai3.Assertion;
|
|
4286
|
-
var assertionPrototype = Assertion2.prototype;
|
|
4287
|
-
Assertion2.addMethod("containSubset", function(expected) {
|
|
4288
|
-
var actual = utils.flag(this, "object");
|
|
4289
|
-
var showDiff = chai3.config.showDiff;
|
|
4290
|
-
assertionPrototype.assert.call(
|
|
4291
|
-
this,
|
|
4292
|
-
compare(expected, actual),
|
|
4293
|
-
"expected #{act} to contain subset #{exp}",
|
|
4294
|
-
"expected #{act} to not contain subset #{exp}",
|
|
4295
|
-
expected,
|
|
4296
|
-
actual,
|
|
4297
|
-
showDiff
|
|
4298
|
-
);
|
|
4299
|
-
});
|
|
4300
|
-
chai3.assert.containSubset = function(val, exp, msg) {
|
|
4301
|
-
new chai3.Assertion(val, msg).to.be.containSubset(exp);
|
|
4302
|
-
};
|
|
4303
|
-
function compare(expected, actual) {
|
|
4304
|
-
if (expected === actual) {
|
|
4305
|
-
return true;
|
|
4306
|
-
}
|
|
4307
|
-
if (typeof actual !== typeof expected) {
|
|
4308
|
-
return false;
|
|
4309
|
-
}
|
|
4310
|
-
if (typeof expected !== "object" || expected === null) {
|
|
4311
|
-
return expected === actual;
|
|
4312
|
-
}
|
|
4313
|
-
if (!!expected && !actual) {
|
|
4314
|
-
return false;
|
|
4315
|
-
}
|
|
4316
|
-
if (Array.isArray(expected)) {
|
|
4317
|
-
if (typeof actual.length !== "number") {
|
|
4318
|
-
return false;
|
|
4319
|
-
}
|
|
4320
|
-
var aa = Array.prototype.slice.call(actual);
|
|
4321
|
-
return expected.every(function(exp) {
|
|
4322
|
-
return aa.some(function(act4) {
|
|
4323
|
-
return compare(exp, act4);
|
|
4324
|
-
});
|
|
4325
|
-
});
|
|
4326
|
-
}
|
|
4327
|
-
if (expected instanceof Date) {
|
|
4328
|
-
if (actual instanceof Date) {
|
|
4329
|
-
return expected.getTime() === actual.getTime();
|
|
4330
|
-
} else {
|
|
4331
|
-
return false;
|
|
4332
|
-
}
|
|
4333
|
-
}
|
|
4334
|
-
return Object.keys(expected).every(function(key) {
|
|
4335
|
-
var eo = expected[key];
|
|
4336
|
-
var ao = actual[key];
|
|
4337
|
-
if (typeof eo === "object" && eo !== null && ao !== null) {
|
|
4338
|
-
return compare(eo, ao);
|
|
4339
|
-
}
|
|
4340
|
-
if (typeof eo === "function") {
|
|
4341
|
-
return eo(ao);
|
|
4342
|
-
}
|
|
4343
|
-
return ao === eo;
|
|
4344
|
-
});
|
|
4345
|
-
}
|
|
4346
|
-
});
|
|
4347
|
-
}).call(chaiSubset);
|
|
4348
|
-
})(chaiSubset$1);
|
|
4349
|
-
return chaiSubset$1.exports;
|
|
4350
|
-
}
|
|
4351
|
-
var chaiSubsetExports = requireChaiSubset();
|
|
4352
|
-
var Subset = /* @__PURE__ */ getDefaultExportFromCjs(chaiSubsetExports);
|
|
4353
|
-
function createAssertionMessage(util2, assertion, hasArgs) {
|
|
4354
|
-
const not = util2.flag(assertion, "negate") ? "not." : "";
|
|
4355
|
-
const name = `${util2.flag(assertion, "_name")}(${"expected"})`;
|
|
4356
|
-
const promiseName = util2.flag(assertion, "promise");
|
|
4357
|
-
const promise = promiseName ? `.${promiseName}` : "";
|
|
4358
|
-
return `expect(actual)${promise}.${not}${name}`;
|
|
4168
|
+
function createAssertionMessage(util, assertion, hasArgs) {
|
|
4169
|
+
const not = util.flag(assertion, "negate") ? "not." : "";
|
|
4170
|
+
const name = `${util.flag(assertion, "_name")}(${"expected"})`;
|
|
4171
|
+
const promiseName = util.flag(assertion, "promise");
|
|
4172
|
+
return `expect(actual)${promiseName ? `.${promiseName}` : ""}.${not}${name}`;
|
|
4359
4173
|
}
|
|
4360
4174
|
function recordAsyncExpect(_test, promise, assertion, error) {
|
|
4361
4175
|
const test2 = _test;
|
|
4362
4176
|
if (test2 && promise instanceof Promise) {
|
|
4363
4177
|
promise = promise.finally(() => {
|
|
4364
|
-
if (!test2.promises)
|
|
4365
|
-
return;
|
|
4366
|
-
}
|
|
4178
|
+
if (!test2.promises) return;
|
|
4367
4179
|
const index = test2.promises.indexOf(promise);
|
|
4368
|
-
if (index !== -1)
|
|
4369
|
-
test2.promises.splice(index, 1);
|
|
4370
|
-
}
|
|
4180
|
+
if (index !== -1) test2.promises.splice(index, 1);
|
|
4371
4181
|
});
|
|
4372
|
-
if (!test2.promises)
|
|
4373
|
-
test2.promises = [];
|
|
4374
|
-
}
|
|
4182
|
+
if (!test2.promises) test2.promises = [];
|
|
4375
4183
|
test2.promises.push(promise);
|
|
4376
4184
|
let resolved = false;
|
|
4377
4185
|
test2.onFinished ??= [];
|
|
4378
4186
|
test2.onFinished.push(() => {
|
|
4379
4187
|
if (!resolved) {
|
|
4380
|
-
const
|
|
4381
|
-
const stack = processor(error.stack);
|
|
4188
|
+
const stack = (globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || ""))(error.stack);
|
|
4382
4189
|
console.warn([
|
|
4383
4190
|
`Promise returned by \`${assertion}\` was not awaited. `,
|
|
4384
4191
|
"Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
|
|
@@ -4388,9 +4195,9 @@ function recordAsyncExpect(_test, promise, assertion, error) {
|
|
|
4388
4195
|
}
|
|
4389
4196
|
});
|
|
4390
4197
|
return {
|
|
4391
|
-
then(
|
|
4198
|
+
then(onFulfilled, onRejected) {
|
|
4392
4199
|
resolved = true;
|
|
4393
|
-
return promise.then(
|
|
4200
|
+
return promise.then(onFulfilled, onRejected);
|
|
4394
4201
|
},
|
|
4395
4202
|
catch(onRejected) {
|
|
4396
4203
|
return promise.catch(onRejected);
|
|
@@ -4405,22 +4212,14 @@ function recordAsyncExpect(_test, promise, assertion, error) {
|
|
|
4405
4212
|
}
|
|
4406
4213
|
var _client;
|
|
4407
4214
|
function getSnapshotClient() {
|
|
4408
|
-
if (!_client) {
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
return equals(received, expected, [iterableEquality, subsetEquality]);
|
|
4412
|
-
}
|
|
4413
|
-
});
|
|
4414
|
-
}
|
|
4215
|
+
if (!_client) _client = new SnapshotClient({ isEqual: (received, expected) => {
|
|
4216
|
+
return equals(received, expected, [iterableEquality, subsetEquality]);
|
|
4217
|
+
} });
|
|
4415
4218
|
return _client;
|
|
4416
4219
|
}
|
|
4417
4220
|
function getError(expected, promise) {
|
|
4418
4221
|
if (typeof expected !== "function") {
|
|
4419
|
-
if (!promise) {
|
|
4420
|
-
throw new Error(
|
|
4421
|
-
`expected must be a function, received ${typeof expected}`
|
|
4422
|
-
);
|
|
4423
|
-
}
|
|
4222
|
+
if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
|
|
4424
4223
|
return expected;
|
|
4425
4224
|
}
|
|
4426
4225
|
try {
|
|
@@ -4431,248 +4230,174 @@ function getError(expected, promise) {
|
|
|
4431
4230
|
throw new Error("snapshot function didn't throw");
|
|
4432
4231
|
}
|
|
4433
4232
|
function getTestNames(test2) {
|
|
4434
|
-
if (!test2) {
|
|
4435
|
-
return {};
|
|
4436
|
-
}
|
|
4437
4233
|
return {
|
|
4438
4234
|
filepath: test2.file.filepath,
|
|
4439
|
-
name: getNames(test2).slice(1).join(" > ")
|
|
4235
|
+
name: getNames(test2).slice(1).join(" > "),
|
|
4236
|
+
testId: test2.id
|
|
4440
4237
|
};
|
|
4441
4238
|
}
|
|
4442
4239
|
var SnapshotPlugin = (chai3, utils) => {
|
|
4443
|
-
|
|
4444
|
-
utils.
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
);
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
"
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
}
|
|
4540
|
-
);
|
|
4541
|
-
utils.addMethod(
|
|
4542
|
-
chai3.Assertion.prototype,
|
|
4543
|
-
"toThrowErrorMatchingSnapshot",
|
|
4544
|
-
function(message) {
|
|
4545
|
-
utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
|
|
4546
|
-
const isNot = utils.flag(this, "negate");
|
|
4547
|
-
if (isNot) {
|
|
4548
|
-
throw new Error(
|
|
4549
|
-
'toThrowErrorMatchingSnapshot cannot be used with "not"'
|
|
4550
|
-
);
|
|
4551
|
-
}
|
|
4552
|
-
const expected = utils.flag(this, "object");
|
|
4553
|
-
const test2 = utils.flag(this, "vitest-test");
|
|
4554
|
-
const promise = utils.flag(this, "promise");
|
|
4555
|
-
const errorMessage = utils.flag(this, "message");
|
|
4556
|
-
getSnapshotClient().assert({
|
|
4557
|
-
received: getError(expected, promise),
|
|
4558
|
-
message,
|
|
4559
|
-
errorMessage,
|
|
4560
|
-
...getTestNames(test2)
|
|
4561
|
-
});
|
|
4562
|
-
}
|
|
4563
|
-
);
|
|
4564
|
-
utils.addMethod(
|
|
4565
|
-
chai3.Assertion.prototype,
|
|
4566
|
-
"toThrowErrorMatchingInlineSnapshot",
|
|
4567
|
-
function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
4568
|
-
const isNot = utils.flag(this, "negate");
|
|
4569
|
-
if (isNot) {
|
|
4570
|
-
throw new Error(
|
|
4571
|
-
'toThrowErrorMatchingInlineSnapshot cannot be used with "not"'
|
|
4572
|
-
);
|
|
4573
|
-
}
|
|
4574
|
-
const test2 = utils.flag(this, "vitest-test");
|
|
4575
|
-
const isInsideEach = test2 && (test2.each || test2.suite?.each);
|
|
4576
|
-
if (isInsideEach) {
|
|
4577
|
-
throw new Error(
|
|
4578
|
-
"InlineSnapshot cannot be used inside of test.each or describe.each"
|
|
4579
|
-
);
|
|
4580
|
-
}
|
|
4581
|
-
const expected = utils.flag(this, "object");
|
|
4582
|
-
const error = utils.flag(this, "error");
|
|
4583
|
-
const promise = utils.flag(this, "promise");
|
|
4584
|
-
const errorMessage = utils.flag(this, "message");
|
|
4585
|
-
if (inlineSnapshot) {
|
|
4586
|
-
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
4587
|
-
}
|
|
4588
|
-
getSnapshotClient().assert({
|
|
4589
|
-
received: getError(expected, promise),
|
|
4590
|
-
message,
|
|
4591
|
-
inlineSnapshot,
|
|
4592
|
-
isInline: true,
|
|
4593
|
-
error,
|
|
4594
|
-
errorMessage,
|
|
4595
|
-
...getTestNames(test2)
|
|
4596
|
-
});
|
|
4597
|
-
}
|
|
4598
|
-
);
|
|
4240
|
+
function getTest(assertionName, obj) {
|
|
4241
|
+
const test2 = utils.flag(obj, "vitest-test");
|
|
4242
|
+
if (!test2) throw new Error(`'${assertionName}' cannot be used without test context`);
|
|
4243
|
+
return test2;
|
|
4244
|
+
}
|
|
4245
|
+
for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai3.Assertion.prototype, key, function(properties, message) {
|
|
4246
|
+
utils.flag(this, "_name", key);
|
|
4247
|
+
if (utils.flag(this, "negate")) throw new Error(`${key} cannot be used with "not"`);
|
|
4248
|
+
const expected = utils.flag(this, "object");
|
|
4249
|
+
const test2 = getTest(key, this);
|
|
4250
|
+
if (typeof properties === "string" && typeof message === "undefined") {
|
|
4251
|
+
message = properties;
|
|
4252
|
+
properties = void 0;
|
|
4253
|
+
}
|
|
4254
|
+
const errorMessage = utils.flag(this, "message");
|
|
4255
|
+
getSnapshotClient().assert({
|
|
4256
|
+
received: expected,
|
|
4257
|
+
message,
|
|
4258
|
+
isInline: false,
|
|
4259
|
+
properties,
|
|
4260
|
+
errorMessage,
|
|
4261
|
+
...getTestNames(test2)
|
|
4262
|
+
});
|
|
4263
|
+
});
|
|
4264
|
+
utils.addMethod(chai3.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
|
|
4265
|
+
utils.flag(this, "_name", "toMatchFileSnapshot");
|
|
4266
|
+
if (utils.flag(this, "negate")) throw new Error('toMatchFileSnapshot cannot be used with "not"');
|
|
4267
|
+
const error = /* @__PURE__ */ new Error("resolves");
|
|
4268
|
+
const expected = utils.flag(this, "object");
|
|
4269
|
+
const test2 = getTest("toMatchFileSnapshot", this);
|
|
4270
|
+
const errorMessage = utils.flag(this, "message");
|
|
4271
|
+
return recordAsyncExpect(test2, getSnapshotClient().assertRaw({
|
|
4272
|
+
received: expected,
|
|
4273
|
+
message,
|
|
4274
|
+
isInline: false,
|
|
4275
|
+
rawSnapshot: { file },
|
|
4276
|
+
errorMessage,
|
|
4277
|
+
...getTestNames(test2)
|
|
4278
|
+
}), createAssertionMessage(utils, this), error);
|
|
4279
|
+
});
|
|
4280
|
+
utils.addMethod(chai3.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
|
|
4281
|
+
utils.flag(this, "_name", "toMatchInlineSnapshot");
|
|
4282
|
+
if (utils.flag(this, "negate")) throw new Error('toMatchInlineSnapshot cannot be used with "not"');
|
|
4283
|
+
const test2 = getTest("toMatchInlineSnapshot", this);
|
|
4284
|
+
if (test2.each || test2.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
4285
|
+
const expected = utils.flag(this, "object");
|
|
4286
|
+
const error = utils.flag(this, "error");
|
|
4287
|
+
if (typeof properties === "string") {
|
|
4288
|
+
message = inlineSnapshot;
|
|
4289
|
+
inlineSnapshot = properties;
|
|
4290
|
+
properties = void 0;
|
|
4291
|
+
}
|
|
4292
|
+
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
4293
|
+
const errorMessage = utils.flag(this, "message");
|
|
4294
|
+
getSnapshotClient().assert({
|
|
4295
|
+
received: expected,
|
|
4296
|
+
message,
|
|
4297
|
+
isInline: true,
|
|
4298
|
+
properties,
|
|
4299
|
+
inlineSnapshot,
|
|
4300
|
+
error,
|
|
4301
|
+
errorMessage,
|
|
4302
|
+
...getTestNames(test2)
|
|
4303
|
+
});
|
|
4304
|
+
});
|
|
4305
|
+
utils.addMethod(chai3.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
|
|
4306
|
+
utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
|
|
4307
|
+
if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
|
|
4308
|
+
const expected = utils.flag(this, "object");
|
|
4309
|
+
const test2 = getTest("toThrowErrorMatchingSnapshot", this);
|
|
4310
|
+
const promise = utils.flag(this, "promise");
|
|
4311
|
+
const errorMessage = utils.flag(this, "message");
|
|
4312
|
+
getSnapshotClient().assert({
|
|
4313
|
+
received: getError(expected, promise),
|
|
4314
|
+
message,
|
|
4315
|
+
errorMessage,
|
|
4316
|
+
...getTestNames(test2)
|
|
4317
|
+
});
|
|
4318
|
+
});
|
|
4319
|
+
utils.addMethod(chai3.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
|
|
4320
|
+
if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
|
|
4321
|
+
const test2 = getTest("toThrowErrorMatchingInlineSnapshot", this);
|
|
4322
|
+
if (test2.each || test2.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
4323
|
+
const expected = utils.flag(this, "object");
|
|
4324
|
+
const error = utils.flag(this, "error");
|
|
4325
|
+
const promise = utils.flag(this, "promise");
|
|
4326
|
+
const errorMessage = utils.flag(this, "message");
|
|
4327
|
+
if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
|
|
4328
|
+
getSnapshotClient().assert({
|
|
4329
|
+
received: getError(expected, promise),
|
|
4330
|
+
message,
|
|
4331
|
+
inlineSnapshot,
|
|
4332
|
+
isInline: true,
|
|
4333
|
+
error,
|
|
4334
|
+
errorMessage,
|
|
4335
|
+
...getTestNames(test2)
|
|
4336
|
+
});
|
|
4337
|
+
});
|
|
4599
4338
|
utils.addMethod(chai3.expect, "addSnapshotSerializer", addSerializer);
|
|
4600
4339
|
};
|
|
4601
|
-
chai
|
|
4602
|
-
chai
|
|
4603
|
-
chai
|
|
4604
|
-
chai
|
|
4605
|
-
chai$1.use(JestAsymmetricMatchers);
|
|
4340
|
+
chai.use(JestExtend);
|
|
4341
|
+
chai.use(JestChaiExpect);
|
|
4342
|
+
chai.use(SnapshotPlugin);
|
|
4343
|
+
chai.use(JestAsymmetricMatchers);
|
|
4606
4344
|
function createExpect(test2) {
|
|
4607
|
-
const
|
|
4608
|
-
const { assertionCalls } = getState(
|
|
4609
|
-
setState({ assertionCalls: assertionCalls + 1 },
|
|
4610
|
-
const
|
|
4345
|
+
const expect = ((value, message) => {
|
|
4346
|
+
const { assertionCalls } = getState(expect);
|
|
4347
|
+
setState({ assertionCalls: assertionCalls + 1 }, expect);
|
|
4348
|
+
const assert2 = chai.expect(value, message);
|
|
4611
4349
|
const _test = getCurrentTest();
|
|
4612
|
-
if (_test)
|
|
4613
|
-
return
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
expect2.getState = () => getState(expect2);
|
|
4621
|
-
expect2.setState = (state) => setState(state, expect2);
|
|
4350
|
+
if (_test)
|
|
4351
|
+
return assert2.withTest(_test);
|
|
4352
|
+
else return assert2;
|
|
4353
|
+
});
|
|
4354
|
+
Object.assign(expect, chai.expect);
|
|
4355
|
+
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
4356
|
+
expect.getState = () => getState(expect);
|
|
4357
|
+
expect.setState = (state) => setState(state, expect);
|
|
4622
4358
|
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
|
|
4623
|
-
setState(
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
environment: getCurrentEnvironment(),
|
|
4633
|
-
get testPath() {
|
|
4634
|
-
return getWorkerState().filepath;
|
|
4635
|
-
},
|
|
4636
|
-
currentTestName: globalState.currentTestName
|
|
4359
|
+
setState({
|
|
4360
|
+
...globalState,
|
|
4361
|
+
assertionCalls: 0,
|
|
4362
|
+
isExpectingAssertions: false,
|
|
4363
|
+
isExpectingAssertionsError: null,
|
|
4364
|
+
expectedAssertionsNumber: null,
|
|
4365
|
+
expectedAssertionsNumberErrorGen: null,
|
|
4366
|
+
get testPath() {
|
|
4367
|
+
return getWorkerState().filepath;
|
|
4637
4368
|
},
|
|
4638
|
-
|
|
4639
|
-
);
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4369
|
+
currentTestName: globalState.currentTestName
|
|
4370
|
+
}, expect);
|
|
4371
|
+
expect.assert = chai.assert;
|
|
4372
|
+
expect.extend = (matchers) => chai.expect.extend(expect, matchers);
|
|
4373
|
+
expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
|
|
4374
|
+
expect.soft = (...args) => {
|
|
4375
|
+
return expect(...args).withContext({ soft: true });
|
|
4644
4376
|
};
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
chai
|
|
4648
|
-
`expected${message ? ` "${message}" ` : " "}not to be reached`
|
|
4649
|
-
);
|
|
4377
|
+
expect.poll = createExpectPoll(expect);
|
|
4378
|
+
expect.unreachable = (message) => {
|
|
4379
|
+
chai.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
|
|
4650
4380
|
};
|
|
4651
4381
|
function assertions(expected) {
|
|
4652
|
-
const errorGen = () => new Error(
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
if (Error.captureStackTrace) {
|
|
4656
|
-
Error.captureStackTrace(errorGen(), assertions);
|
|
4657
|
-
}
|
|
4658
|
-
expect2.setState({
|
|
4382
|
+
const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
|
|
4383
|
+
if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
|
|
4384
|
+
expect.setState({
|
|
4659
4385
|
expectedAssertionsNumber: expected,
|
|
4660
4386
|
expectedAssertionsNumberErrorGen: errorGen
|
|
4661
4387
|
});
|
|
4662
4388
|
}
|
|
4663
4389
|
function hasAssertions() {
|
|
4664
|
-
const error = new Error("expected any number of assertion, but got none");
|
|
4665
|
-
if (Error.captureStackTrace)
|
|
4666
|
-
|
|
4667
|
-
}
|
|
4668
|
-
expect2.setState({
|
|
4390
|
+
const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
|
|
4391
|
+
if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
|
|
4392
|
+
expect.setState({
|
|
4669
4393
|
isExpectingAssertions: true,
|
|
4670
4394
|
isExpectingAssertionsError: error
|
|
4671
4395
|
});
|
|
4672
4396
|
}
|
|
4673
|
-
chai
|
|
4674
|
-
chai
|
|
4675
|
-
|
|
4397
|
+
chai.util.addMethod(expect, "assertions", assertions);
|
|
4398
|
+
chai.util.addMethod(expect, "hasAssertions", hasAssertions);
|
|
4399
|
+
expect.extend(customMatchers);
|
|
4400
|
+
return expect;
|
|
4676
4401
|
}
|
|
4677
4402
|
var globalExpect = createExpect();
|
|
4678
4403
|
Object.defineProperty(globalThis, GLOBAL_EXPECT, {
|
|
@@ -4680,6 +4405,8 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
|
|
|
4680
4405
|
writable: true,
|
|
4681
4406
|
configurable: true
|
|
4682
4407
|
});
|
|
4408
|
+
chai.assert;
|
|
4409
|
+
chai.should;
|
|
4683
4410
|
var fakeTimersSrc = {};
|
|
4684
4411
|
var global2;
|
|
4685
4412
|
var hasRequiredGlobal;
|
|
@@ -4787,42 +4514,14 @@ function requireCalledInOrder() {
|
|
|
4787
4514
|
calledInOrder_1 = calledInOrder;
|
|
4788
4515
|
return calledInOrder_1;
|
|
4789
4516
|
}
|
|
4790
|
-
var functionName;
|
|
4791
|
-
var hasRequiredFunctionName;
|
|
4792
|
-
function requireFunctionName() {
|
|
4793
|
-
if (hasRequiredFunctionName) return functionName;
|
|
4794
|
-
hasRequiredFunctionName = 1;
|
|
4795
|
-
functionName = function functionName2(func) {
|
|
4796
|
-
if (!func) {
|
|
4797
|
-
return "";
|
|
4798
|
-
}
|
|
4799
|
-
try {
|
|
4800
|
-
return func.displayName || func.name || // Use function decomposition as a last resort to get function
|
|
4801
|
-
// name. Does not rely on function decomposition to work - if it
|
|
4802
|
-
// doesn't debugging will be slightly less informative
|
|
4803
|
-
// (i.e. toString will say 'spy' rather than 'myFunc').
|
|
4804
|
-
(String(func).match(/function ([^\s(]+)/) || [])[1];
|
|
4805
|
-
} catch (e) {
|
|
4806
|
-
return "";
|
|
4807
|
-
}
|
|
4808
|
-
};
|
|
4809
|
-
return functionName;
|
|
4810
|
-
}
|
|
4811
4517
|
var className_1;
|
|
4812
4518
|
var hasRequiredClassName;
|
|
4813
4519
|
function requireClassName() {
|
|
4814
4520
|
if (hasRequiredClassName) return className_1;
|
|
4815
4521
|
hasRequiredClassName = 1;
|
|
4816
|
-
var functionName2 = requireFunctionName();
|
|
4817
4522
|
function className(value) {
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
// of the Function object, we finally try to grab the
|
|
4821
|
-
// name from its definition. This will never be reached
|
|
4822
|
-
// in node, so we are not able to test this properly.
|
|
4823
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
|
|
4824
|
-
typeof value.constructor === "function" && /* istanbul ignore next */
|
|
4825
|
-
functionName2(value.constructor) || null;
|
|
4523
|
+
const name = value.constructor && value.constructor.name;
|
|
4524
|
+
return name || null;
|
|
4826
4525
|
}
|
|
4827
4526
|
className_1 = className;
|
|
4828
4527
|
return className_1;
|
|
@@ -4878,6 +4577,27 @@ function requireEvery() {
|
|
|
4878
4577
|
};
|
|
4879
4578
|
return every;
|
|
4880
4579
|
}
|
|
4580
|
+
var functionName;
|
|
4581
|
+
var hasRequiredFunctionName;
|
|
4582
|
+
function requireFunctionName() {
|
|
4583
|
+
if (hasRequiredFunctionName) return functionName;
|
|
4584
|
+
hasRequiredFunctionName = 1;
|
|
4585
|
+
functionName = function functionName2(func) {
|
|
4586
|
+
if (!func) {
|
|
4587
|
+
return "";
|
|
4588
|
+
}
|
|
4589
|
+
try {
|
|
4590
|
+
return func.displayName || func.name || // Use function decomposition as a last resort to get function
|
|
4591
|
+
// name. Does not rely on function decomposition to work - if it
|
|
4592
|
+
// doesn't debugging will be slightly less informative
|
|
4593
|
+
// (i.e. toString will say 'spy' rather than 'myFunc').
|
|
4594
|
+
(String(func).match(/function ([^\s(]+)/) || [])[1];
|
|
4595
|
+
} catch (e) {
|
|
4596
|
+
return "";
|
|
4597
|
+
}
|
|
4598
|
+
};
|
|
4599
|
+
return functionName;
|
|
4600
|
+
}
|
|
4881
4601
|
var orderByFirstCall_1;
|
|
4882
4602
|
var hasRequiredOrderByFirstCall;
|
|
4883
4603
|
function requireOrderByFirstCall() {
|
|
@@ -5129,12 +4849,16 @@ function requireFakeTimersSrc() {
|
|
|
5129
4849
|
if (hasRequiredFakeTimersSrc) return fakeTimersSrc;
|
|
5130
4850
|
hasRequiredFakeTimersSrc = 1;
|
|
5131
4851
|
const globalObject = requireLib().global;
|
|
5132
|
-
let timersModule;
|
|
4852
|
+
let timersModule, timersPromisesModule;
|
|
5133
4853
|
if (typeof __vitest_required__ !== "undefined") {
|
|
5134
4854
|
try {
|
|
5135
4855
|
timersModule = __vitest_required__.timers;
|
|
5136
4856
|
} catch (e) {
|
|
5137
4857
|
}
|
|
4858
|
+
try {
|
|
4859
|
+
timersPromisesModule = __vitest_required__.timersPromises;
|
|
4860
|
+
} catch (e) {
|
|
4861
|
+
}
|
|
5138
4862
|
}
|
|
5139
4863
|
function withGlobal(_global) {
|
|
5140
4864
|
const maxTimeout = Math.pow(2, 31) - 1;
|
|
@@ -5145,26 +4869,57 @@ function requireFakeTimersSrc() {
|
|
|
5145
4869
|
const NOOP_ARRAY = function() {
|
|
5146
4870
|
return [];
|
|
5147
4871
|
};
|
|
5148
|
-
const
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
4872
|
+
const isPresent = {};
|
|
4873
|
+
let timeoutResult, addTimerReturnsObject = false;
|
|
4874
|
+
if (_global.setTimeout) {
|
|
4875
|
+
isPresent.setTimeout = true;
|
|
4876
|
+
timeoutResult = _global.setTimeout(NOOP, 0);
|
|
4877
|
+
addTimerReturnsObject = typeof timeoutResult === "object";
|
|
4878
|
+
}
|
|
4879
|
+
isPresent.clearTimeout = Boolean(_global.clearTimeout);
|
|
4880
|
+
isPresent.setInterval = Boolean(_global.setInterval);
|
|
4881
|
+
isPresent.clearInterval = Boolean(_global.clearInterval);
|
|
4882
|
+
isPresent.hrtime = _global.process && typeof _global.process.hrtime === "function";
|
|
4883
|
+
isPresent.hrtimeBigint = isPresent.hrtime && typeof _global.process.hrtime.bigint === "function";
|
|
4884
|
+
isPresent.nextTick = _global.process && typeof _global.process.nextTick === "function";
|
|
5153
4885
|
const utilPromisify = _global.process && _global.__vitest_required__ && _global.__vitest_required__.util.promisify;
|
|
5154
|
-
|
|
4886
|
+
isPresent.performance = _global.performance && typeof _global.performance.now === "function";
|
|
5155
4887
|
const hasPerformancePrototype = _global.Performance && (typeof _global.Performance).match(/^(function|object)$/);
|
|
5156
4888
|
const hasPerformanceConstructorPrototype = _global.performance && _global.performance.constructor && _global.performance.constructor.prototype;
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
_global.
|
|
4889
|
+
isPresent.queueMicrotask = _global.hasOwnProperty("queueMicrotask");
|
|
4890
|
+
isPresent.requestAnimationFrame = _global.requestAnimationFrame && typeof _global.requestAnimationFrame === "function";
|
|
4891
|
+
isPresent.cancelAnimationFrame = _global.cancelAnimationFrame && typeof _global.cancelAnimationFrame === "function";
|
|
4892
|
+
isPresent.requestIdleCallback = _global.requestIdleCallback && typeof _global.requestIdleCallback === "function";
|
|
4893
|
+
isPresent.cancelIdleCallbackPresent = _global.cancelIdleCallback && typeof _global.cancelIdleCallback === "function";
|
|
4894
|
+
isPresent.setImmediate = _global.setImmediate && typeof _global.setImmediate === "function";
|
|
4895
|
+
isPresent.clearImmediate = _global.clearImmediate && typeof _global.clearImmediate === "function";
|
|
4896
|
+
isPresent.Intl = _global.Intl && typeof _global.Intl === "object";
|
|
4897
|
+
if (_global.clearTimeout) {
|
|
4898
|
+
_global.clearTimeout(timeoutResult);
|
|
4899
|
+
}
|
|
5165
4900
|
const NativeDate = _global.Date;
|
|
5166
|
-
const NativeIntl =
|
|
4901
|
+
const NativeIntl = isPresent.Intl ? Object.defineProperties(
|
|
4902
|
+
/* @__PURE__ */ Object.create(null),
|
|
4903
|
+
Object.getOwnPropertyDescriptors(_global.Intl)
|
|
4904
|
+
) : void 0;
|
|
5167
4905
|
let uniqueTimerId = idCounterStart;
|
|
4906
|
+
if (NativeDate === void 0) {
|
|
4907
|
+
throw new Error(
|
|
4908
|
+
"The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
|
|
4909
|
+
);
|
|
4910
|
+
}
|
|
4911
|
+
isPresent.Date = true;
|
|
4912
|
+
class FakePerformanceEntry {
|
|
4913
|
+
constructor(name, entryType, startTime, duration) {
|
|
4914
|
+
this.name = name;
|
|
4915
|
+
this.entryType = entryType;
|
|
4916
|
+
this.startTime = startTime;
|
|
4917
|
+
this.duration = duration;
|
|
4918
|
+
}
|
|
4919
|
+
toJSON() {
|
|
4920
|
+
return JSON.stringify({ ...this });
|
|
4921
|
+
}
|
|
4922
|
+
}
|
|
5168
4923
|
function isNumberFinite(num) {
|
|
5169
4924
|
if (Number.isFinite) {
|
|
5170
4925
|
return Number.isFinite(num);
|
|
@@ -5265,80 +5020,66 @@ ${job.error.stack.split("\n").slice(matchedLineIndex + 1).join("\n")}`;
|
|
|
5265
5020
|
}
|
|
5266
5021
|
return infiniteLoopError;
|
|
5267
5022
|
}
|
|
5268
|
-
function
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5023
|
+
function createDate() {
|
|
5024
|
+
class ClockDate extends NativeDate {
|
|
5025
|
+
/**
|
|
5026
|
+
* @param {number} year
|
|
5027
|
+
* @param {number} month
|
|
5028
|
+
* @param {number} date
|
|
5029
|
+
* @param {number} hour
|
|
5030
|
+
* @param {number} minute
|
|
5031
|
+
* @param {number} second
|
|
5032
|
+
* @param {number} ms
|
|
5033
|
+
* @returns void
|
|
5034
|
+
*/
|
|
5035
|
+
// eslint-disable-next-line no-unused-vars
|
|
5036
|
+
constructor(year, month, date, hour, minute, second, ms) {
|
|
5037
|
+
if (arguments.length === 0) {
|
|
5038
|
+
super(ClockDate.clock.now);
|
|
5039
|
+
} else {
|
|
5040
|
+
super(...arguments);
|
|
5041
|
+
}
|
|
5042
|
+
Object.defineProperty(this, "constructor", {
|
|
5043
|
+
value: NativeDate,
|
|
5044
|
+
enumerable: false
|
|
5045
|
+
});
|
|
5046
|
+
}
|
|
5047
|
+
static [Symbol.hasInstance](instance) {
|
|
5048
|
+
return instance instanceof NativeDate;
|
|
5273
5049
|
}
|
|
5274
5050
|
}
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5051
|
+
ClockDate.isFake = true;
|
|
5052
|
+
if (NativeDate.now) {
|
|
5053
|
+
ClockDate.now = function now2() {
|
|
5054
|
+
return ClockDate.clock.now;
|
|
5278
5055
|
};
|
|
5279
|
-
} else {
|
|
5280
|
-
delete target.now;
|
|
5281
5056
|
}
|
|
5282
|
-
if (
|
|
5283
|
-
|
|
5284
|
-
return
|
|
5057
|
+
if (NativeDate.toSource) {
|
|
5058
|
+
ClockDate.toSource = function toSource() {
|
|
5059
|
+
return NativeDate.toSource();
|
|
5285
5060
|
};
|
|
5286
|
-
} else {
|
|
5287
|
-
delete target.toSource;
|
|
5288
5061
|
}
|
|
5289
|
-
|
|
5290
|
-
return
|
|
5062
|
+
ClockDate.toString = function toString() {
|
|
5063
|
+
return NativeDate.toString();
|
|
5291
5064
|
};
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
}
|
|
5299
|
-
function createDate() {
|
|
5300
|
-
function ClockDate(year, month, date, hour, minute, second, ms) {
|
|
5301
|
-
if (!(this instanceof ClockDate)) {
|
|
5302
|
-
return new NativeDate(ClockDate.clock.now).toString();
|
|
5303
|
-
}
|
|
5304
|
-
switch (arguments.length) {
|
|
5305
|
-
case 0:
|
|
5306
|
-
return new NativeDate(ClockDate.clock.now);
|
|
5307
|
-
case 1:
|
|
5308
|
-
return new NativeDate(year);
|
|
5309
|
-
case 2:
|
|
5310
|
-
return new NativeDate(year, month);
|
|
5311
|
-
case 3:
|
|
5312
|
-
return new NativeDate(year, month, date);
|
|
5313
|
-
case 4:
|
|
5314
|
-
return new NativeDate(year, month, date, hour);
|
|
5315
|
-
case 5:
|
|
5316
|
-
return new NativeDate(year, month, date, hour, minute);
|
|
5317
|
-
case 6:
|
|
5318
|
-
return new NativeDate(
|
|
5319
|
-
year,
|
|
5320
|
-
month,
|
|
5321
|
-
date,
|
|
5322
|
-
hour,
|
|
5323
|
-
minute,
|
|
5324
|
-
second
|
|
5325
|
-
);
|
|
5326
|
-
default:
|
|
5327
|
-
return new NativeDate(
|
|
5328
|
-
year,
|
|
5329
|
-
month,
|
|
5330
|
-
date,
|
|
5331
|
-
hour,
|
|
5332
|
-
minute,
|
|
5333
|
-
second,
|
|
5334
|
-
ms
|
|
5065
|
+
const ClockDateProxy = new Proxy(ClockDate, {
|
|
5066
|
+
// handler for [[Call]] invocations (i.e. not using `new`)
|
|
5067
|
+
apply() {
|
|
5068
|
+
if (this instanceof ClockDate) {
|
|
5069
|
+
throw new TypeError(
|
|
5070
|
+
"A Proxy should only capture `new` calls with the `construct` handler. This is not supposed to be possible, so check the logic."
|
|
5335
5071
|
);
|
|
5072
|
+
}
|
|
5073
|
+
return new NativeDate(ClockDate.clock.now).toString();
|
|
5336
5074
|
}
|
|
5337
|
-
}
|
|
5338
|
-
return
|
|
5075
|
+
});
|
|
5076
|
+
return ClockDateProxy;
|
|
5339
5077
|
}
|
|
5340
5078
|
function createIntl() {
|
|
5341
|
-
const ClockIntl = {
|
|
5079
|
+
const ClockIntl = {};
|
|
5080
|
+
Object.getOwnPropertyNames(NativeIntl).forEach(
|
|
5081
|
+
(property) => ClockIntl[property] = NativeIntl[property]
|
|
5082
|
+
);
|
|
5342
5083
|
ClockIntl.DateTimeFormat = function(...args) {
|
|
5343
5084
|
const realFormatter = new NativeIntl.DateTimeFormat(...args);
|
|
5344
5085
|
const formatter = {};
|
|
@@ -5624,11 +5365,21 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
5624
5365
|
timersModule[entry.methodName] = entry.original;
|
|
5625
5366
|
}
|
|
5626
5367
|
}
|
|
5368
|
+
if (clock.timersPromisesModuleMethods !== void 0) {
|
|
5369
|
+
for (let j = 0; j < clock.timersPromisesModuleMethods.length; j++) {
|
|
5370
|
+
const entry = clock.timersPromisesModuleMethods[j];
|
|
5371
|
+
timersPromisesModule[entry.methodName] = entry.original;
|
|
5372
|
+
}
|
|
5373
|
+
}
|
|
5627
5374
|
}
|
|
5628
5375
|
if (config2.shouldAdvanceTime === true) {
|
|
5629
5376
|
_global.clearInterval(clock.attachedInterval);
|
|
5630
5377
|
}
|
|
5631
5378
|
clock.methods = [];
|
|
5379
|
+
for (const [listener, signal] of clock.abortListenerMap.entries()) {
|
|
5380
|
+
signal.removeEventListener("abort", listener);
|
|
5381
|
+
clock.abortListenerMap.delete(listener);
|
|
5382
|
+
}
|
|
5632
5383
|
if (!clock.timers) {
|
|
5633
5384
|
return [];
|
|
5634
5385
|
}
|
|
@@ -5643,8 +5394,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
5643
5394
|
);
|
|
5644
5395
|
clock[`_${method}`] = target[method];
|
|
5645
5396
|
if (method === "Date") {
|
|
5646
|
-
|
|
5647
|
-
target[method] = date;
|
|
5397
|
+
target[method] = clock[method];
|
|
5648
5398
|
} else if (method === "Intl") {
|
|
5649
5399
|
target[method] = clock[method];
|
|
5650
5400
|
} else if (method === "performance") {
|
|
@@ -5687,36 +5437,38 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
5687
5437
|
clearInterval: _global.clearInterval,
|
|
5688
5438
|
Date: _global.Date
|
|
5689
5439
|
};
|
|
5690
|
-
if (
|
|
5440
|
+
if (isPresent.setImmediate) {
|
|
5691
5441
|
timers.setImmediate = _global.setImmediate;
|
|
5442
|
+
}
|
|
5443
|
+
if (isPresent.clearImmediate) {
|
|
5692
5444
|
timers.clearImmediate = _global.clearImmediate;
|
|
5693
5445
|
}
|
|
5694
|
-
if (
|
|
5446
|
+
if (isPresent.hrtime) {
|
|
5695
5447
|
timers.hrtime = _global.process.hrtime;
|
|
5696
5448
|
}
|
|
5697
|
-
if (
|
|
5449
|
+
if (isPresent.nextTick) {
|
|
5698
5450
|
timers.nextTick = _global.process.nextTick;
|
|
5699
5451
|
}
|
|
5700
|
-
if (
|
|
5452
|
+
if (isPresent.performance) {
|
|
5701
5453
|
timers.performance = _global.performance;
|
|
5702
5454
|
}
|
|
5703
|
-
if (
|
|
5455
|
+
if (isPresent.requestAnimationFrame) {
|
|
5704
5456
|
timers.requestAnimationFrame = _global.requestAnimationFrame;
|
|
5705
5457
|
}
|
|
5706
|
-
if (
|
|
5707
|
-
timers.queueMicrotask =
|
|
5458
|
+
if (isPresent.queueMicrotask) {
|
|
5459
|
+
timers.queueMicrotask = _global.queueMicrotask;
|
|
5708
5460
|
}
|
|
5709
|
-
if (
|
|
5461
|
+
if (isPresent.cancelAnimationFrame) {
|
|
5710
5462
|
timers.cancelAnimationFrame = _global.cancelAnimationFrame;
|
|
5711
5463
|
}
|
|
5712
|
-
if (
|
|
5464
|
+
if (isPresent.requestIdleCallback) {
|
|
5713
5465
|
timers.requestIdleCallback = _global.requestIdleCallback;
|
|
5714
5466
|
}
|
|
5715
|
-
if (
|
|
5467
|
+
if (isPresent.cancelIdleCallback) {
|
|
5716
5468
|
timers.cancelIdleCallback = _global.cancelIdleCallback;
|
|
5717
5469
|
}
|
|
5718
|
-
if (
|
|
5719
|
-
timers.Intl =
|
|
5470
|
+
if (isPresent.Intl) {
|
|
5471
|
+
timers.Intl = NativeIntl;
|
|
5720
5472
|
}
|
|
5721
5473
|
const originalSetTimeout = _global.setImmediate || _global.setTimeout;
|
|
5722
5474
|
function createClock(start, loopLimit) {
|
|
@@ -5724,11 +5476,6 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
5724
5476
|
loopLimit = loopLimit || 1e3;
|
|
5725
5477
|
let nanos = 0;
|
|
5726
5478
|
const adjustedSystemTime = [0, 0];
|
|
5727
|
-
if (NativeDate === void 0) {
|
|
5728
|
-
throw new Error(
|
|
5729
|
-
"The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
|
|
5730
|
-
);
|
|
5731
|
-
}
|
|
5732
5479
|
const clock = {
|
|
5733
5480
|
now: start,
|
|
5734
5481
|
Date: createDate(),
|
|
@@ -5764,13 +5511,13 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
5764
5511
|
const millis = hrt[0] * 1e3 + hrt[1] / 1e6;
|
|
5765
5512
|
return millis;
|
|
5766
5513
|
}
|
|
5767
|
-
if (
|
|
5514
|
+
if (isPresent.hrtimeBigint) {
|
|
5768
5515
|
hrtime.bigint = function() {
|
|
5769
5516
|
const parts = hrtime();
|
|
5770
5517
|
return BigInt(parts[0]) * BigInt(1e9) + BigInt(parts[1]);
|
|
5771
5518
|
};
|
|
5772
5519
|
}
|
|
5773
|
-
if (
|
|
5520
|
+
if (isPresent.Intl) {
|
|
5774
5521
|
clock.Intl = createIntl();
|
|
5775
5522
|
clock.Intl.clock = clock;
|
|
5776
5523
|
}
|
|
@@ -5833,7 +5580,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
5833
5580
|
clock.clearInterval = function clearInterval2(timerId) {
|
|
5834
5581
|
return clearTimer(clock, timerId, "Interval");
|
|
5835
5582
|
};
|
|
5836
|
-
if (
|
|
5583
|
+
if (isPresent.setImmediate) {
|
|
5837
5584
|
clock.setImmediate = function setImmediate(func) {
|
|
5838
5585
|
return addTimer(clock, {
|
|
5839
5586
|
func,
|
|
@@ -6066,6 +5813,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
6066
5813
|
function doRun() {
|
|
6067
5814
|
originalSetTimeout(function() {
|
|
6068
5815
|
try {
|
|
5816
|
+
runJobs(clock);
|
|
6069
5817
|
let numTimers;
|
|
6070
5818
|
if (i < clock.loopLimit) {
|
|
6071
5819
|
if (!clock.timers) {
|
|
@@ -6113,6 +5861,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
6113
5861
|
try {
|
|
6114
5862
|
const timer = lastTimer(clock);
|
|
6115
5863
|
if (!timer) {
|
|
5864
|
+
runJobs(clock);
|
|
6116
5865
|
resolve(clock.now);
|
|
6117
5866
|
}
|
|
6118
5867
|
resolve(clock.tickAsync(timer.callAt - clock.now));
|
|
@@ -6155,11 +5904,11 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
6155
5904
|
}
|
|
6156
5905
|
clock.tick(ms);
|
|
6157
5906
|
};
|
|
6158
|
-
if (
|
|
5907
|
+
if (isPresent.performance) {
|
|
6159
5908
|
clock.performance = /* @__PURE__ */ Object.create(null);
|
|
6160
5909
|
clock.performance.now = fakePerformanceNow;
|
|
6161
5910
|
}
|
|
6162
|
-
if (
|
|
5911
|
+
if (isPresent.hrtime) {
|
|
6163
5912
|
clock.hrtime = hrtime;
|
|
6164
5913
|
}
|
|
6165
5914
|
return clock;
|
|
@@ -6186,17 +5935,24 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
6186
5935
|
"config.target is no longer supported. Use `withGlobal(target)` instead."
|
|
6187
5936
|
);
|
|
6188
5937
|
}
|
|
5938
|
+
function handleMissingTimer(timer) {
|
|
5939
|
+
if (config2.ignoreMissingTimers) {
|
|
5940
|
+
return;
|
|
5941
|
+
}
|
|
5942
|
+
throw new ReferenceError(
|
|
5943
|
+
`non-existent timers and/or objects cannot be faked: '${timer}'`
|
|
5944
|
+
);
|
|
5945
|
+
}
|
|
6189
5946
|
let i, l;
|
|
6190
5947
|
const clock = createClock(config2.now, config2.loopLimit);
|
|
6191
5948
|
clock.shouldClearNativeTimers = config2.shouldClearNativeTimers;
|
|
6192
5949
|
clock.uninstall = function() {
|
|
6193
5950
|
return uninstall(clock, config2);
|
|
6194
5951
|
};
|
|
5952
|
+
clock.abortListenerMap = /* @__PURE__ */ new Map();
|
|
6195
5953
|
clock.methods = config2.toFake || [];
|
|
6196
5954
|
if (clock.methods.length === 0) {
|
|
6197
|
-
clock.methods = Object.keys(timers)
|
|
6198
|
-
return key !== "nextTick" && key !== "queueMicrotask";
|
|
6199
|
-
});
|
|
5955
|
+
clock.methods = Object.keys(timers);
|
|
6200
5956
|
}
|
|
6201
5957
|
if (config2.shouldAdvanceTime === true) {
|
|
6202
5958
|
const intervalTick = doIntervalTick.bind(
|
|
@@ -6225,17 +5981,25 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
6225
5981
|
clock.performance[name] = name.indexOf("getEntries") === 0 ? NOOP_ARRAY : NOOP;
|
|
6226
5982
|
}
|
|
6227
5983
|
});
|
|
5984
|
+
clock.performance.mark = (name) => new FakePerformanceEntry(name, "mark", 0, 0);
|
|
5985
|
+
clock.performance.measure = (name) => new FakePerformanceEntry(name, "measure", 0, 100);
|
|
5986
|
+
clock.performance.timeOrigin = getEpoch(config2.now);
|
|
6228
5987
|
} else if ((config2.toFake || []).includes("performance")) {
|
|
6229
|
-
|
|
6230
|
-
"non-existent performance object cannot be faked"
|
|
6231
|
-
);
|
|
5988
|
+
return handleMissingTimer("performance");
|
|
6232
5989
|
}
|
|
6233
5990
|
}
|
|
6234
5991
|
if (_global === globalObject && timersModule) {
|
|
6235
5992
|
clock.timersModuleMethods = [];
|
|
6236
5993
|
}
|
|
5994
|
+
if (_global === globalObject && timersPromisesModule) {
|
|
5995
|
+
clock.timersPromisesModuleMethods = [];
|
|
5996
|
+
}
|
|
6237
5997
|
for (i = 0, l = clock.methods.length; i < l; i++) {
|
|
6238
5998
|
const nameOfMethodToReplace = clock.methods[i];
|
|
5999
|
+
if (!isPresent[nameOfMethodToReplace]) {
|
|
6000
|
+
handleMissingTimer(nameOfMethodToReplace);
|
|
6001
|
+
continue;
|
|
6002
|
+
}
|
|
6239
6003
|
if (nameOfMethodToReplace === "hrtime") {
|
|
6240
6004
|
if (_global.process && typeof _global.process.hrtime === "function") {
|
|
6241
6005
|
hijackMethod(_global.process, nameOfMethodToReplace, clock);
|
|
@@ -6255,6 +6019,194 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
6255
6019
|
});
|
|
6256
6020
|
timersModule[nameOfMethodToReplace] = _global[nameOfMethodToReplace];
|
|
6257
6021
|
}
|
|
6022
|
+
if (clock.timersPromisesModuleMethods !== void 0) {
|
|
6023
|
+
if (nameOfMethodToReplace === "setTimeout") {
|
|
6024
|
+
clock.timersPromisesModuleMethods.push({
|
|
6025
|
+
methodName: "setTimeout",
|
|
6026
|
+
original: timersPromisesModule.setTimeout
|
|
6027
|
+
});
|
|
6028
|
+
timersPromisesModule.setTimeout = (delay2, value, options = {}) => new Promise((resolve, reject) => {
|
|
6029
|
+
const abort = () => {
|
|
6030
|
+
options.signal.removeEventListener(
|
|
6031
|
+
"abort",
|
|
6032
|
+
abort
|
|
6033
|
+
);
|
|
6034
|
+
clock.abortListenerMap.delete(abort);
|
|
6035
|
+
clock.clearTimeout(handle);
|
|
6036
|
+
reject(options.signal.reason);
|
|
6037
|
+
};
|
|
6038
|
+
const handle = clock.setTimeout(() => {
|
|
6039
|
+
if (options.signal) {
|
|
6040
|
+
options.signal.removeEventListener(
|
|
6041
|
+
"abort",
|
|
6042
|
+
abort
|
|
6043
|
+
);
|
|
6044
|
+
clock.abortListenerMap.delete(abort);
|
|
6045
|
+
}
|
|
6046
|
+
resolve(value);
|
|
6047
|
+
}, delay2);
|
|
6048
|
+
if (options.signal) {
|
|
6049
|
+
if (options.signal.aborted) {
|
|
6050
|
+
abort();
|
|
6051
|
+
} else {
|
|
6052
|
+
options.signal.addEventListener(
|
|
6053
|
+
"abort",
|
|
6054
|
+
abort
|
|
6055
|
+
);
|
|
6056
|
+
clock.abortListenerMap.set(
|
|
6057
|
+
abort,
|
|
6058
|
+
options.signal
|
|
6059
|
+
);
|
|
6060
|
+
}
|
|
6061
|
+
}
|
|
6062
|
+
});
|
|
6063
|
+
} else if (nameOfMethodToReplace === "setImmediate") {
|
|
6064
|
+
clock.timersPromisesModuleMethods.push({
|
|
6065
|
+
methodName: "setImmediate",
|
|
6066
|
+
original: timersPromisesModule.setImmediate
|
|
6067
|
+
});
|
|
6068
|
+
timersPromisesModule.setImmediate = (value, options = {}) => new Promise((resolve, reject) => {
|
|
6069
|
+
const abort = () => {
|
|
6070
|
+
options.signal.removeEventListener(
|
|
6071
|
+
"abort",
|
|
6072
|
+
abort
|
|
6073
|
+
);
|
|
6074
|
+
clock.abortListenerMap.delete(abort);
|
|
6075
|
+
clock.clearImmediate(handle);
|
|
6076
|
+
reject(options.signal.reason);
|
|
6077
|
+
};
|
|
6078
|
+
const handle = clock.setImmediate(() => {
|
|
6079
|
+
if (options.signal) {
|
|
6080
|
+
options.signal.removeEventListener(
|
|
6081
|
+
"abort",
|
|
6082
|
+
abort
|
|
6083
|
+
);
|
|
6084
|
+
clock.abortListenerMap.delete(abort);
|
|
6085
|
+
}
|
|
6086
|
+
resolve(value);
|
|
6087
|
+
});
|
|
6088
|
+
if (options.signal) {
|
|
6089
|
+
if (options.signal.aborted) {
|
|
6090
|
+
abort();
|
|
6091
|
+
} else {
|
|
6092
|
+
options.signal.addEventListener(
|
|
6093
|
+
"abort",
|
|
6094
|
+
abort
|
|
6095
|
+
);
|
|
6096
|
+
clock.abortListenerMap.set(
|
|
6097
|
+
abort,
|
|
6098
|
+
options.signal
|
|
6099
|
+
);
|
|
6100
|
+
}
|
|
6101
|
+
}
|
|
6102
|
+
});
|
|
6103
|
+
} else if (nameOfMethodToReplace === "setInterval") {
|
|
6104
|
+
clock.timersPromisesModuleMethods.push({
|
|
6105
|
+
methodName: "setInterval",
|
|
6106
|
+
original: timersPromisesModule.setInterval
|
|
6107
|
+
});
|
|
6108
|
+
timersPromisesModule.setInterval = (delay2, value, options = {}) => ({
|
|
6109
|
+
[Symbol.asyncIterator]: () => {
|
|
6110
|
+
const createResolvable = () => {
|
|
6111
|
+
let resolve, reject;
|
|
6112
|
+
const promise = new Promise((res, rej) => {
|
|
6113
|
+
resolve = res;
|
|
6114
|
+
reject = rej;
|
|
6115
|
+
});
|
|
6116
|
+
promise.resolve = resolve;
|
|
6117
|
+
promise.reject = reject;
|
|
6118
|
+
return promise;
|
|
6119
|
+
};
|
|
6120
|
+
let done = false;
|
|
6121
|
+
let hasThrown = false;
|
|
6122
|
+
let returnCall;
|
|
6123
|
+
let nextAvailable = 0;
|
|
6124
|
+
const nextQueue = [];
|
|
6125
|
+
const handle = clock.setInterval(() => {
|
|
6126
|
+
if (nextQueue.length > 0) {
|
|
6127
|
+
nextQueue.shift().resolve();
|
|
6128
|
+
} else {
|
|
6129
|
+
nextAvailable++;
|
|
6130
|
+
}
|
|
6131
|
+
}, delay2);
|
|
6132
|
+
const abort = () => {
|
|
6133
|
+
options.signal.removeEventListener(
|
|
6134
|
+
"abort",
|
|
6135
|
+
abort
|
|
6136
|
+
);
|
|
6137
|
+
clock.abortListenerMap.delete(abort);
|
|
6138
|
+
clock.clearInterval(handle);
|
|
6139
|
+
done = true;
|
|
6140
|
+
for (const resolvable of nextQueue) {
|
|
6141
|
+
resolvable.resolve();
|
|
6142
|
+
}
|
|
6143
|
+
};
|
|
6144
|
+
if (options.signal) {
|
|
6145
|
+
if (options.signal.aborted) {
|
|
6146
|
+
done = true;
|
|
6147
|
+
} else {
|
|
6148
|
+
options.signal.addEventListener(
|
|
6149
|
+
"abort",
|
|
6150
|
+
abort
|
|
6151
|
+
);
|
|
6152
|
+
clock.abortListenerMap.set(
|
|
6153
|
+
abort,
|
|
6154
|
+
options.signal
|
|
6155
|
+
);
|
|
6156
|
+
}
|
|
6157
|
+
}
|
|
6158
|
+
return {
|
|
6159
|
+
next: async () => {
|
|
6160
|
+
if (options.signal?.aborted && !hasThrown) {
|
|
6161
|
+
hasThrown = true;
|
|
6162
|
+
throw options.signal.reason;
|
|
6163
|
+
}
|
|
6164
|
+
if (done) {
|
|
6165
|
+
return { done: true, value: void 0 };
|
|
6166
|
+
}
|
|
6167
|
+
if (nextAvailable > 0) {
|
|
6168
|
+
nextAvailable--;
|
|
6169
|
+
return { done: false, value };
|
|
6170
|
+
}
|
|
6171
|
+
const resolvable = createResolvable();
|
|
6172
|
+
nextQueue.push(resolvable);
|
|
6173
|
+
await resolvable;
|
|
6174
|
+
if (returnCall && nextQueue.length === 0) {
|
|
6175
|
+
returnCall.resolve();
|
|
6176
|
+
}
|
|
6177
|
+
if (options.signal?.aborted && !hasThrown) {
|
|
6178
|
+
hasThrown = true;
|
|
6179
|
+
throw options.signal.reason;
|
|
6180
|
+
}
|
|
6181
|
+
if (done) {
|
|
6182
|
+
return { done: true, value: void 0 };
|
|
6183
|
+
}
|
|
6184
|
+
return { done: false, value };
|
|
6185
|
+
},
|
|
6186
|
+
return: async () => {
|
|
6187
|
+
if (done) {
|
|
6188
|
+
return { done: true, value: void 0 };
|
|
6189
|
+
}
|
|
6190
|
+
if (nextQueue.length > 0) {
|
|
6191
|
+
returnCall = createResolvable();
|
|
6192
|
+
await returnCall;
|
|
6193
|
+
}
|
|
6194
|
+
clock.clearInterval(handle);
|
|
6195
|
+
done = true;
|
|
6196
|
+
if (options.signal) {
|
|
6197
|
+
options.signal.removeEventListener(
|
|
6198
|
+
"abort",
|
|
6199
|
+
abort
|
|
6200
|
+
);
|
|
6201
|
+
clock.abortListenerMap.delete(abort);
|
|
6202
|
+
}
|
|
6203
|
+
return { done: true, value: void 0 };
|
|
6204
|
+
}
|
|
6205
|
+
};
|
|
6206
|
+
}
|
|
6207
|
+
});
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6258
6210
|
}
|
|
6259
6211
|
return clock;
|
|
6260
6212
|
}
|
|
@@ -6272,604 +6224,33 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
6272
6224
|
fakeTimersSrc.withGlobal = withGlobal;
|
|
6273
6225
|
return fakeTimersSrc;
|
|
6274
6226
|
}
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
_now = RealDate.now;
|
|
6284
|
-
constructor({
|
|
6285
|
-
global: global3,
|
|
6286
|
-
config: config2
|
|
6287
|
-
}) {
|
|
6288
|
-
this._userConfig = config2;
|
|
6289
|
-
this._fakingDate = false;
|
|
6290
|
-
this._fakingTime = false;
|
|
6291
|
-
this._fakeTimers = fakeTimersSrcExports.withGlobal(global3);
|
|
6292
|
-
this._global = global3;
|
|
6293
|
-
}
|
|
6294
|
-
clearAllTimers() {
|
|
6295
|
-
if (this._fakingTime) {
|
|
6296
|
-
this._clock.reset();
|
|
6297
|
-
}
|
|
6298
|
-
}
|
|
6299
|
-
dispose() {
|
|
6300
|
-
this.useRealTimers();
|
|
6301
|
-
}
|
|
6302
|
-
runAllTimers() {
|
|
6303
|
-
if (this._checkFakeTimers()) {
|
|
6304
|
-
this._clock.runAll();
|
|
6305
|
-
}
|
|
6306
|
-
}
|
|
6307
|
-
async runAllTimersAsync() {
|
|
6308
|
-
if (this._checkFakeTimers()) {
|
|
6309
|
-
await this._clock.runAllAsync();
|
|
6310
|
-
}
|
|
6311
|
-
}
|
|
6312
|
-
runOnlyPendingTimers() {
|
|
6313
|
-
if (this._checkFakeTimers()) {
|
|
6314
|
-
this._clock.runToLast();
|
|
6315
|
-
}
|
|
6316
|
-
}
|
|
6317
|
-
async runOnlyPendingTimersAsync() {
|
|
6318
|
-
if (this._checkFakeTimers()) {
|
|
6319
|
-
await this._clock.runToLastAsync();
|
|
6320
|
-
}
|
|
6321
|
-
}
|
|
6322
|
-
advanceTimersToNextTimer(steps = 1) {
|
|
6323
|
-
if (this._checkFakeTimers()) {
|
|
6324
|
-
for (let i = steps; i > 0; i--) {
|
|
6325
|
-
this._clock.next();
|
|
6326
|
-
this._clock.tick(0);
|
|
6327
|
-
if (this._clock.countTimers() === 0) {
|
|
6328
|
-
break;
|
|
6329
|
-
}
|
|
6330
|
-
}
|
|
6331
|
-
}
|
|
6332
|
-
}
|
|
6333
|
-
async advanceTimersToNextTimerAsync(steps = 1) {
|
|
6334
|
-
if (this._checkFakeTimers()) {
|
|
6335
|
-
for (let i = steps; i > 0; i--) {
|
|
6336
|
-
await this._clock.nextAsync();
|
|
6337
|
-
this._clock.tick(0);
|
|
6338
|
-
if (this._clock.countTimers() === 0) {
|
|
6339
|
-
break;
|
|
6340
|
-
}
|
|
6341
|
-
}
|
|
6342
|
-
}
|
|
6343
|
-
}
|
|
6344
|
-
advanceTimersByTime(msToRun) {
|
|
6345
|
-
if (this._checkFakeTimers()) {
|
|
6346
|
-
this._clock.tick(msToRun);
|
|
6347
|
-
}
|
|
6348
|
-
}
|
|
6349
|
-
async advanceTimersByTimeAsync(msToRun) {
|
|
6350
|
-
if (this._checkFakeTimers()) {
|
|
6351
|
-
await this._clock.tickAsync(msToRun);
|
|
6352
|
-
}
|
|
6353
|
-
}
|
|
6354
|
-
advanceTimersToNextFrame() {
|
|
6355
|
-
if (this._checkFakeTimers()) {
|
|
6356
|
-
this._clock.runToFrame();
|
|
6357
|
-
}
|
|
6358
|
-
}
|
|
6359
|
-
runAllTicks() {
|
|
6360
|
-
if (this._checkFakeTimers()) {
|
|
6361
|
-
this._clock.runMicrotasks();
|
|
6362
|
-
}
|
|
6363
|
-
}
|
|
6364
|
-
useRealTimers() {
|
|
6365
|
-
if (this._fakingDate) {
|
|
6366
|
-
resetDate();
|
|
6367
|
-
this._fakingDate = false;
|
|
6368
|
-
}
|
|
6369
|
-
if (this._fakingTime) {
|
|
6370
|
-
this._clock.uninstall();
|
|
6371
|
-
this._fakingTime = false;
|
|
6372
|
-
}
|
|
6373
|
-
}
|
|
6374
|
-
useFakeTimers() {
|
|
6375
|
-
if (this._fakingDate) {
|
|
6376
|
-
throw new Error(
|
|
6377
|
-
'"setSystemTime" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.'
|
|
6378
|
-
);
|
|
6379
|
-
}
|
|
6380
|
-
if (!this._fakingTime) {
|
|
6381
|
-
const toFake = Object.keys(this._fakeTimers.timers).filter(
|
|
6382
|
-
(timer) => timer !== "nextTick"
|
|
6383
|
-
);
|
|
6384
|
-
if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) {
|
|
6385
|
-
throw new Error(
|
|
6386
|
-
"process.nextTick cannot be mocked inside child_process"
|
|
6387
|
-
);
|
|
6388
|
-
}
|
|
6389
|
-
const existingFakedMethods = (this._userConfig?.toFake || toFake).filter(
|
|
6390
|
-
(method) => {
|
|
6391
|
-
switch (method) {
|
|
6392
|
-
case "setImmediate":
|
|
6393
|
-
case "clearImmediate":
|
|
6394
|
-
return method in this._global && this._global[method];
|
|
6395
|
-
default:
|
|
6396
|
-
return true;
|
|
6397
|
-
}
|
|
6398
|
-
}
|
|
6399
|
-
);
|
|
6400
|
-
this._clock = this._fakeTimers.install({
|
|
6401
|
-
now: Date.now(),
|
|
6402
|
-
...this._userConfig,
|
|
6403
|
-
toFake: existingFakedMethods
|
|
6404
|
-
});
|
|
6405
|
-
this._fakingTime = true;
|
|
6406
|
-
}
|
|
6407
|
-
}
|
|
6408
|
-
reset() {
|
|
6409
|
-
if (this._checkFakeTimers()) {
|
|
6410
|
-
const { now: now2 } = this._clock;
|
|
6411
|
-
this._clock.reset();
|
|
6412
|
-
this._clock.setSystemTime(now2);
|
|
6413
|
-
}
|
|
6414
|
-
}
|
|
6415
|
-
setSystemTime(now2) {
|
|
6416
|
-
if (this._fakingTime) {
|
|
6417
|
-
this._clock.setSystemTime(now2);
|
|
6418
|
-
} else {
|
|
6419
|
-
mockDate(now2 ?? this.getRealSystemTime());
|
|
6420
|
-
this._fakingDate = true;
|
|
6421
|
-
}
|
|
6422
|
-
}
|
|
6423
|
-
getRealSystemTime() {
|
|
6424
|
-
return this._now();
|
|
6425
|
-
}
|
|
6426
|
-
getTimerCount() {
|
|
6427
|
-
if (this._checkFakeTimers()) {
|
|
6428
|
-
return this._clock.countTimers();
|
|
6429
|
-
}
|
|
6430
|
-
return 0;
|
|
6431
|
-
}
|
|
6432
|
-
configure(config2) {
|
|
6433
|
-
this._userConfig = config2;
|
|
6434
|
-
}
|
|
6435
|
-
isFakeTimers() {
|
|
6436
|
-
return this._fakingTime;
|
|
6437
|
-
}
|
|
6438
|
-
_checkFakeTimers() {
|
|
6439
|
-
if (!this._fakingTime) {
|
|
6440
|
-
throw new Error(
|
|
6441
|
-
'Timers are not mocked. Try calling "vi.useFakeTimers()" first.'
|
|
6442
|
-
);
|
|
6443
|
-
}
|
|
6444
|
-
return this._fakingTime;
|
|
6445
|
-
}
|
|
6446
|
-
};
|
|
6447
|
-
function copyStackTrace2(target, source) {
|
|
6448
|
-
if (source.stack !== void 0) {
|
|
6449
|
-
target.stack = source.stack.replace(source.message, target.message);
|
|
6450
|
-
}
|
|
6451
|
-
return target;
|
|
6452
|
-
}
|
|
6453
|
-
function waitFor2(callback, options = {}) {
|
|
6454
|
-
const { setTimeout: setTimeout2, setInterval: setInterval2, clearTimeout: clearTimeout2, clearInterval: clearInterval2 } = getSafeTimers();
|
|
6455
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
6456
|
-
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
6457
|
-
return new Promise((resolve, reject) => {
|
|
6458
|
-
let lastError;
|
|
6459
|
-
let promiseStatus = "idle";
|
|
6460
|
-
let timeoutId;
|
|
6461
|
-
let intervalId;
|
|
6462
|
-
const onResolve = (result) => {
|
|
6463
|
-
if (timeoutId) {
|
|
6464
|
-
clearTimeout2(timeoutId);
|
|
6465
|
-
}
|
|
6466
|
-
if (intervalId) {
|
|
6467
|
-
clearInterval2(intervalId);
|
|
6468
|
-
}
|
|
6469
|
-
resolve(result);
|
|
6470
|
-
};
|
|
6471
|
-
const handleTimeout = () => {
|
|
6472
|
-
if (intervalId) {
|
|
6473
|
-
clearInterval2(intervalId);
|
|
6474
|
-
}
|
|
6475
|
-
let error = lastError;
|
|
6476
|
-
if (!error) {
|
|
6477
|
-
error = copyStackTrace2(
|
|
6478
|
-
new Error("Timed out in waitFor!"),
|
|
6479
|
-
STACK_TRACE_ERROR
|
|
6480
|
-
);
|
|
6481
|
-
}
|
|
6482
|
-
reject(error);
|
|
6483
|
-
};
|
|
6484
|
-
const checkCallback = () => {
|
|
6485
|
-
if (vi.isFakeTimers()) {
|
|
6486
|
-
vi.advanceTimersByTime(interval);
|
|
6487
|
-
}
|
|
6488
|
-
if (promiseStatus === "pending") {
|
|
6489
|
-
return;
|
|
6490
|
-
}
|
|
6491
|
-
try {
|
|
6492
|
-
const result = callback();
|
|
6493
|
-
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
6494
|
-
const thenable = result;
|
|
6495
|
-
promiseStatus = "pending";
|
|
6496
|
-
thenable.then(
|
|
6497
|
-
(resolvedValue) => {
|
|
6498
|
-
promiseStatus = "resolved";
|
|
6499
|
-
onResolve(resolvedValue);
|
|
6500
|
-
},
|
|
6501
|
-
(rejectedValue) => {
|
|
6502
|
-
promiseStatus = "rejected";
|
|
6503
|
-
lastError = rejectedValue;
|
|
6504
|
-
}
|
|
6505
|
-
);
|
|
6506
|
-
} else {
|
|
6507
|
-
onResolve(result);
|
|
6508
|
-
return true;
|
|
6509
|
-
}
|
|
6510
|
-
} catch (error) {
|
|
6511
|
-
lastError = error;
|
|
6512
|
-
}
|
|
6513
|
-
};
|
|
6514
|
-
if (checkCallback() === true) {
|
|
6515
|
-
return;
|
|
6516
|
-
}
|
|
6517
|
-
timeoutId = setTimeout2(handleTimeout, timeout);
|
|
6518
|
-
intervalId = setInterval2(checkCallback, interval);
|
|
6519
|
-
});
|
|
6520
|
-
}
|
|
6521
|
-
function waitUntil(callback, options = {}) {
|
|
6522
|
-
const { setTimeout: setTimeout2, setInterval: setInterval2, clearTimeout: clearTimeout2, clearInterval: clearInterval2 } = getSafeTimers();
|
|
6523
|
-
const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
|
|
6524
|
-
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
6525
|
-
return new Promise((resolve, reject) => {
|
|
6526
|
-
let promiseStatus = "idle";
|
|
6527
|
-
let timeoutId;
|
|
6528
|
-
let intervalId;
|
|
6529
|
-
const onReject = (error) => {
|
|
6530
|
-
if (intervalId) {
|
|
6531
|
-
clearInterval2(intervalId);
|
|
6532
|
-
}
|
|
6533
|
-
if (!error) {
|
|
6534
|
-
error = copyStackTrace2(
|
|
6535
|
-
new Error("Timed out in waitUntil!"),
|
|
6536
|
-
STACK_TRACE_ERROR
|
|
6537
|
-
);
|
|
6538
|
-
}
|
|
6539
|
-
reject(error);
|
|
6540
|
-
};
|
|
6541
|
-
const onResolve = (result) => {
|
|
6542
|
-
if (!result) {
|
|
6543
|
-
return;
|
|
6544
|
-
}
|
|
6545
|
-
if (timeoutId) {
|
|
6546
|
-
clearTimeout2(timeoutId);
|
|
6547
|
-
}
|
|
6548
|
-
if (intervalId) {
|
|
6549
|
-
clearInterval2(intervalId);
|
|
6550
|
-
}
|
|
6551
|
-
resolve(result);
|
|
6552
|
-
return true;
|
|
6553
|
-
};
|
|
6554
|
-
const checkCallback = () => {
|
|
6555
|
-
if (vi.isFakeTimers()) {
|
|
6556
|
-
vi.advanceTimersByTime(interval);
|
|
6557
|
-
}
|
|
6558
|
-
if (promiseStatus === "pending") {
|
|
6559
|
-
return;
|
|
6560
|
-
}
|
|
6561
|
-
try {
|
|
6562
|
-
const result = callback();
|
|
6563
|
-
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
6564
|
-
const thenable = result;
|
|
6565
|
-
promiseStatus = "pending";
|
|
6566
|
-
thenable.then(
|
|
6567
|
-
(resolvedValue) => {
|
|
6568
|
-
promiseStatus = "resolved";
|
|
6569
|
-
onResolve(resolvedValue);
|
|
6570
|
-
},
|
|
6571
|
-
(rejectedValue) => {
|
|
6572
|
-
promiseStatus = "rejected";
|
|
6573
|
-
onReject(rejectedValue);
|
|
6574
|
-
}
|
|
6575
|
-
);
|
|
6576
|
-
} else {
|
|
6577
|
-
return onResolve(result);
|
|
6578
|
-
}
|
|
6579
|
-
} catch (error) {
|
|
6580
|
-
onReject(error);
|
|
6581
|
-
}
|
|
6582
|
-
};
|
|
6583
|
-
if (checkCallback() === true) {
|
|
6584
|
-
return;
|
|
6585
|
-
}
|
|
6586
|
-
timeoutId = setTimeout2(onReject, timeout);
|
|
6587
|
-
intervalId = setInterval2(checkCallback, interval);
|
|
6588
|
-
});
|
|
6589
|
-
}
|
|
6590
|
-
function createVitest() {
|
|
6591
|
-
let _mockedDate = null;
|
|
6592
|
-
let _config = null;
|
|
6593
|
-
const workerState = getWorkerState();
|
|
6594
|
-
let _timers;
|
|
6595
|
-
const timers = () => _timers ||= new FakeTimers({
|
|
6596
|
-
global: globalThis,
|
|
6597
|
-
config: workerState.config.fakeTimers
|
|
6598
|
-
});
|
|
6599
|
-
const _stubsGlobal = /* @__PURE__ */ new Map();
|
|
6600
|
-
const _stubsEnv = /* @__PURE__ */ new Map();
|
|
6601
|
-
const _envBooleans = ["PROD", "DEV", "SSR"];
|
|
6602
|
-
const utils = {
|
|
6603
|
-
useFakeTimers(config2) {
|
|
6604
|
-
if (isChildProcess()) {
|
|
6605
|
-
if (config2?.toFake?.includes("nextTick") || workerState.config?.fakeTimers?.toFake?.includes("nextTick")) {
|
|
6606
|
-
throw new Error(
|
|
6607
|
-
'vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.'
|
|
6608
|
-
);
|
|
6609
|
-
}
|
|
6610
|
-
}
|
|
6611
|
-
if (config2) {
|
|
6612
|
-
timers().configure({ ...workerState.config.fakeTimers, ...config2 });
|
|
6613
|
-
} else {
|
|
6614
|
-
timers().configure(workerState.config.fakeTimers);
|
|
6615
|
-
}
|
|
6616
|
-
timers().useFakeTimers();
|
|
6617
|
-
return utils;
|
|
6618
|
-
},
|
|
6619
|
-
isFakeTimers() {
|
|
6620
|
-
return timers().isFakeTimers();
|
|
6621
|
-
},
|
|
6622
|
-
useRealTimers() {
|
|
6623
|
-
timers().useRealTimers();
|
|
6624
|
-
_mockedDate = null;
|
|
6625
|
-
return utils;
|
|
6626
|
-
},
|
|
6627
|
-
runOnlyPendingTimers() {
|
|
6628
|
-
timers().runOnlyPendingTimers();
|
|
6629
|
-
return utils;
|
|
6630
|
-
},
|
|
6631
|
-
async runOnlyPendingTimersAsync() {
|
|
6632
|
-
await timers().runOnlyPendingTimersAsync();
|
|
6633
|
-
return utils;
|
|
6634
|
-
},
|
|
6635
|
-
runAllTimers() {
|
|
6636
|
-
timers().runAllTimers();
|
|
6637
|
-
return utils;
|
|
6638
|
-
},
|
|
6639
|
-
async runAllTimersAsync() {
|
|
6640
|
-
await timers().runAllTimersAsync();
|
|
6641
|
-
return utils;
|
|
6642
|
-
},
|
|
6643
|
-
runAllTicks() {
|
|
6644
|
-
timers().runAllTicks();
|
|
6645
|
-
return utils;
|
|
6646
|
-
},
|
|
6647
|
-
advanceTimersByTime(ms) {
|
|
6648
|
-
timers().advanceTimersByTime(ms);
|
|
6649
|
-
return utils;
|
|
6650
|
-
},
|
|
6651
|
-
async advanceTimersByTimeAsync(ms) {
|
|
6652
|
-
await timers().advanceTimersByTimeAsync(ms);
|
|
6653
|
-
return utils;
|
|
6654
|
-
},
|
|
6655
|
-
advanceTimersToNextTimer() {
|
|
6656
|
-
timers().advanceTimersToNextTimer();
|
|
6657
|
-
return utils;
|
|
6658
|
-
},
|
|
6659
|
-
async advanceTimersToNextTimerAsync() {
|
|
6660
|
-
await timers().advanceTimersToNextTimerAsync();
|
|
6661
|
-
return utils;
|
|
6662
|
-
},
|
|
6663
|
-
advanceTimersToNextFrame() {
|
|
6664
|
-
timers().advanceTimersToNextFrame();
|
|
6665
|
-
return utils;
|
|
6666
|
-
},
|
|
6667
|
-
getTimerCount() {
|
|
6668
|
-
return timers().getTimerCount();
|
|
6669
|
-
},
|
|
6670
|
-
setSystemTime(time) {
|
|
6671
|
-
const date = time instanceof Date ? time : new Date(time);
|
|
6672
|
-
_mockedDate = date;
|
|
6673
|
-
timers().setSystemTime(date);
|
|
6674
|
-
return utils;
|
|
6675
|
-
},
|
|
6676
|
-
getMockedSystemTime() {
|
|
6677
|
-
return _mockedDate;
|
|
6678
|
-
},
|
|
6679
|
-
getRealSystemTime() {
|
|
6680
|
-
return timers().getRealSystemTime();
|
|
6681
|
-
},
|
|
6682
|
-
clearAllTimers() {
|
|
6683
|
-
timers().clearAllTimers();
|
|
6684
|
-
return utils;
|
|
6685
|
-
},
|
|
6686
|
-
// mocks
|
|
6687
|
-
spyOn,
|
|
6688
|
-
fn,
|
|
6689
|
-
waitFor: waitFor2,
|
|
6690
|
-
waitUntil,
|
|
6691
|
-
hoisted(factory) {
|
|
6692
|
-
assertTypes(factory, '"vi.hoisted" factory', ["function"]);
|
|
6693
|
-
return factory();
|
|
6694
|
-
},
|
|
6695
|
-
mock(path, factory) {
|
|
6696
|
-
if (typeof path !== "string") {
|
|
6697
|
-
throw new TypeError(
|
|
6698
|
-
`vi.mock() expects a string path, but received a ${typeof path}`
|
|
6699
|
-
);
|
|
6700
|
-
}
|
|
6701
|
-
const importer = getImporter("mock");
|
|
6702
|
-
_mocker().queueMock(
|
|
6703
|
-
path,
|
|
6704
|
-
importer,
|
|
6705
|
-
typeof factory === "function" ? () => factory(
|
|
6706
|
-
() => _mocker().importActual(
|
|
6707
|
-
path,
|
|
6708
|
-
importer,
|
|
6709
|
-
_mocker().getMockContext().callstack
|
|
6710
|
-
)
|
|
6711
|
-
) : factory
|
|
6712
|
-
);
|
|
6713
|
-
},
|
|
6714
|
-
unmock(path) {
|
|
6715
|
-
if (typeof path !== "string") {
|
|
6716
|
-
throw new TypeError(
|
|
6717
|
-
`vi.unmock() expects a string path, but received a ${typeof path}`
|
|
6718
|
-
);
|
|
6719
|
-
}
|
|
6720
|
-
_mocker().queueUnmock(path, getImporter("unmock"));
|
|
6721
|
-
},
|
|
6722
|
-
doMock(path, factory) {
|
|
6723
|
-
if (typeof path !== "string") {
|
|
6724
|
-
throw new TypeError(
|
|
6725
|
-
`vi.doMock() expects a string path, but received a ${typeof path}`
|
|
6726
|
-
);
|
|
6727
|
-
}
|
|
6728
|
-
const importer = getImporter("doMock");
|
|
6729
|
-
_mocker().queueMock(
|
|
6730
|
-
path,
|
|
6731
|
-
importer,
|
|
6732
|
-
typeof factory === "function" ? () => factory(
|
|
6733
|
-
() => _mocker().importActual(
|
|
6734
|
-
path,
|
|
6735
|
-
importer,
|
|
6736
|
-
_mocker().getMockContext().callstack
|
|
6737
|
-
)
|
|
6738
|
-
) : factory
|
|
6739
|
-
);
|
|
6740
|
-
},
|
|
6741
|
-
doUnmock(path) {
|
|
6742
|
-
if (typeof path !== "string") {
|
|
6743
|
-
throw new TypeError(
|
|
6744
|
-
`vi.doUnmock() expects a string path, but received a ${typeof path}`
|
|
6745
|
-
);
|
|
6746
|
-
}
|
|
6747
|
-
_mocker().queueUnmock(path, getImporter("doUnmock"));
|
|
6748
|
-
},
|
|
6749
|
-
async importActual(path) {
|
|
6750
|
-
return _mocker().importActual(
|
|
6751
|
-
path,
|
|
6752
|
-
getImporter("importActual"),
|
|
6753
|
-
_mocker().getMockContext().callstack
|
|
6754
|
-
);
|
|
6755
|
-
},
|
|
6756
|
-
async importMock(path) {
|
|
6757
|
-
return _mocker().importMock(path, getImporter("importMock"));
|
|
6758
|
-
},
|
|
6759
|
-
// this is typed in the interface so it's not necessary to type it here
|
|
6760
|
-
mocked(item, _options = {}) {
|
|
6761
|
-
return item;
|
|
6762
|
-
},
|
|
6763
|
-
isMockFunction(fn2) {
|
|
6764
|
-
return isMockFunction(fn2);
|
|
6765
|
-
},
|
|
6766
|
-
clearAllMocks() {
|
|
6767
|
-
mocks.forEach((spy) => spy.mockClear());
|
|
6768
|
-
return utils;
|
|
6769
|
-
},
|
|
6770
|
-
resetAllMocks() {
|
|
6771
|
-
mocks.forEach((spy) => spy.mockReset());
|
|
6772
|
-
return utils;
|
|
6773
|
-
},
|
|
6774
|
-
restoreAllMocks() {
|
|
6775
|
-
mocks.forEach((spy) => spy.mockRestore());
|
|
6776
|
-
return utils;
|
|
6777
|
-
},
|
|
6778
|
-
stubGlobal(name, value) {
|
|
6779
|
-
if (!_stubsGlobal.has(name)) {
|
|
6780
|
-
_stubsGlobal.set(
|
|
6781
|
-
name,
|
|
6782
|
-
Object.getOwnPropertyDescriptor(globalThis, name)
|
|
6783
|
-
);
|
|
6784
|
-
}
|
|
6785
|
-
Object.defineProperty(globalThis, name, {
|
|
6786
|
-
value,
|
|
6787
|
-
writable: true,
|
|
6788
|
-
configurable: true,
|
|
6789
|
-
enumerable: true
|
|
6790
|
-
});
|
|
6791
|
-
return utils;
|
|
6792
|
-
},
|
|
6793
|
-
stubEnv(name, value) {
|
|
6794
|
-
if (!_stubsEnv.has(name)) {
|
|
6795
|
-
_stubsEnv.set(name, process.env[name]);
|
|
6796
|
-
}
|
|
6797
|
-
if (_envBooleans.includes(name)) {
|
|
6798
|
-
process.env[name] = value ? "1" : "";
|
|
6799
|
-
} else if (value === void 0) {
|
|
6800
|
-
delete process.env[name];
|
|
6801
|
-
} else {
|
|
6802
|
-
process.env[name] = String(value);
|
|
6803
|
-
}
|
|
6804
|
-
return utils;
|
|
6805
|
-
},
|
|
6806
|
-
unstubAllGlobals() {
|
|
6807
|
-
_stubsGlobal.forEach((original, name) => {
|
|
6808
|
-
if (!original) {
|
|
6809
|
-
Reflect.deleteProperty(globalThis, name);
|
|
6810
|
-
} else {
|
|
6811
|
-
Object.defineProperty(globalThis, name, original);
|
|
6812
|
-
}
|
|
6813
|
-
});
|
|
6814
|
-
_stubsGlobal.clear();
|
|
6815
|
-
return utils;
|
|
6816
|
-
},
|
|
6817
|
-
unstubAllEnvs() {
|
|
6818
|
-
_stubsEnv.forEach((original, name) => {
|
|
6819
|
-
if (original === void 0) {
|
|
6820
|
-
delete process.env[name];
|
|
6821
|
-
} else {
|
|
6822
|
-
process.env[name] = original;
|
|
6823
|
-
}
|
|
6824
|
-
});
|
|
6825
|
-
_stubsEnv.clear();
|
|
6826
|
-
return utils;
|
|
6827
|
-
},
|
|
6828
|
-
resetModules() {
|
|
6829
|
-
resetModules(workerState.moduleCache);
|
|
6830
|
-
return utils;
|
|
6831
|
-
},
|
|
6832
|
-
async dynamicImportSettled() {
|
|
6833
|
-
return waitForImportsToResolve();
|
|
6834
|
-
},
|
|
6835
|
-
setConfig(config2) {
|
|
6836
|
-
if (!_config) {
|
|
6837
|
-
_config = { ...workerState.config };
|
|
6838
|
-
}
|
|
6839
|
-
Object.assign(workerState.config, config2);
|
|
6840
|
-
},
|
|
6841
|
-
resetConfig() {
|
|
6842
|
-
if (_config) {
|
|
6843
|
-
Object.assign(workerState.config, _config);
|
|
6844
|
-
}
|
|
6845
|
-
}
|
|
6846
|
-
};
|
|
6847
|
-
return utils;
|
|
6848
|
-
}
|
|
6849
|
-
var vitest = createVitest();
|
|
6850
|
-
var vi = vitest;
|
|
6851
|
-
function _mocker() {
|
|
6852
|
-
return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy(
|
|
6853
|
-
{},
|
|
6854
|
-
{
|
|
6855
|
-
get(_, name) {
|
|
6856
|
-
throw new Error(
|
|
6857
|
-
`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
|
|
6858
|
-
);
|
|
6859
|
-
}
|
|
6860
|
-
}
|
|
6861
|
-
);
|
|
6227
|
+
requireFakeTimersSrc();
|
|
6228
|
+
typeof process < "u" && process.platform === "win32";
|
|
6229
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
6230
|
+
var intToChar = new Uint8Array(64);
|
|
6231
|
+
var charToInt = new Uint8Array(128);
|
|
6232
|
+
for (let i = 0; i < chars.length; i++) {
|
|
6233
|
+
let c = chars.charCodeAt(i);
|
|
6234
|
+
intToChar[i] = c, charToInt[c] = i;
|
|
6862
6235
|
}
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6236
|
+
var customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/";
|
|
6237
|
+
`
|
|
6238
|
+
|
|
6239
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
6240
|
+
if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
|
|
6241
|
+
const data = specifier.slice(${JSON.stringify(customizationHookNamespace)}.length)
|
|
6242
|
+
const [parsedSpecifier, parsedImporter] = JSON.parse(data)
|
|
6243
|
+
specifier = parsedSpecifier
|
|
6244
|
+
context.parentURL = parsedImporter
|
|
6245
|
+
}
|
|
6246
|
+
return nextResolve(specifier, context)
|
|
6871
6247
|
}
|
|
6872
6248
|
|
|
6249
|
+
`;
|
|
6250
|
+
new Proxy({}, { get(_, p) {
|
|
6251
|
+
throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
|
|
6252
|
+
} });
|
|
6253
|
+
|
|
6873
6254
|
// src/test/setup.ts
|
|
6874
6255
|
globalExpect.extend(matchers_exports);
|
|
6875
6256
|
afterEach$1(() => {
|