@farming-labs/theme 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -26
  2. package/dist/ai-search-dialog.mjs +1 -1
  3. package/dist/code-block-copy-wrapper.d.mts +1 -1
  4. package/dist/docs-layout.d.mts +1 -1
  5. package/dist/docs-layout.mjs +4 -4
  6. package/dist/docs-page-client.mjs +2 -2
  7. package/dist/index.mjs +1 -1
  8. package/dist/mdx.d.mts +1 -1
  9. package/dist/mdx.mjs +1 -1
  10. package/dist/page-actions.mjs +1 -1
  11. package/package.json +2 -2
  12. package/dist/get-app-dir.d.mts +0 -9
  13. package/dist/get-app-dir.test.d.mts +0 -1
  14. package/dist/get-app-dir.test.mjs +0 -41
  15. package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -77
  16. package/dist/node_modules/.pnpm/@vitest_expect@3.2.4/node_modules/@vitest/expect/dist/index.mjs +0 -1356
  17. package/dist/node_modules/.pnpm/@vitest_pretty-format@3.2.4/node_modules/@vitest/pretty-format/dist/index.mjs +0 -1119
  18. package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/chunk-hooks.mjs +0 -1091
  19. package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/index.mjs +0 -4
  20. package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/utils.mjs +0 -3
  21. package/dist/node_modules/.pnpm/@vitest_snapshot@3.2.4/node_modules/@vitest/snapshot/dist/index.mjs +0 -1821
  22. package/dist/node_modules/.pnpm/@vitest_spy@3.2.4/node_modules/@vitest/spy/dist/index.mjs +0 -171
  23. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.mjs +0 -124
  24. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/diff.mjs +0 -1334
  25. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/error.mjs +0 -105
  26. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/helpers.mjs +0 -118
  27. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/index.mjs +0 -455
  28. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/source-map.mjs +0 -168
  29. package/dist/node_modules/.pnpm/chai@5.3.3/node_modules/chai/index.mjs +0 -3087
  30. package/dist/node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.mjs +0 -384
  31. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/arguments.mjs +0 -11
  32. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/array.mjs +0 -16
  33. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/bigint.mjs +0 -11
  34. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/class.mjs +0 -15
  35. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/date.mjs +0 -13
  36. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/error.mjs +0 -34
  37. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/function.mjs +0 -12
  38. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/helpers.mjs +0 -122
  39. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/html.mjs +0 -39
  40. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/index.mjs +0 -99
  41. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/map.mjs +0 -25
  42. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/number.mjs +0 -14
  43. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/object.mjs +0 -21
  44. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/promise.mjs +0 -5
  45. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/regexp.mjs +0 -12
  46. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/set.mjs +0 -18
  47. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/string.mjs +0 -25
  48. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/symbol.mjs +0 -8
  49. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/typedarray.mjs +0 -30
  50. package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +0 -939
  51. package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -81
  52. package/dist/node_modules/.pnpm/strip-literal@3.1.0/node_modules/strip-literal/dist/index.mjs +0 -51
  53. package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.mjs +0 -81
  54. package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.mjs +0 -9
  55. package/dist/node_modules/.pnpm/tinyspy@4.0.4/node_modules/tinyspy/dist/index.mjs +0 -125
  56. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.mjs +0 -8
  57. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.mjs +0 -50
  58. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/utils.XdZDrNZV.mjs +0 -48
  59. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.mjs +0 -2613
  60. package/dist/serialize-icon.d.mts +0 -4
@@ -1,1356 +0,0 @@
1
- import { u } from "../../../../../tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.mjs";
2
- import { stringify } from "../../../../../@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.mjs";
3
- import { assertTypes, getType, isObject, noop } from "../../../../../@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/helpers.mjs";
4
- import { diff, printDiffOrStringify } from "../../../../../@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/diff.mjs";
5
- import { isMockFunction } from "../../../../../@vitest_spy@3.2.4/node_modules/@vitest/spy/dist/index.mjs";
6
- import { processError } from "../../../../../@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/error.mjs";
7
- import { use, utils_exports } from "../../../../../chai@5.3.3/node_modules/chai/index.mjs";
8
-
9
- //#region ../../node_modules/.pnpm/@vitest+expect@3.2.4/node_modules/@vitest/expect/dist/index.js
10
- const MATCHERS_OBJECT = Symbol.for("matchers-object");
11
- const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
12
- const GLOBAL_EXPECT = Symbol.for("expect-global");
13
- const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
14
- const customMatchers = {
15
- toSatisfy(actual, expected, message) {
16
- const { printReceived, printExpected, matcherHint } = this.utils;
17
- const pass = expected(actual);
18
- return {
19
- pass,
20
- message: () => pass ? `\
21
- ${matcherHint(".not.toSatisfy", "received", "")}
22
-
23
- Expected value to not satisfy:
24
- ${message || printExpected(expected)}
25
- Received:
26
- ${printReceived(actual)}` : `\
27
- ${matcherHint(".toSatisfy", "received", "")}
28
-
29
- Expected value to satisfy:
30
- ${message || printExpected(expected)}
31
-
32
- Received:
33
- ${printReceived(actual)}`
34
- };
35
- },
36
- toBeOneOf(actual, expected) {
37
- const { equals, customTesters } = this;
38
- const { printReceived, printExpected, matcherHint } = this.utils;
39
- if (!Array.isArray(expected)) throw new TypeError(`You must provide an array to ${matcherHint(".toBeOneOf")}, not '${typeof expected}'.`);
40
- const pass = expected.length === 0 || expected.some((item) => equals(item, actual, customTesters));
41
- return {
42
- pass,
43
- message: () => pass ? `\
44
- ${matcherHint(".not.toBeOneOf", "received", "")}
45
-
46
- Expected value to not be one of:
47
- ${printExpected(expected)}
48
- Received:
49
- ${printReceived(actual)}` : `\
50
- ${matcherHint(".toBeOneOf", "received", "")}
51
-
52
- Expected value to be one of:
53
- ${printExpected(expected)}
54
-
55
- Received:
56
- ${printReceived(actual)}`
57
- };
58
- }
59
- };
60
- const EXPECTED_COLOR = u.green;
61
- const RECEIVED_COLOR = u.red;
62
- const INVERTED_COLOR = u.inverse;
63
- const BOLD_WEIGHT = u.bold;
64
- const DIM_COLOR = u.dim;
65
- function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
66
- const { comment = "", isDirectExpectCall = false, isNot = false, promise = "", secondArgument = "", expectedColor = EXPECTED_COLOR, receivedColor = RECEIVED_COLOR, secondArgumentColor = EXPECTED_COLOR } = options;
67
- let hint = "";
68
- let dimString = "expect";
69
- if (!isDirectExpectCall && received !== "") {
70
- hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
71
- dimString = ")";
72
- }
73
- if (promise !== "") {
74
- hint += DIM_COLOR(`${dimString}.`) + promise;
75
- dimString = "";
76
- }
77
- if (isNot) {
78
- hint += `${DIM_COLOR(`${dimString}.`)}not`;
79
- dimString = "";
80
- }
81
- if (matcherName.includes(".")) dimString += matcherName;
82
- else {
83
- hint += DIM_COLOR(`${dimString}.`) + matcherName;
84
- dimString = "";
85
- }
86
- if (expected === "") dimString += "()";
87
- else {
88
- hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
89
- if (secondArgument) hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
90
- dimString = ")";
91
- }
92
- if (comment !== "") dimString += ` // ${comment}`;
93
- if (dimString !== "") hint += DIM_COLOR(dimString);
94
- return hint;
95
- }
96
- const SPACE_SYMBOL = "·";
97
- function replaceTrailingSpaces(text) {
98
- return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
99
- }
100
- function printReceived(object) {
101
- return RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
102
- }
103
- function printExpected(value) {
104
- return EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
105
- }
106
- function getMatcherUtils() {
107
- return {
108
- EXPECTED_COLOR,
109
- RECEIVED_COLOR,
110
- INVERTED_COLOR,
111
- BOLD_WEIGHT,
112
- DIM_COLOR,
113
- diff,
114
- matcherHint,
115
- printReceived,
116
- printExpected,
117
- printDiffOrStringify,
118
- printWithType
119
- };
120
- }
121
- function printWithType(name, value, print) {
122
- const type = getType(value);
123
- return (type !== "null" && type !== "undefined" ? `${name} has type: ${type}\n` : "") + `${name} has value: ${print(value)}`;
124
- }
125
- function addCustomEqualityTesters(newTesters) {
126
- if (!Array.isArray(newTesters)) throw new TypeError(`expect.customEqualityTesters: Must be set to an array of Testers. Was given "${getType(newTesters)}"`);
127
- globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters.push(...newTesters);
128
- }
129
- function getCustomEqualityTesters() {
130
- return globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters;
131
- }
132
- function equals(a, b, customTesters, strictCheck) {
133
- customTesters = customTesters || [];
134
- return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
135
- }
136
- const functionToString = Function.prototype.toString;
137
- function isAsymmetric(obj) {
138
- return !!obj && typeof obj === "object" && "asymmetricMatch" in obj && isA("Function", obj.asymmetricMatch);
139
- }
140
- function asymmetricMatch(a, b) {
141
- const asymmetricA = isAsymmetric(a);
142
- const asymmetricB = isAsymmetric(b);
143
- if (asymmetricA && asymmetricB) return;
144
- if (asymmetricA) return a.asymmetricMatch(b);
145
- if (asymmetricB) return b.asymmetricMatch(a);
146
- }
147
- function eq(a, b, aStack, bStack, customTesters, hasKey) {
148
- let result = true;
149
- const asymmetricResult = asymmetricMatch(a, b);
150
- if (asymmetricResult !== void 0) return asymmetricResult;
151
- const testerContext = { equals };
152
- for (let i = 0; i < customTesters.length; i++) {
153
- const customTesterResult = customTesters[i].call(testerContext, a, b, customTesters);
154
- if (customTesterResult !== void 0) return customTesterResult;
155
- }
156
- if (typeof URL === "function" && a instanceof URL && b instanceof URL) return a.href === b.href;
157
- if (Object.is(a, b)) return true;
158
- if (a === null || b === null) return a === b;
159
- const className = Object.prototype.toString.call(a);
160
- if (className !== Object.prototype.toString.call(b)) return false;
161
- switch (className) {
162
- case "[object Boolean]":
163
- case "[object String]":
164
- case "[object Number]": if (typeof a !== typeof b) return false;
165
- else if (typeof a !== "object" && typeof b !== "object") return Object.is(a, b);
166
- else return Object.is(a.valueOf(), b.valueOf());
167
- case "[object Date]": {
168
- const numA = +a;
169
- const numB = +b;
170
- return numA === numB || Number.isNaN(numA) && Number.isNaN(numB);
171
- }
172
- case "[object RegExp]": return a.source === b.source && a.flags === b.flags;
173
- case "[object Temporal.Instant]":
174
- case "[object Temporal.ZonedDateTime]":
175
- case "[object Temporal.PlainDateTime]":
176
- case "[object Temporal.PlainDate]":
177
- case "[object Temporal.PlainTime]":
178
- case "[object Temporal.PlainYearMonth]":
179
- case "[object Temporal.PlainMonthDay]": return a.equals(b);
180
- case "[object Temporal.Duration]": return a.toString() === b.toString();
181
- }
182
- if (typeof a !== "object" || typeof b !== "object") return false;
183
- if (isDomNode(a) && isDomNode(b)) return a.isEqualNode(b);
184
- let length = aStack.length;
185
- while (length--) if (aStack[length] === a) return bStack[length] === b;
186
- else if (bStack[length] === b) return false;
187
- aStack.push(a);
188
- bStack.push(b);
189
- if (className === "[object Array]" && a.length !== b.length) return false;
190
- if (a instanceof Error && b instanceof Error) try {
191
- return isErrorEqual(a, b, aStack, bStack, customTesters, hasKey);
192
- } finally {
193
- aStack.pop();
194
- bStack.pop();
195
- }
196
- const aKeys = keys(a, hasKey);
197
- let key;
198
- let size = aKeys.length;
199
- if (keys(b, hasKey).length !== size) return false;
200
- while (size--) {
201
- key = aKeys[size];
202
- result = hasKey(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, hasKey);
203
- if (!result) return false;
204
- }
205
- aStack.pop();
206
- bStack.pop();
207
- return result;
208
- }
209
- function isErrorEqual(a, b, aStack, bStack, customTesters, hasKey) {
210
- let result = Object.getPrototypeOf(a) === Object.getPrototypeOf(b) && a.name === b.name && a.message === b.message;
211
- if (typeof b.cause !== "undefined") result && (result = eq(a.cause, b.cause, aStack, bStack, customTesters, hasKey));
212
- if (a instanceof AggregateError && b instanceof AggregateError) result && (result = eq(a.errors, b.errors, aStack, bStack, customTesters, hasKey));
213
- result && (result = eq({ ...a }, { ...b }, aStack, bStack, customTesters, hasKey));
214
- return result;
215
- }
216
- function keys(obj, hasKey) {
217
- const keys = [];
218
- for (const key in obj) if (hasKey(obj, key)) keys.push(key);
219
- return keys.concat(Object.getOwnPropertySymbols(obj).filter((symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable));
220
- }
221
- function hasDefinedKey(obj, key) {
222
- return hasKey(obj, key) && obj[key] !== void 0;
223
- }
224
- function hasKey(obj, key) {
225
- return Object.prototype.hasOwnProperty.call(obj, key);
226
- }
227
- function isA(typeName, value) {
228
- return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
229
- }
230
- function isDomNode(obj) {
231
- return obj !== null && typeof obj === "object" && "nodeType" in obj && typeof obj.nodeType === "number" && "nodeName" in obj && typeof obj.nodeName === "string" && "isEqualNode" in obj && typeof obj.isEqualNode === "function";
232
- }
233
- const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
234
- const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
235
- const IS_LIST_SENTINEL = "@@__IMMUTABLE_LIST__@@";
236
- const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
237
- const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
238
- function isImmutableUnorderedKeyed(maybeKeyed) {
239
- return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL] && !maybeKeyed[IS_ORDERED_SENTINEL]);
240
- }
241
- function isImmutableUnorderedSet(maybeSet) {
242
- return !!(maybeSet && maybeSet[IS_SET_SENTINEL] && !maybeSet[IS_ORDERED_SENTINEL]);
243
- }
244
- function isObjectLiteral(source) {
245
- return source != null && typeof source === "object" && !Array.isArray(source);
246
- }
247
- function isImmutableList(source) {
248
- return Boolean(source && isObjectLiteral(source) && source[IS_LIST_SENTINEL]);
249
- }
250
- function isImmutableOrderedKeyed(source) {
251
- return Boolean(source && isObjectLiteral(source) && source[IS_KEYED_SENTINEL] && source[IS_ORDERED_SENTINEL]);
252
- }
253
- function isImmutableOrderedSet(source) {
254
- return Boolean(source && isObjectLiteral(source) && source[IS_SET_SENTINEL] && source[IS_ORDERED_SENTINEL]);
255
- }
256
- function isImmutableRecord(source) {
257
- return Boolean(source && isObjectLiteral(source) && source[IS_RECORD_SYMBOL]);
258
- }
259
- /**
260
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
261
- *
262
- * This source code is licensed under the MIT license found in the
263
- * LICENSE file in the root directory of this source tree.
264
- *
265
- */
266
- const IteratorSymbol = Symbol.iterator;
267
- function hasIterator(object) {
268
- return !!(object != null && object[IteratorSymbol]);
269
- }
270
- function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
271
- if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b)) return;
272
- if (a.constructor !== b.constructor) return false;
273
- let length = aStack.length;
274
- while (length--) if (aStack[length] === a) return bStack[length] === b;
275
- aStack.push(a);
276
- bStack.push(b);
277
- const filteredCustomTesters = [...customTesters.filter((t) => t !== iterableEquality), iterableEqualityWithStack];
278
- function iterableEqualityWithStack(a, b) {
279
- return iterableEquality(a, b, [...customTesters], [...aStack], [...bStack]);
280
- }
281
- if (a.size !== void 0) {
282
- if (a.size !== b.size) return false;
283
- else if (isA("Set", a) || isImmutableUnorderedSet(a)) {
284
- let allFound = true;
285
- for (const aValue of a) if (!b.has(aValue)) {
286
- let has = false;
287
- for (const bValue of b) if (equals(aValue, bValue, filteredCustomTesters) === true) has = true;
288
- if (has === false) {
289
- allFound = false;
290
- break;
291
- }
292
- }
293
- aStack.pop();
294
- bStack.pop();
295
- return allFound;
296
- } else if (isA("Map", a) || isImmutableUnorderedKeyed(a)) {
297
- let allFound = true;
298
- for (const aEntry of a) if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), filteredCustomTesters)) {
299
- let has = false;
300
- for (const bEntry of b) {
301
- const matchedKey = equals(aEntry[0], bEntry[0], filteredCustomTesters);
302
- let matchedValue = false;
303
- if (matchedKey === true) matchedValue = equals(aEntry[1], bEntry[1], filteredCustomTesters);
304
- if (matchedValue === true) has = true;
305
- }
306
- if (has === false) {
307
- allFound = false;
308
- break;
309
- }
310
- }
311
- aStack.pop();
312
- bStack.pop();
313
- return allFound;
314
- }
315
- }
316
- const bIterator = b[IteratorSymbol]();
317
- for (const aValue of a) {
318
- const nextB = bIterator.next();
319
- if (nextB.done || !equals(aValue, nextB.value, filteredCustomTesters)) return false;
320
- }
321
- if (!bIterator.next().done) return false;
322
- if (!isImmutableList(a) && !isImmutableOrderedKeyed(a) && !isImmutableOrderedSet(a) && !isImmutableRecord(a)) {
323
- if (!equals(Object.entries(a), Object.entries(b), filteredCustomTesters)) return false;
324
- }
325
- aStack.pop();
326
- bStack.pop();
327
- return true;
328
- }
329
- /**
330
- * Checks if `hasOwnProperty(object, key)` up the prototype chain, stopping at `Object.prototype`.
331
- */
332
- function hasPropertyInObject(object, key) {
333
- if (!object || typeof object !== "object" || object === Object.prototype) return false;
334
- return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
335
- }
336
- function isObjectWithKeys(a) {
337
- return isObject(a) && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date);
338
- }
339
- function subsetEquality(object, subset, customTesters = []) {
340
- const filteredCustomTesters = customTesters.filter((t) => t !== subsetEquality);
341
- const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object, subset) => {
342
- if (!isObjectWithKeys(subset)) return;
343
- return Object.keys(subset).every((key) => {
344
- if (subset[key] != null && typeof subset[key] === "object") {
345
- if (seenReferences.has(subset[key])) return equals(object[key], subset[key], filteredCustomTesters);
346
- seenReferences.set(subset[key], true);
347
- }
348
- const result = object != null && hasPropertyInObject(object, key) && equals(object[key], subset[key], [...filteredCustomTesters, subsetEqualityWithContext(seenReferences)]);
349
- seenReferences.delete(subset[key]);
350
- return result;
351
- });
352
- };
353
- return subsetEqualityWithContext()(object, subset);
354
- }
355
- function typeEquality(a, b) {
356
- if (a == null || b == null || a.constructor === b.constructor) return;
357
- return false;
358
- }
359
- function arrayBufferEquality(a, b) {
360
- let dataViewA = a;
361
- let dataViewB = b;
362
- if (!(a instanceof DataView && b instanceof DataView)) {
363
- if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer)) return;
364
- try {
365
- dataViewA = new DataView(a);
366
- dataViewB = new DataView(b);
367
- } catch {
368
- return;
369
- }
370
- }
371
- if (dataViewA.byteLength !== dataViewB.byteLength) return false;
372
- for (let i = 0; i < dataViewA.byteLength; i++) if (dataViewA.getUint8(i) !== dataViewB.getUint8(i)) return false;
373
- return true;
374
- }
375
- function sparseArrayEquality(a, b, customTesters = []) {
376
- if (!Array.isArray(a) || !Array.isArray(b)) return;
377
- const aKeys = Object.keys(a);
378
- const bKeys = Object.keys(b);
379
- return equals(a, b, customTesters.filter((t) => t !== sparseArrayEquality), true) && equals(aKeys, bKeys);
380
- }
381
- function generateToBeMessage(deepEqualityName, expected = "#{this}", actual = "#{exp}") {
382
- const toBeMessage = `expected ${expected} to be ${actual} // Object.is equality`;
383
- if (["toStrictEqual", "toEqual"].includes(deepEqualityName)) return `${toBeMessage}\n\nIf it should pass with deep equality, replace "toBe" with "${deepEqualityName}"\n\nExpected: ${expected}\nReceived: serializes to the same string\n`;
384
- return toBeMessage;
385
- }
386
- function pluralize(word, count) {
387
- return `${count} ${word}${count === 1 ? "" : "s"}`;
388
- }
389
- function getObjectKeys(object) {
390
- return [...Object.keys(object), ...Object.getOwnPropertySymbols(object).filter((s) => {
391
- var _Object$getOwnPropert;
392
- return (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(object, s)) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.enumerable;
393
- })];
394
- }
395
- function getObjectSubset(object, subset, customTesters) {
396
- let stripped = 0;
397
- const getObjectSubsetWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object, subset) => {
398
- if (Array.isArray(object)) {
399
- if (Array.isArray(subset) && subset.length === object.length) return subset.map((sub, i) => getObjectSubsetWithContext(seenReferences)(object[i], sub));
400
- } else if (object instanceof Date) return object;
401
- else if (isObject(object) && isObject(subset)) {
402
- if (equals(object, subset, [
403
- ...customTesters,
404
- iterableEquality,
405
- subsetEquality
406
- ])) return subset;
407
- const trimmed = {};
408
- seenReferences.set(object, trimmed);
409
- if (typeof object.constructor === "function" && typeof object.constructor.name === "string") Object.defineProperty(trimmed, "constructor", {
410
- enumerable: false,
411
- value: object.constructor
412
- });
413
- for (const key of getObjectKeys(object)) if (hasPropertyInObject(subset, key)) trimmed[key] = seenReferences.has(object[key]) ? seenReferences.get(object[key]) : getObjectSubsetWithContext(seenReferences)(object[key], subset[key]);
414
- else if (!seenReferences.has(object[key])) {
415
- stripped += 1;
416
- if (isObject(object[key])) stripped += getObjectKeys(object[key]).length;
417
- getObjectSubsetWithContext(seenReferences)(object[key], subset[key]);
418
- }
419
- if (getObjectKeys(trimmed).length > 0) return trimmed;
420
- }
421
- return object;
422
- };
423
- return {
424
- subset: getObjectSubsetWithContext()(object, subset),
425
- stripped
426
- };
427
- }
428
- if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
429
- const globalState = /* @__PURE__ */ new WeakMap();
430
- const matchers = Object.create(null);
431
- const customEqualityTesters = [];
432
- const asymmetricMatchers = Object.create(null);
433
- Object.defineProperty(globalThis, MATCHERS_OBJECT, { get: () => globalState });
434
- Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
435
- configurable: true,
436
- get: () => ({
437
- state: globalState.get(globalThis[GLOBAL_EXPECT]),
438
- matchers,
439
- customEqualityTesters
440
- })
441
- });
442
- Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, { get: () => asymmetricMatchers });
443
- }
444
- function getState(expect) {
445
- return globalThis[MATCHERS_OBJECT].get(expect);
446
- }
447
- function setState(state, expect) {
448
- const map = globalThis[MATCHERS_OBJECT];
449
- const current = map.get(expect) || {};
450
- const results = Object.defineProperties(current, {
451
- ...Object.getOwnPropertyDescriptors(current),
452
- ...Object.getOwnPropertyDescriptors(state)
453
- });
454
- map.set(expect, results);
455
- }
456
- var AsymmetricMatcher = class {
457
- $$typeof = Symbol.for("jest.asymmetricMatcher");
458
- constructor(sample, inverse = false) {
459
- this.sample = sample;
460
- this.inverse = inverse;
461
- }
462
- getMatcherContext(expect) {
463
- return {
464
- ...getState(expect || globalThis[GLOBAL_EXPECT]),
465
- equals,
466
- isNot: this.inverse,
467
- customTesters: getCustomEqualityTesters(),
468
- utils: {
469
- ...getMatcherUtils(),
470
- diff,
471
- stringify,
472
- iterableEquality,
473
- subsetEquality
474
- }
475
- };
476
- }
477
- };
478
- AsymmetricMatcher.prototype[Symbol.for("chai/inspect")] = function(options) {
479
- const result = stringify(this, options.depth, { min: true });
480
- if (result.length <= options.truncate) return result;
481
- return `${this.toString()}{…}`;
482
- };
483
- var StringContaining = class extends AsymmetricMatcher {
484
- constructor(sample, inverse = false) {
485
- if (!isA("String", sample)) throw new Error("Expected is not a string");
486
- super(sample, inverse);
487
- }
488
- asymmetricMatch(other) {
489
- const result = isA("String", other) && other.includes(this.sample);
490
- return this.inverse ? !result : result;
491
- }
492
- toString() {
493
- return `String${this.inverse ? "Not" : ""}Containing`;
494
- }
495
- getExpectedType() {
496
- return "string";
497
- }
498
- };
499
- var Anything = class extends AsymmetricMatcher {
500
- asymmetricMatch(other) {
501
- return other != null;
502
- }
503
- toString() {
504
- return "Anything";
505
- }
506
- toAsymmetricMatcher() {
507
- return "Anything";
508
- }
509
- };
510
- var ObjectContaining = class extends AsymmetricMatcher {
511
- constructor(sample, inverse = false) {
512
- super(sample, inverse);
513
- }
514
- getPrototype(obj) {
515
- if (Object.getPrototypeOf) return Object.getPrototypeOf(obj);
516
- if (obj.constructor.prototype === obj) return null;
517
- return obj.constructor.prototype;
518
- }
519
- hasProperty(obj, property) {
520
- if (!obj) return false;
521
- if (Object.prototype.hasOwnProperty.call(obj, property)) return true;
522
- return this.hasProperty(this.getPrototype(obj), property);
523
- }
524
- asymmetricMatch(other) {
525
- if (typeof this.sample !== "object") throw new TypeError(`You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`);
526
- let result = true;
527
- const matcherContext = this.getMatcherContext();
528
- for (const property in this.sample) if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property], matcherContext.customTesters)) {
529
- result = false;
530
- break;
531
- }
532
- return this.inverse ? !result : result;
533
- }
534
- toString() {
535
- return `Object${this.inverse ? "Not" : ""}Containing`;
536
- }
537
- getExpectedType() {
538
- return "object";
539
- }
540
- };
541
- var ArrayContaining = class extends AsymmetricMatcher {
542
- constructor(sample, inverse = false) {
543
- super(sample, inverse);
544
- }
545
- asymmetricMatch(other) {
546
- if (!Array.isArray(this.sample)) throw new TypeError(`You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`);
547
- const matcherContext = this.getMatcherContext();
548
- const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every((item) => other.some((another) => equals(item, another, matcherContext.customTesters)));
549
- return this.inverse ? !result : result;
550
- }
551
- toString() {
552
- return `Array${this.inverse ? "Not" : ""}Containing`;
553
- }
554
- getExpectedType() {
555
- return "array";
556
- }
557
- };
558
- var Any = class extends AsymmetricMatcher {
559
- constructor(sample) {
560
- if (typeof sample === "undefined") throw new TypeError("any() expects to be passed a constructor function. Please pass one or use anything() to match any object.");
561
- super(sample);
562
- }
563
- fnNameFor(func) {
564
- if (func.name) return func.name;
565
- const matches = Function.prototype.toString.call(func).match(/^(?:async)?\s*function\s*(?:\*\s*)?([\w$]+)\s*\(/);
566
- return matches ? matches[1] : "<anonymous>";
567
- }
568
- asymmetricMatch(other) {
569
- if (this.sample === String) return typeof other == "string" || other instanceof String;
570
- if (this.sample === Number) return typeof other == "number" || other instanceof Number;
571
- if (this.sample === Function) return typeof other == "function" || typeof other === "function";
572
- if (this.sample === Boolean) return typeof other == "boolean" || other instanceof Boolean;
573
- if (this.sample === BigInt) return typeof other == "bigint" || other instanceof BigInt;
574
- if (this.sample === Symbol) return typeof other == "symbol" || other instanceof Symbol;
575
- if (this.sample === Object) return typeof other == "object";
576
- return other instanceof this.sample;
577
- }
578
- toString() {
579
- return "Any";
580
- }
581
- getExpectedType() {
582
- if (this.sample === String) return "string";
583
- if (this.sample === Number) return "number";
584
- if (this.sample === Function) return "function";
585
- if (this.sample === Object) return "object";
586
- if (this.sample === Boolean) return "boolean";
587
- return this.fnNameFor(this.sample);
588
- }
589
- toAsymmetricMatcher() {
590
- return `Any<${this.fnNameFor(this.sample)}>`;
591
- }
592
- };
593
- var StringMatching = class extends AsymmetricMatcher {
594
- constructor(sample, inverse = false) {
595
- if (!isA("String", sample) && !isA("RegExp", sample)) throw new Error("Expected is not a String or a RegExp");
596
- super(new RegExp(sample), inverse);
597
- }
598
- asymmetricMatch(other) {
599
- const result = isA("String", other) && this.sample.test(other);
600
- return this.inverse ? !result : result;
601
- }
602
- toString() {
603
- return `String${this.inverse ? "Not" : ""}Matching`;
604
- }
605
- getExpectedType() {
606
- return "string";
607
- }
608
- };
609
- var CloseTo = class extends AsymmetricMatcher {
610
- precision;
611
- constructor(sample, precision = 2, inverse = false) {
612
- if (!isA("Number", sample)) throw new Error("Expected is not a Number");
613
- if (!isA("Number", precision)) throw new Error("Precision is not a Number");
614
- super(sample);
615
- this.inverse = inverse;
616
- this.precision = precision;
617
- }
618
- asymmetricMatch(other) {
619
- if (!isA("Number", other)) return false;
620
- let result = false;
621
- if (other === Number.POSITIVE_INFINITY && this.sample === Number.POSITIVE_INFINITY) result = true;
622
- else if (other === Number.NEGATIVE_INFINITY && this.sample === Number.NEGATIVE_INFINITY) result = true;
623
- else result = Math.abs(this.sample - other) < 10 ** -this.precision / 2;
624
- return this.inverse ? !result : result;
625
- }
626
- toString() {
627
- return `Number${this.inverse ? "Not" : ""}CloseTo`;
628
- }
629
- getExpectedType() {
630
- return "number";
631
- }
632
- toAsymmetricMatcher() {
633
- return [
634
- this.toString(),
635
- this.sample,
636
- `(${pluralize("digit", this.precision)})`
637
- ].join(" ");
638
- }
639
- };
640
- const JestAsymmetricMatchers = (chai, utils) => {
641
- utils.addMethod(chai.expect, "anything", () => new Anything());
642
- utils.addMethod(chai.expect, "any", (expected) => new Any(expected));
643
- utils.addMethod(chai.expect, "stringContaining", (expected) => new StringContaining(expected));
644
- utils.addMethod(chai.expect, "objectContaining", (expected) => new ObjectContaining(expected));
645
- utils.addMethod(chai.expect, "arrayContaining", (expected) => new ArrayContaining(expected));
646
- utils.addMethod(chai.expect, "stringMatching", (expected) => new StringMatching(expected));
647
- utils.addMethod(chai.expect, "closeTo", (expected, precision) => new CloseTo(expected, precision));
648
- chai.expect.not = {
649
- stringContaining: (expected) => new StringContaining(expected, true),
650
- objectContaining: (expected) => new ObjectContaining(expected, true),
651
- arrayContaining: (expected) => new ArrayContaining(expected, true),
652
- stringMatching: (expected) => new StringMatching(expected, true),
653
- closeTo: (expected, precision) => new CloseTo(expected, precision, true)
654
- };
655
- };
656
- function createAssertionMessage(util, assertion, hasArgs) {
657
- const not = util.flag(assertion, "negate") ? "not." : "";
658
- const name = `${util.flag(assertion, "_name")}(${hasArgs ? "expected" : ""})`;
659
- const promiseName = util.flag(assertion, "promise");
660
- return `expect(actual)${promiseName ? `.${promiseName}` : ""}.${not}${name}`;
661
- }
662
- function recordAsyncExpect(_test, promise, assertion, error) {
663
- const test = _test;
664
- if (test && promise instanceof Promise) {
665
- promise = promise.finally(() => {
666
- if (!test.promises) return;
667
- const index = test.promises.indexOf(promise);
668
- if (index !== -1) test.promises.splice(index, 1);
669
- });
670
- if (!test.promises) test.promises = [];
671
- test.promises.push(promise);
672
- let resolved = false;
673
- test.onFinished ?? (test.onFinished = []);
674
- test.onFinished.push(() => {
675
- if (!resolved) {
676
- var _vitest_worker__;
677
- const stack = (((_vitest_worker__ = globalThis.__vitest_worker__) === null || _vitest_worker__ === void 0 ? void 0 : _vitest_worker__.onFilterStackTrace) || ((s) => s || ""))(error.stack);
678
- console.warn([
679
- `Promise returned by \`${assertion}\` was not awaited. `,
680
- "Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
681
- "Please remember to await the assertion.\n",
682
- stack
683
- ].join(""));
684
- }
685
- });
686
- return {
687
- then(onFulfilled, onRejected) {
688
- resolved = true;
689
- return promise.then(onFulfilled, onRejected);
690
- },
691
- catch(onRejected) {
692
- return promise.catch(onRejected);
693
- },
694
- finally(onFinally) {
695
- return promise.finally(onFinally);
696
- },
697
- [Symbol.toStringTag]: "Promise"
698
- };
699
- }
700
- return promise;
701
- }
702
- function handleTestError(test, err) {
703
- var _test$result;
704
- test.result || (test.result = { state: "fail" });
705
- test.result.state = "fail";
706
- (_test$result = test.result).errors || (_test$result.errors = []);
707
- test.result.errors.push(processError(err));
708
- }
709
- function wrapAssertion(utils, name, fn) {
710
- return function(...args) {
711
- if (name !== "withTest") utils.flag(this, "_name", name);
712
- if (!utils.flag(this, "soft")) return fn.apply(this, args);
713
- const test = utils.flag(this, "vitest-test");
714
- if (!test) throw new Error("expect.soft() can only be used inside a test");
715
- try {
716
- const result = fn.apply(this, args);
717
- if (result && typeof result === "object" && typeof result.then === "function") return result.then(noop, (err) => {
718
- handleTestError(test, err);
719
- });
720
- return result;
721
- } catch (err) {
722
- handleTestError(test, err);
723
- }
724
- };
725
- }
726
- const JestChaiExpect = (chai, utils) => {
727
- const { AssertionError } = chai;
728
- const customTesters = getCustomEqualityTesters();
729
- function def(name, fn) {
730
- const addMethod = (n) => {
731
- const softWrapper = wrapAssertion(utils, n, fn);
732
- utils.addMethod(chai.Assertion.prototype, n, softWrapper);
733
- utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, n, softWrapper);
734
- };
735
- if (Array.isArray(name)) name.forEach((n) => addMethod(n));
736
- else addMethod(name);
737
- }
738
- [
739
- "throw",
740
- "throws",
741
- "Throw"
742
- ].forEach((m) => {
743
- utils.overwriteMethod(chai.Assertion.prototype, m, (_super) => {
744
- return function(...args) {
745
- const promise = utils.flag(this, "promise");
746
- const object = utils.flag(this, "object");
747
- const isNot = utils.flag(this, "negate");
748
- if (promise === "rejects") utils.flag(this, "object", () => {
749
- throw object;
750
- });
751
- else if (promise === "resolves" && typeof object !== "function") if (!isNot) throw new AssertionError(utils.flag(this, "message") || "expected promise to throw an error, but it didn't", { showDiff: false }, utils.flag(this, "ssfi"));
752
- else return;
753
- _super.apply(this, args);
754
- };
755
- });
756
- });
757
- def("withTest", function(test) {
758
- utils.flag(this, "vitest-test", test);
759
- return this;
760
- });
761
- def("toEqual", function(expected) {
762
- const actual = utils.flag(this, "object");
763
- const equal = equals(actual, expected, [...customTesters, iterableEquality]);
764
- return this.assert(equal, "expected #{this} to deeply equal #{exp}", "expected #{this} to not deeply equal #{exp}", expected, actual);
765
- });
766
- def("toStrictEqual", function(expected) {
767
- const obj = utils.flag(this, "object");
768
- const equal = equals(obj, expected, [
769
- ...customTesters,
770
- iterableEquality,
771
- typeEquality,
772
- sparseArrayEquality,
773
- arrayBufferEquality
774
- ], true);
775
- return this.assert(equal, "expected #{this} to strictly equal #{exp}", "expected #{this} to not strictly equal #{exp}", expected, obj);
776
- });
777
- def("toBe", function(expected) {
778
- const actual = this._obj;
779
- const pass = Object.is(actual, expected);
780
- let deepEqualityName = "";
781
- if (!pass) {
782
- if (equals(actual, expected, [
783
- ...customTesters,
784
- iterableEquality,
785
- typeEquality,
786
- sparseArrayEquality,
787
- arrayBufferEquality
788
- ], true)) deepEqualityName = "toStrictEqual";
789
- else if (equals(actual, expected, [...customTesters, iterableEquality])) deepEqualityName = "toEqual";
790
- }
791
- return this.assert(pass, generateToBeMessage(deepEqualityName), "expected #{this} not to be #{exp} // Object.is equality", expected, actual);
792
- });
793
- def("toMatchObject", function(expected) {
794
- const actual = this._obj;
795
- const pass = equals(actual, expected, [
796
- ...customTesters,
797
- iterableEquality,
798
- subsetEquality
799
- ]);
800
- const isNot = utils.flag(this, "negate");
801
- const { subset: actualSubset, stripped } = getObjectSubset(actual, expected, customTesters);
802
- if (pass && isNot || !pass && !isNot) {
803
- const msg = utils.getMessage(this, [
804
- pass,
805
- "expected #{this} to match object #{exp}",
806
- "expected #{this} to not match object #{exp}",
807
- expected,
808
- actualSubset,
809
- false
810
- ]);
811
- throw new AssertionError(stripped === 0 ? msg : `${msg}\n(${stripped} matching ${stripped === 1 ? "property" : "properties"} omitted from actual)`, {
812
- showDiff: true,
813
- expected,
814
- actual: actualSubset
815
- });
816
- }
817
- });
818
- def("toMatch", function(expected) {
819
- const actual = this._obj;
820
- if (typeof actual !== "string") throw new TypeError(`.toMatch() expects to receive a string, but got ${typeof actual}`);
821
- return this.assert(typeof expected === "string" ? actual.includes(expected) : actual.match(expected), `expected #{this} to match #{exp}`, `expected #{this} not to match #{exp}`, expected, actual);
822
- });
823
- def("toContain", function(item) {
824
- const actual = this._obj;
825
- if (typeof Node !== "undefined" && actual instanceof Node) {
826
- if (!(item instanceof Node)) throw new TypeError(`toContain() expected a DOM node as the argument, but got ${typeof item}`);
827
- return this.assert(actual.contains(item), "expected #{this} to contain element #{exp}", "expected #{this} not to contain element #{exp}", item, actual);
828
- }
829
- if (typeof DOMTokenList !== "undefined" && actual instanceof DOMTokenList) {
830
- assertTypes(item, "class name", ["string"]);
831
- const expectedClassList = utils.flag(this, "negate") ? actual.value.replace(item, "").trim() : `${actual.value} ${item}`;
832
- return this.assert(actual.contains(item), `expected "${actual.value}" to contain "${item}"`, `expected "${actual.value}" not to contain "${item}"`, expectedClassList, actual.value);
833
- }
834
- if (typeof actual === "string" && typeof item === "string") return this.assert(actual.includes(item), `expected #{this} to contain #{exp}`, `expected #{this} not to contain #{exp}`, item, actual);
835
- if (actual != null && typeof actual !== "string") utils.flag(this, "object", Array.from(actual));
836
- return this.contain(item);
837
- });
838
- def("toContainEqual", function(expected) {
839
- const obj = utils.flag(this, "object");
840
- const index = Array.from(obj).findIndex((item) => {
841
- return equals(item, expected, customTesters);
842
- });
843
- this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
844
- });
845
- def("toBeTruthy", function() {
846
- const obj = utils.flag(this, "object");
847
- this.assert(Boolean(obj), "expected #{this} to be truthy", "expected #{this} to not be truthy", true, obj);
848
- });
849
- def("toBeFalsy", function() {
850
- const obj = utils.flag(this, "object");
851
- this.assert(!obj, "expected #{this} to be falsy", "expected #{this} to not be falsy", false, obj);
852
- });
853
- def("toBeGreaterThan", function(expected) {
854
- const actual = this._obj;
855
- assertTypes(actual, "actual", ["number", "bigint"]);
856
- assertTypes(expected, "expected", ["number", "bigint"]);
857
- return this.assert(actual > expected, `expected ${actual} to be greater than ${expected}`, `expected ${actual} to be not greater than ${expected}`, expected, actual, false);
858
- });
859
- def("toBeGreaterThanOrEqual", function(expected) {
860
- const actual = this._obj;
861
- assertTypes(actual, "actual", ["number", "bigint"]);
862
- assertTypes(expected, "expected", ["number", "bigint"]);
863
- return this.assert(actual >= expected, `expected ${actual} to be greater than or equal to ${expected}`, `expected ${actual} to be not greater than or equal to ${expected}`, expected, actual, false);
864
- });
865
- def("toBeLessThan", function(expected) {
866
- const actual = this._obj;
867
- assertTypes(actual, "actual", ["number", "bigint"]);
868
- assertTypes(expected, "expected", ["number", "bigint"]);
869
- return this.assert(actual < expected, `expected ${actual} to be less than ${expected}`, `expected ${actual} to be not less than ${expected}`, expected, actual, false);
870
- });
871
- def("toBeLessThanOrEqual", function(expected) {
872
- const actual = this._obj;
873
- assertTypes(actual, "actual", ["number", "bigint"]);
874
- assertTypes(expected, "expected", ["number", "bigint"]);
875
- return this.assert(actual <= expected, `expected ${actual} to be less than or equal to ${expected}`, `expected ${actual} to be not less than or equal to ${expected}`, expected, actual, false);
876
- });
877
- def("toBeNaN", function() {
878
- const obj = utils.flag(this, "object");
879
- this.assert(Number.isNaN(obj), "expected #{this} to be NaN", "expected #{this} not to be NaN", NaN, obj);
880
- });
881
- def("toBeUndefined", function() {
882
- const obj = utils.flag(this, "object");
883
- this.assert(void 0 === obj, "expected #{this} to be undefined", "expected #{this} not to be undefined", void 0, obj);
884
- });
885
- def("toBeNull", function() {
886
- const obj = utils.flag(this, "object");
887
- this.assert(obj === null, "expected #{this} to be null", "expected #{this} not to be null", null, obj);
888
- });
889
- def("toBeDefined", function() {
890
- const obj = utils.flag(this, "object");
891
- this.assert(typeof obj !== "undefined", "expected #{this} to be defined", "expected #{this} to be undefined", obj);
892
- });
893
- def("toBeTypeOf", function(expected) {
894
- const actual = typeof this._obj;
895
- const equal = expected === actual;
896
- return this.assert(equal, "expected #{this} to be type of #{exp}", "expected #{this} not to be type of #{exp}", expected, actual);
897
- });
898
- def("toBeInstanceOf", function(obj) {
899
- return this.instanceOf(obj);
900
- });
901
- def("toHaveLength", function(length) {
902
- return this.have.length(length);
903
- });
904
- def("toHaveProperty", function(...args) {
905
- if (Array.isArray(args[0])) args[0] = args[0].map((key) => String(key).replace(/([.[\]])/g, "\\$1")).join(".");
906
- const actual = this._obj;
907
- const [propertyName, expected] = args;
908
- const getValue = () => {
909
- if (Object.prototype.hasOwnProperty.call(actual, propertyName)) return {
910
- value: actual[propertyName],
911
- exists: true
912
- };
913
- return utils.getPathInfo(actual, propertyName);
914
- };
915
- const { value, exists } = getValue();
916
- const pass = exists && (args.length === 1 || equals(expected, value, customTesters));
917
- const valueString = args.length === 1 ? "" : ` with value ${utils.objDisplay(expected)}`;
918
- return this.assert(pass, `expected #{this} to have property "${propertyName}"${valueString}`, `expected #{this} to not have property "${propertyName}"${valueString}`, expected, exists ? value : void 0);
919
- });
920
- def("toBeCloseTo", function(received, precision = 2) {
921
- const expected = this._obj;
922
- let pass = false;
923
- let expectedDiff = 0;
924
- let receivedDiff = 0;
925
- if (received === Number.POSITIVE_INFINITY && expected === Number.POSITIVE_INFINITY) pass = true;
926
- else if (received === Number.NEGATIVE_INFINITY && expected === Number.NEGATIVE_INFINITY) pass = true;
927
- else {
928
- expectedDiff = 10 ** -precision / 2;
929
- receivedDiff = Math.abs(expected - received);
930
- pass = receivedDiff < expectedDiff;
931
- }
932
- return this.assert(pass, `expected #{this} to be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`, `expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`, received, expected, false);
933
- });
934
- function assertIsMock(assertion) {
935
- if (!isMockFunction(assertion._obj)) throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
936
- }
937
- function getSpy(assertion) {
938
- assertIsMock(assertion);
939
- return assertion._obj;
940
- }
941
- def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
942
- const spy = getSpy(this);
943
- const spyName = spy.getMockName();
944
- const callCount = spy.mock.calls.length;
945
- return this.assert(callCount === number, `expected "${spyName}" to be called #{exp} times, but got ${callCount} times`, `expected "${spyName}" to not be called #{exp} times`, number, callCount, false);
946
- });
947
- def("toHaveBeenCalledOnce", function() {
948
- const spy = getSpy(this);
949
- const spyName = spy.getMockName();
950
- const callCount = spy.mock.calls.length;
951
- return this.assert(callCount === 1, `expected "${spyName}" to be called once, but got ${callCount} times`, `expected "${spyName}" to not be called once`, 1, callCount, false);
952
- });
953
- def(["toHaveBeenCalled", "toBeCalled"], function() {
954
- const spy = getSpy(this);
955
- const spyName = spy.getMockName();
956
- const callCount = spy.mock.calls.length;
957
- const called = callCount > 0;
958
- const isNot = utils.flag(this, "negate");
959
- let msg = utils.getMessage(this, [
960
- called,
961
- `expected "${spyName}" to be called at least once`,
962
- `expected "${spyName}" to not be called at all, but actually been called ${callCount} times`,
963
- true,
964
- called
965
- ]);
966
- if (called && isNot) msg = formatCalls(spy, msg);
967
- if (called && isNot || !called && !isNot) throw new AssertionError(msg);
968
- });
969
- function equalsArgumentArray(a, b) {
970
- return a.length === b.length && a.every((aItem, i) => equals(aItem, b[i], [...customTesters, iterableEquality]));
971
- }
972
- def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
973
- const spy = getSpy(this);
974
- const spyName = spy.getMockName();
975
- const pass = spy.mock.calls.some((callArg) => equalsArgumentArray(callArg, args));
976
- const isNot = utils.flag(this, "negate");
977
- const msg = utils.getMessage(this, [
978
- pass,
979
- `expected "${spyName}" to be called with arguments: #{exp}`,
980
- `expected "${spyName}" to not be called with arguments: #{exp}`,
981
- args
982
- ]);
983
- if (pass && isNot || !pass && !isNot) throw new AssertionError(formatCalls(spy, msg, args));
984
- });
985
- def("toHaveBeenCalledExactlyOnceWith", function(...args) {
986
- const spy = getSpy(this);
987
- const spyName = spy.getMockName();
988
- const callCount = spy.mock.calls.length;
989
- const pass = spy.mock.calls.some((callArg) => equalsArgumentArray(callArg, args)) && callCount === 1;
990
- const isNot = utils.flag(this, "negate");
991
- const msg = utils.getMessage(this, [
992
- pass,
993
- `expected "${spyName}" to be called once with arguments: #{exp}`,
994
- `expected "${spyName}" to not be called once with arguments: #{exp}`,
995
- args
996
- ]);
997
- if (pass && isNot || !pass && !isNot) throw new AssertionError(formatCalls(spy, msg, args));
998
- });
999
- def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
1000
- const spy = getSpy(this);
1001
- const spyName = spy.getMockName();
1002
- const nthCall = spy.mock.calls[times - 1];
1003
- const callCount = spy.mock.calls.length;
1004
- const isCalled = times <= callCount;
1005
- this.assert(nthCall && equalsArgumentArray(nthCall, args), `expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}${isCalled ? `` : `, but called only ${callCount} times`}`, `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`, args, nthCall, isCalled);
1006
- });
1007
- def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
1008
- const spy = getSpy(this);
1009
- const spyName = spy.getMockName();
1010
- const lastCall = spy.mock.calls[spy.mock.calls.length - 1];
1011
- this.assert(lastCall && equalsArgumentArray(lastCall, args), `expected last "${spyName}" call to have been called with #{exp}`, `expected last "${spyName}" call to not have been called with #{exp}`, args, lastCall);
1012
- });
1013
- /**
1014
- * Used for `toHaveBeenCalledBefore` and `toHaveBeenCalledAfter` to determine if the expected spy was called before the result spy.
1015
- */
1016
- function isSpyCalledBeforeAnotherSpy(beforeSpy, afterSpy, failIfNoFirstInvocation) {
1017
- const beforeInvocationCallOrder = beforeSpy.mock.invocationCallOrder;
1018
- const afterInvocationCallOrder = afterSpy.mock.invocationCallOrder;
1019
- if (beforeInvocationCallOrder.length === 0) return !failIfNoFirstInvocation;
1020
- if (afterInvocationCallOrder.length === 0) return false;
1021
- return beforeInvocationCallOrder[0] < afterInvocationCallOrder[0];
1022
- }
1023
- def(["toHaveBeenCalledBefore"], function(resultSpy, failIfNoFirstInvocation = true) {
1024
- const expectSpy = getSpy(this);
1025
- if (!isMockFunction(resultSpy)) throw new TypeError(`${utils.inspect(resultSpy)} is not a spy or a call to a spy`);
1026
- this.assert(isSpyCalledBeforeAnotherSpy(expectSpy, resultSpy, failIfNoFirstInvocation), `expected "${expectSpy.getMockName()}" to have been called before "${resultSpy.getMockName()}"`, `expected "${expectSpy.getMockName()}" to not have been called before "${resultSpy.getMockName()}"`, resultSpy, expectSpy);
1027
- });
1028
- def(["toHaveBeenCalledAfter"], function(resultSpy, failIfNoFirstInvocation = true) {
1029
- const expectSpy = getSpy(this);
1030
- if (!isMockFunction(resultSpy)) throw new TypeError(`${utils.inspect(resultSpy)} is not a spy or a call to a spy`);
1031
- this.assert(isSpyCalledBeforeAnotherSpy(resultSpy, expectSpy, failIfNoFirstInvocation), `expected "${expectSpy.getMockName()}" to have been called after "${resultSpy.getMockName()}"`, `expected "${expectSpy.getMockName()}" to not have been called after "${resultSpy.getMockName()}"`, resultSpy, expectSpy);
1032
- });
1033
- def(["toThrow", "toThrowError"], function(expected) {
1034
- if (typeof expected === "string" || typeof expected === "undefined" || expected instanceof RegExp) return this.throws(expected === "" ? /^$/ : expected);
1035
- const obj = this._obj;
1036
- const promise = utils.flag(this, "promise");
1037
- const isNot = utils.flag(this, "negate");
1038
- let thrown = null;
1039
- if (promise === "rejects") thrown = obj;
1040
- else if (promise === "resolves" && typeof obj !== "function") if (!isNot) throw new AssertionError(utils.flag(this, "message") || "expected promise to throw an error, but it didn't", { showDiff: false }, utils.flag(this, "ssfi"));
1041
- else return;
1042
- else {
1043
- let isThrow = false;
1044
- try {
1045
- obj();
1046
- } catch (err) {
1047
- isThrow = true;
1048
- thrown = err;
1049
- }
1050
- if (!isThrow && !isNot) throw new AssertionError(utils.flag(this, "message") || "expected function to throw an error, but it didn't", { showDiff: false }, utils.flag(this, "ssfi"));
1051
- }
1052
- if (typeof expected === "function") {
1053
- const name = expected.name || expected.prototype.constructor.name;
1054
- return this.assert(thrown && thrown instanceof expected, `expected error to be instance of ${name}`, `expected error not to be instance of ${name}`, expected, thrown);
1055
- }
1056
- if (expected instanceof Error) {
1057
- const equal = equals(thrown, expected, [...customTesters, iterableEquality]);
1058
- return this.assert(equal, "expected a thrown error to be #{exp}", "expected a thrown error not to be #{exp}", expected, thrown);
1059
- }
1060
- if (typeof expected === "object" && "asymmetricMatch" in expected && typeof expected.asymmetricMatch === "function") {
1061
- const matcher = expected;
1062
- return this.assert(thrown && matcher.asymmetricMatch(thrown), "expected error to match asymmetric matcher", "expected error not to match asymmetric matcher", matcher, thrown);
1063
- }
1064
- throw new Error(`"toThrow" expects string, RegExp, function, Error instance or asymmetric matcher, got "${typeof expected}"`);
1065
- });
1066
- [{
1067
- name: "toHaveResolved",
1068
- condition: (spy) => spy.mock.settledResults.length > 0 && spy.mock.settledResults.some(({ type }) => type === "fulfilled"),
1069
- action: "resolved"
1070
- }, {
1071
- name: ["toHaveReturned", "toReturn"],
1072
- condition: (spy) => spy.mock.calls.length > 0 && spy.mock.results.some(({ type }) => type !== "throw"),
1073
- action: "called"
1074
- }].forEach(({ name, condition, action }) => {
1075
- def(name, function() {
1076
- const spy = getSpy(this);
1077
- const spyName = spy.getMockName();
1078
- const pass = condition(spy);
1079
- this.assert(pass, `expected "${spyName}" to be successfully ${action} at least once`, `expected "${spyName}" to not be successfully ${action}`, pass, !pass, false);
1080
- });
1081
- });
1082
- [{
1083
- name: "toHaveResolvedTimes",
1084
- condition: (spy, times) => spy.mock.settledResults.reduce((s, { type }) => type === "fulfilled" ? ++s : s, 0) === times,
1085
- action: "resolved"
1086
- }, {
1087
- name: ["toHaveReturnedTimes", "toReturnTimes"],
1088
- condition: (spy, times) => spy.mock.results.reduce((s, { type }) => type === "throw" ? s : ++s, 0) === times,
1089
- action: "called"
1090
- }].forEach(({ name, condition, action }) => {
1091
- def(name, function(times) {
1092
- const spy = getSpy(this);
1093
- const spyName = spy.getMockName();
1094
- const pass = condition(spy, times);
1095
- this.assert(pass, `expected "${spyName}" to be successfully ${action} ${times} times`, `expected "${spyName}" to not be successfully ${action} ${times} times`, `expected resolved times: ${times}`, `received resolved times: ${pass}`, false);
1096
- });
1097
- });
1098
- [{
1099
- name: "toHaveResolvedWith",
1100
- condition: (spy, value) => spy.mock.settledResults.some(({ type, value: result }) => type === "fulfilled" && equals(value, result)),
1101
- action: "resolve"
1102
- }, {
1103
- name: ["toHaveReturnedWith", "toReturnWith"],
1104
- condition: (spy, value) => spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result)),
1105
- action: "return"
1106
- }].forEach(({ name, condition, action }) => {
1107
- def(name, function(value) {
1108
- const spy = getSpy(this);
1109
- const pass = condition(spy, value);
1110
- const isNot = utils.flag(this, "negate");
1111
- if (pass && isNot || !pass && !isNot) {
1112
- const spyName = spy.getMockName();
1113
- const msg = utils.getMessage(this, [
1114
- pass,
1115
- `expected "${spyName}" to ${action} with: #{exp} at least once`,
1116
- `expected "${spyName}" to not ${action} with: #{exp}`,
1117
- value
1118
- ]);
1119
- throw new AssertionError(formatReturns(spy, action === "return" ? spy.mock.results : spy.mock.settledResults, msg, value));
1120
- }
1121
- });
1122
- });
1123
- [{
1124
- name: "toHaveLastResolvedWith",
1125
- condition: (spy, value) => {
1126
- const result = spy.mock.settledResults[spy.mock.settledResults.length - 1];
1127
- return result && result.type === "fulfilled" && equals(result.value, value);
1128
- },
1129
- action: "resolve"
1130
- }, {
1131
- name: ["toHaveLastReturnedWith", "lastReturnedWith"],
1132
- condition: (spy, value) => {
1133
- const result = spy.mock.results[spy.mock.results.length - 1];
1134
- return result && result.type === "return" && equals(result.value, value);
1135
- },
1136
- action: "return"
1137
- }].forEach(({ name, condition, action }) => {
1138
- def(name, function(value) {
1139
- const spy = getSpy(this);
1140
- const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1141
- const result = results[results.length - 1];
1142
- const spyName = spy.getMockName();
1143
- this.assert(condition(spy, value), `expected last "${spyName}" call to ${action} #{exp}`, `expected last "${spyName}" call to not ${action} #{exp}`, value, result === null || result === void 0 ? void 0 : result.value);
1144
- });
1145
- });
1146
- [{
1147
- name: "toHaveNthResolvedWith",
1148
- condition: (spy, index, value) => {
1149
- const result = spy.mock.settledResults[index - 1];
1150
- return result && result.type === "fulfilled" && equals(result.value, value);
1151
- },
1152
- action: "resolve"
1153
- }, {
1154
- name: ["toHaveNthReturnedWith", "nthReturnedWith"],
1155
- condition: (spy, index, value) => {
1156
- const result = spy.mock.results[index - 1];
1157
- return result && result.type === "return" && equals(result.value, value);
1158
- },
1159
- action: "return"
1160
- }].forEach(({ name, condition, action }) => {
1161
- def(name, function(nthCall, value) {
1162
- const spy = getSpy(this);
1163
- const spyName = spy.getMockName();
1164
- const result = (action === "return" ? spy.mock.results : spy.mock.settledResults)[nthCall - 1];
1165
- const ordinalCall = `${ordinalOf(nthCall)} call`;
1166
- this.assert(condition(spy, nthCall, value), `expected ${ordinalCall} "${spyName}" call to ${action} #{exp}`, `expected ${ordinalCall} "${spyName}" call to not ${action} #{exp}`, value, result === null || result === void 0 ? void 0 : result.value);
1167
- });
1168
- });
1169
- def("withContext", function(context) {
1170
- for (const key in context) utils.flag(this, key, context[key]);
1171
- return this;
1172
- });
1173
- utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() {
1174
- const error = /* @__PURE__ */ new Error("resolves");
1175
- utils.flag(this, "promise", "resolves");
1176
- utils.flag(this, "error", error);
1177
- const test = utils.flag(this, "vitest-test");
1178
- const obj = utils.flag(this, "object");
1179
- if (utils.flag(this, "poll")) throw new SyntaxError(`expect.poll() is not supported in combination with .resolves`);
1180
- if (typeof (obj === null || obj === void 0 ? void 0 : obj.then) !== "function") throw new TypeError(`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`);
1181
- const proxy = new Proxy(this, { get: (target, key, receiver) => {
1182
- const result = Reflect.get(target, key, receiver);
1183
- if (typeof result !== "function") return result instanceof chai.Assertion ? proxy : result;
1184
- return (...args) => {
1185
- utils.flag(this, "_name", key);
1186
- return recordAsyncExpect(test, obj.then((value) => {
1187
- utils.flag(this, "object", value);
1188
- return result.call(this, ...args);
1189
- }, (err) => {
1190
- const _error = new AssertionError(`promise rejected "${utils.inspect(err)}" instead of resolving`, { showDiff: false });
1191
- _error.cause = err;
1192
- _error.stack = error.stack.replace(error.message, _error.message);
1193
- throw _error;
1194
- }), createAssertionMessage(utils, this, !!args.length), error);
1195
- };
1196
- } });
1197
- return proxy;
1198
- });
1199
- utils.addProperty(chai.Assertion.prototype, "rejects", function __VITEST_REJECTS__() {
1200
- const error = /* @__PURE__ */ new Error("rejects");
1201
- utils.flag(this, "promise", "rejects");
1202
- utils.flag(this, "error", error);
1203
- const test = utils.flag(this, "vitest-test");
1204
- const obj = utils.flag(this, "object");
1205
- const wrapper = typeof obj === "function" ? obj() : obj;
1206
- if (utils.flag(this, "poll")) throw new SyntaxError(`expect.poll() is not supported in combination with .rejects`);
1207
- if (typeof (wrapper === null || wrapper === void 0 ? void 0 : wrapper.then) !== "function") throw new TypeError(`You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`);
1208
- const proxy = new Proxy(this, { get: (target, key, receiver) => {
1209
- const result = Reflect.get(target, key, receiver);
1210
- if (typeof result !== "function") return result instanceof chai.Assertion ? proxy : result;
1211
- return (...args) => {
1212
- utils.flag(this, "_name", key);
1213
- return recordAsyncExpect(test, wrapper.then((value) => {
1214
- const _error = new AssertionError(`promise resolved "${utils.inspect(value)}" instead of rejecting`, {
1215
- showDiff: true,
1216
- expected: /* @__PURE__ */ new Error("rejected promise"),
1217
- actual: value
1218
- });
1219
- _error.stack = error.stack.replace(error.message, _error.message);
1220
- throw _error;
1221
- }, (err) => {
1222
- utils.flag(this, "object", err);
1223
- return result.call(this, ...args);
1224
- }), createAssertionMessage(utils, this, !!args.length), error);
1225
- };
1226
- } });
1227
- return proxy;
1228
- });
1229
- };
1230
- function ordinalOf(i) {
1231
- const j = i % 10;
1232
- const k = i % 100;
1233
- if (j === 1 && k !== 11) return `${i}st`;
1234
- if (j === 2 && k !== 12) return `${i}nd`;
1235
- if (j === 3 && k !== 13) return `${i}rd`;
1236
- return `${i}th`;
1237
- }
1238
- function formatCalls(spy, msg, showActualCall) {
1239
- if (spy.mock.calls.length) msg += u.gray(`\n\nReceived: \n\n${spy.mock.calls.map((callArg, i) => {
1240
- let methodCall = u.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`);
1241
- if (showActualCall) methodCall += diff(showActualCall, callArg, { omitAnnotationLines: true });
1242
- else methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
1243
- methodCall += "\n";
1244
- return methodCall;
1245
- }).join("\n")}`);
1246
- msg += u.gray(`\n\nNumber of calls: ${u.bold(spy.mock.calls.length)}\n`);
1247
- return msg;
1248
- }
1249
- function formatReturns(spy, results, msg, showActualReturn) {
1250
- if (results.length) msg += u.gray(`\n\nReceived: \n\n${results.map((callReturn, i) => {
1251
- let methodCall = u.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`);
1252
- if (showActualReturn) methodCall += diff(showActualReturn, callReturn.value, { omitAnnotationLines: true });
1253
- else methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
1254
- methodCall += "\n";
1255
- return methodCall;
1256
- }).join("\n")}`);
1257
- msg += u.gray(`\n\nNumber of calls: ${u.bold(spy.mock.calls.length)}\n`);
1258
- return msg;
1259
- }
1260
- function getMatcherState(assertion, expect) {
1261
- const obj = assertion._obj;
1262
- const isNot = utils_exports.flag(assertion, "negate");
1263
- const promise = utils_exports.flag(assertion, "promise") || "";
1264
- const jestUtils = {
1265
- ...getMatcherUtils(),
1266
- diff,
1267
- stringify,
1268
- iterableEquality,
1269
- subsetEquality
1270
- };
1271
- return {
1272
- state: {
1273
- ...getState(expect),
1274
- customTesters: getCustomEqualityTesters(),
1275
- isNot,
1276
- utils: jestUtils,
1277
- promise,
1278
- equals,
1279
- suppressedErrors: [],
1280
- soft: utils_exports.flag(assertion, "soft"),
1281
- poll: utils_exports.flag(assertion, "poll")
1282
- },
1283
- isNot,
1284
- obj
1285
- };
1286
- }
1287
- var JestExtendError = class extends Error {
1288
- constructor(message, actual, expected) {
1289
- super(message);
1290
- this.actual = actual;
1291
- this.expected = expected;
1292
- }
1293
- };
1294
- function JestExtendPlugin(c, expect, matchers) {
1295
- return (_, utils) => {
1296
- Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
1297
- function expectWrapper(...args) {
1298
- const { state, isNot, obj } = getMatcherState(this, expect);
1299
- const result = expectAssertion.call(state, obj, ...args);
1300
- if (result && typeof result === "object" && typeof result.then === "function") return result.then(({ pass, message, actual, expected }) => {
1301
- if (pass && isNot || !pass && !isNot) throw new JestExtendError(message(), actual, expected);
1302
- });
1303
- const { pass, message, actual, expected } = result;
1304
- if (pass && isNot || !pass && !isNot) throw new JestExtendError(message(), actual, expected);
1305
- }
1306
- const softWrapper = wrapAssertion(utils, expectAssertionName, expectWrapper);
1307
- utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, softWrapper);
1308
- utils.addMethod(c.Assertion.prototype, expectAssertionName, softWrapper);
1309
- class CustomMatcher extends AsymmetricMatcher {
1310
- constructor(inverse = false, ...sample) {
1311
- super(sample, inverse);
1312
- }
1313
- asymmetricMatch(other) {
1314
- const { pass } = expectAssertion.call(this.getMatcherContext(expect), other, ...this.sample);
1315
- return this.inverse ? !pass : pass;
1316
- }
1317
- toString() {
1318
- return `${this.inverse ? "not." : ""}${expectAssertionName}`;
1319
- }
1320
- getExpectedType() {
1321
- return "any";
1322
- }
1323
- toAsymmetricMatcher() {
1324
- return `${this.toString()}<${this.sample.map((item) => stringify(item)).join(", ")}>`;
1325
- }
1326
- }
1327
- const customMatcher = (...sample) => new CustomMatcher(false, ...sample);
1328
- Object.defineProperty(expect, expectAssertionName, {
1329
- configurable: true,
1330
- enumerable: true,
1331
- value: customMatcher,
1332
- writable: true
1333
- });
1334
- Object.defineProperty(expect.not, expectAssertionName, {
1335
- configurable: true,
1336
- enumerable: true,
1337
- value: (...sample) => new CustomMatcher(true, ...sample),
1338
- writable: true
1339
- });
1340
- Object.defineProperty(globalThis[ASYMMETRIC_MATCHERS_OBJECT], expectAssertionName, {
1341
- configurable: true,
1342
- enumerable: true,
1343
- value: customMatcher,
1344
- writable: true
1345
- });
1346
- });
1347
- };
1348
- }
1349
- const JestExtend = (chai, utils) => {
1350
- utils.addMethod(chai.expect, "extend", (expect, expects) => {
1351
- use(JestExtendPlugin(chai, expect, expects));
1352
- });
1353
- };
1354
-
1355
- //#endregion
1356
- export { ASYMMETRIC_MATCHERS_OBJECT, GLOBAL_EXPECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, addCustomEqualityTesters, customMatchers, equals, getState, iterableEquality, setState, subsetEquality };