index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*!
  2. * /**
  3. * * Copyright (c) Meta Platforms, Inc. and affiliates.
  4. * *
  5. * * This source code is licensed under the MIT license found in the
  6. * * LICENSE file in the root directory of this source tree.
  7. * * /
  8. */
  9. /******/ (() => { // webpackBootstrap
  10. /******/ "use strict";
  11. /******/ var __webpack_modules__ = ({
  12. /***/ "./src/immutableUtils.ts":
  13. /***/ ((__unused_webpack_module, exports) => {
  14. Object.defineProperty(exports, "__esModule", ({
  15. value: true
  16. }));
  17. exports.isImmutableList = isImmutableList;
  18. exports.isImmutableOrderedKeyed = isImmutableOrderedKeyed;
  19. exports.isImmutableOrderedSet = isImmutableOrderedSet;
  20. exports.isImmutableRecord = isImmutableRecord;
  21. exports.isImmutableUnorderedKeyed = isImmutableUnorderedKeyed;
  22. exports.isImmutableUnorderedSet = isImmutableUnorderedSet;
  23. /**
  24. * Copyright (c) Meta Platforms, Inc. and affiliates.
  25. *
  26. * This source code is licensed under the MIT license found in the
  27. * LICENSE file in the root directory of this source tree.
  28. *
  29. */
  30. // SENTINEL constants are from https://github.com/immutable-js/immutable-js/tree/main/src/predicates
  31. const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  32. const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  33. const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  34. const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  35. const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
  36. function isObjectLiteral(source) {
  37. return source != null && typeof source === 'object' && !Array.isArray(source);
  38. }
  39. function isImmutableUnorderedKeyed(source) {
  40. return Boolean(source && isObjectLiteral(source) && source[IS_KEYED_SENTINEL] && !source[IS_ORDERED_SENTINEL]);
  41. }
  42. function isImmutableUnorderedSet(source) {
  43. return Boolean(source && isObjectLiteral(source) && source[IS_SET_SENTINEL] && !source[IS_ORDERED_SENTINEL]);
  44. }
  45. function isImmutableList(source) {
  46. return Boolean(source && isObjectLiteral(source) && source[IS_LIST_SENTINEL]);
  47. }
  48. function isImmutableOrderedKeyed(source) {
  49. return Boolean(source && isObjectLiteral(source) && source[IS_KEYED_SENTINEL] && source[IS_ORDERED_SENTINEL]);
  50. }
  51. function isImmutableOrderedSet(source) {
  52. return Boolean(source && isObjectLiteral(source) && source[IS_SET_SENTINEL] && source[IS_ORDERED_SENTINEL]);
  53. }
  54. function isImmutableRecord(source) {
  55. return Boolean(source && isObjectLiteral(source) && source[IS_RECORD_SYMBOL]);
  56. }
  57. /***/ }),
  58. /***/ "./src/index.ts":
  59. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  60. Object.defineProperty(exports, "__esModule", ({
  61. value: true
  62. }));
  63. var _exportNames = {
  64. equals: true,
  65. isA: true
  66. };
  67. Object.defineProperty(exports, "equals", ({
  68. enumerable: true,
  69. get: function () {
  70. return _jasmineUtils.equals;
  71. }
  72. }));
  73. Object.defineProperty(exports, "isA", ({
  74. enumerable: true,
  75. get: function () {
  76. return _jasmineUtils.isA;
  77. }
  78. }));
  79. var _jasmineUtils = __webpack_require__("./src/jasmineUtils.ts");
  80. var _utils = __webpack_require__("./src/utils.ts");
  81. Object.keys(_utils).forEach(function (key) {
  82. if (key === "default" || key === "__esModule") return;
  83. if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  84. if (key in exports && exports[key] === _utils[key]) return;
  85. Object.defineProperty(exports, key, {
  86. enumerable: true,
  87. get: function () {
  88. return _utils[key];
  89. }
  90. });
  91. });
  92. /***/ }),
  93. /***/ "./src/jasmineUtils.ts":
  94. /***/ ((__unused_webpack_module, exports) => {
  95. Object.defineProperty(exports, "__esModule", ({
  96. value: true
  97. }));
  98. exports.equals = void 0;
  99. exports.isA = isA;
  100. /*
  101. Copyright (c) 2008-2016 Pivotal Labs
  102. Permission is hereby granted, free of charge, to any person obtaining
  103. a copy of this software and associated documentation files (the
  104. "Software"), to deal in the Software without restriction, including
  105. without limitation the rights to use, copy, modify, merge, publish,
  106. distribute, sublicense, and/or sell copies of the Software, and to
  107. permit persons to whom the Software is furnished to do so, subject to
  108. the following conditions:
  109. The above copyright notice and this permission notice shall be
  110. included in all copies or substantial portions of the Software.
  111. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  112. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  113. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  114. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  115. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  116. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  117. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  118. */
  119. // Extracted out of jasmine 2.5.2
  120. const equals = (a, b, customTesters, strictCheck) => {
  121. customTesters = customTesters || [];
  122. return eq(a, b, [], [], customTesters, strictCheck);
  123. };
  124. exports.equals = equals;
  125. function isAsymmetric(obj) {
  126. return !!obj && isA('Function', obj.asymmetricMatch);
  127. }
  128. function asymmetricMatch(a, b) {
  129. const asymmetricA = isAsymmetric(a);
  130. const asymmetricB = isAsymmetric(b);
  131. if (asymmetricA && asymmetricB) {
  132. return undefined;
  133. }
  134. if (asymmetricA) {
  135. return a.asymmetricMatch(b);
  136. }
  137. if (asymmetricB) {
  138. return b.asymmetricMatch(a);
  139. }
  140. }
  141. // Equality function lovingly adapted from isEqual in
  142. // [Underscore](http://underscorejs.org)
  143. function eq(a, b, aStack, bStack, customTesters, strictCheck) {
  144. let result = true;
  145. const asymmetricResult = asymmetricMatch(a, b);
  146. if (asymmetricResult !== undefined) {
  147. return asymmetricResult;
  148. }
  149. const testerContext = {
  150. equals
  151. };
  152. for (const item of customTesters) {
  153. const customTesterResult = item.call(testerContext, a, b, customTesters);
  154. if (customTesterResult !== undefined) {
  155. return customTesterResult;
  156. }
  157. }
  158. if (a instanceof Error && b instanceof Error) {
  159. return a.message === b.message;
  160. }
  161. if (Object.is(a, b)) {
  162. return true;
  163. }
  164. // A strict comparison is necessary because `null == undefined`.
  165. if (a === null || b === null) {
  166. return false;
  167. }
  168. const className = Object.prototype.toString.call(a);
  169. if (className !== Object.prototype.toString.call(b)) {
  170. return false;
  171. }
  172. switch (className) {
  173. case '[object Boolean]':
  174. case '[object String]':
  175. case '[object Number]':
  176. if (typeof a !== typeof b) {
  177. // One is a primitive, one a `new Primitive()`
  178. return false;
  179. } else if (typeof a !== 'object' && typeof b !== 'object') {
  180. // both are proper primitives
  181. return false;
  182. } else {
  183. // both are `new Primitive()`s
  184. return Object.is(a.valueOf(), b.valueOf());
  185. }
  186. case '[object Date]':
  187. // Coerce dates to numeric primitive values. Dates are compared by their
  188. // millisecond representations. Note that invalid dates with millisecond representations
  189. // of `NaN` are not equivalent.
  190. return +a === +b;
  191. // RegExps are compared by their source patterns and flags.
  192. case '[object RegExp]':
  193. return a.source === b.source && a.flags === b.flags;
  194. // URLs are compared by their href property which contains the entire url string.
  195. case '[object URL]':
  196. return a.href === b.href;
  197. }
  198. if (typeof a !== 'object' || typeof b !== 'object') {
  199. return false;
  200. }
  201. // Use DOM3 method isEqualNode (IE>=9)
  202. if (isDomNode(a) && isDomNode(b)) {
  203. return a.isEqualNode(b);
  204. }
  205. // Used to detect circular references.
  206. let length = aStack.length;
  207. while (length--) {
  208. // Linear search. Performance is inversely proportional to the number of
  209. // unique nested structures.
  210. // circular references at same depth are equal
  211. // circular reference is not equal to non-circular one
  212. if (aStack[length] === a) {
  213. return bStack[length] === b;
  214. } else if (bStack[length] === b) {
  215. return false;
  216. }
  217. }
  218. // Add the first object to the stack of traversed objects.
  219. aStack.push(a);
  220. bStack.push(b);
  221. // Recursively compare objects and arrays.
  222. // Compare array lengths to determine if a deep comparison is necessary.
  223. if (strictCheck && className === '[object Array]' && a.length !== b.length) {
  224. return false;
  225. }
  226. // Deep compare objects.
  227. const aKeys = keys(a, hasKey);
  228. let key;
  229. const bKeys = keys(b, hasKey);
  230. // Add keys corresponding to asymmetric matchers if they miss in non strict check mode
  231. if (!strictCheck) {
  232. for (let index = 0; index !== bKeys.length; ++index) {
  233. key = bKeys[index];
  234. if ((isAsymmetric(b[key]) || b[key] === undefined) && !hasKey(a, key)) {
  235. aKeys.push(key);
  236. }
  237. }
  238. for (let index = 0; index !== aKeys.length; ++index) {
  239. key = aKeys[index];
  240. if ((isAsymmetric(a[key]) || a[key] === undefined) && !hasKey(b, key)) {
  241. bKeys.push(key);
  242. }
  243. }
  244. }
  245. // Ensure that both objects contain the same number of properties before comparing deep equality.
  246. let size = aKeys.length;
  247. if (bKeys.length !== size) {
  248. return false;
  249. }
  250. while (size--) {
  251. key = aKeys[size];
  252. // Deep compare each member
  253. if (strictCheck) result = hasKey(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, strictCheck);else result = (hasKey(b, key) || isAsymmetric(a[key]) || a[key] === undefined) && eq(a[key], b[key], aStack, bStack, customTesters, strictCheck);
  254. if (!result) {
  255. return false;
  256. }
  257. }
  258. // Remove the first object from the stack of traversed objects.
  259. aStack.pop();
  260. bStack.pop();
  261. return result;
  262. }
  263. function keys(obj, hasKey) {
  264. const keys = [];
  265. for (const key in obj) {
  266. if (hasKey(obj, key)) {
  267. keys.push(key);
  268. }
  269. }
  270. return [...keys, ...Object.getOwnPropertySymbols(obj).filter(symbol => Object.getOwnPropertyDescriptor(obj, symbol).enumerable)];
  271. }
  272. function hasKey(obj, key) {
  273. return Object.prototype.hasOwnProperty.call(obj, key);
  274. }
  275. function isA(typeName, value) {
  276. return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
  277. }
  278. function isDomNode(obj) {
  279. return obj !== null && typeof obj === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string' && typeof obj.isEqualNode === 'function';
  280. }
  281. /***/ }),
  282. /***/ "./src/utils.ts":
  283. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  284. Object.defineProperty(exports, "__esModule", ({
  285. value: true
  286. }));
  287. exports.arrayBufferEquality = void 0;
  288. exports.emptyObject = emptyObject;
  289. exports.typeEquality = exports.subsetEquality = exports.sparseArrayEquality = exports.pathAsArray = exports.partition = exports.iterableEquality = exports.isOneline = exports.isError = exports.getPath = exports.getObjectSubset = exports.getObjectKeys = void 0;
  290. var _getType = require("@jest/get-type");
  291. var _immutableUtils = __webpack_require__("./src/immutableUtils.ts");
  292. var _jasmineUtils = __webpack_require__("./src/jasmineUtils.ts");
  293. var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol;
  294. /**
  295. * Copyright (c) Meta Platforms, Inc. and affiliates.
  296. *
  297. * This source code is licensed under the MIT license found in the
  298. * LICENSE file in the root directory of this source tree.
  299. *
  300. */
  301. /**
  302. * Checks if `hasOwnProperty(object, key)` up the prototype chain, stopping at `Object.prototype`.
  303. */
  304. const hasPropertyInObject = (object, key) => {
  305. const shouldTerminate = !object || typeof object !== 'object' || object === Object.prototype;
  306. if (shouldTerminate) {
  307. return false;
  308. }
  309. return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
  310. };
  311. // Retrieves an object's keys for evaluation by getObjectSubset. This evaluates
  312. // the prototype chain for string keys but not for non-enumerable symbols.
  313. // (Otherwise, it could find values such as a Set or Map's Symbol.toStringTag,
  314. // with unexpected results.)
  315. const getObjectKeys = object => {
  316. return [...Object.keys(object), ...Object.getOwnPropertySymbols(object).filter(s => Object.getOwnPropertyDescriptor(object, s)?.enumerable)];
  317. };
  318. exports.getObjectKeys = getObjectKeys;
  319. const getPath = (object, propertyPath) => {
  320. if (!Array.isArray(propertyPath)) {
  321. propertyPath = pathAsArray(propertyPath);
  322. }
  323. if (propertyPath.length > 0) {
  324. const lastProp = propertyPath.length === 1;
  325. const prop = propertyPath[0];
  326. const newObject = object[prop];
  327. if (!lastProp && (newObject === null || newObject === undefined)) {
  328. // This is not the last prop in the chain. If we keep recursing it will
  329. // hit a `can't access property X of undefined | null`. At this point we
  330. // know that the chain has broken and we can return right away.
  331. return {
  332. hasEndProp: false,
  333. lastTraversedObject: object,
  334. traversedPath: []
  335. };
  336. }
  337. const result = getPath(newObject, propertyPath.slice(1));
  338. if (result.lastTraversedObject === null) {
  339. result.lastTraversedObject = object;
  340. }
  341. result.traversedPath.unshift(prop);
  342. if (lastProp) {
  343. // Does object have the property with an undefined value?
  344. // Although primitive values support bracket notation (above)
  345. // they would throw TypeError for in operator (below).
  346. result.endPropIsDefined = !(0, _getType.isPrimitive)(object) && prop in object;
  347. result.hasEndProp = newObject !== undefined || result.endPropIsDefined;
  348. if (!result.hasEndProp) {
  349. result.traversedPath.shift();
  350. }
  351. }
  352. return result;
  353. }
  354. return {
  355. lastTraversedObject: null,
  356. traversedPath: [],
  357. value: object
  358. };
  359. };
  360. // Strip properties from object that are not present in the subset. Useful for
  361. // printing the diff for toMatchObject() without adding unrelated noise.
  362. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  363. exports.getPath = getPath;
  364. const getObjectSubset = (object, subset, customTesters = [], seenReferences = new WeakMap()) => {
  365. /* eslint-enable @typescript-eslint/explicit-module-boundary-types */
  366. if (Array.isArray(object)) {
  367. if (Array.isArray(subset) && subset.length === object.length) {
  368. // The map method returns correct subclass of subset.
  369. return subset.map((sub, i) => getObjectSubset(object[i], sub, customTesters));
  370. }
  371. } else if (object instanceof Date) {
  372. return object;
  373. } else if (isObject(object) && isObject(subset)) {
  374. if ((0, _jasmineUtils.equals)(object, subset, [...customTesters, iterableEquality, subsetEquality])) {
  375. // Avoid unnecessary copy which might return Object instead of subclass.
  376. return subset;
  377. }
  378. const trimmed = {};
  379. seenReferences.set(object, trimmed);
  380. for (const key of getObjectKeys(object).filter(key => hasPropertyInObject(subset, key))) {
  381. trimmed[key] = seenReferences.has(object[key]) ? seenReferences.get(object[key]) : getObjectSubset(object[key], subset[key], customTesters, seenReferences);
  382. }
  383. if (getObjectKeys(trimmed).length > 0) {
  384. return trimmed;
  385. }
  386. }
  387. return object;
  388. };
  389. exports.getObjectSubset = getObjectSubset;
  390. const IteratorSymbol = Symbol.iterator;
  391. const hasIterator = object => !!(object != null && object[IteratorSymbol]);
  392. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  393. const iterableEquality = (a, b, customTesters = [], /* eslint-enable @typescript-eslint/explicit-module-boundary-types */
  394. aStack = [], bStack = []) => {
  395. if (typeof a !== 'object' || typeof b !== 'object' || Array.isArray(a) || Array.isArray(b) || ArrayBuffer.isView(a) || ArrayBuffer.isView(b) || !hasIterator(a) || !hasIterator(b)) {
  396. return undefined;
  397. }
  398. if (a.constructor !== b.constructor) {
  399. return false;
  400. }
  401. let length = aStack.length;
  402. while (length--) {
  403. // Linear search. Performance is inversely proportional to the number of
  404. // unique nested structures.
  405. // circular references at same depth are equal
  406. // circular reference is not equal to non-circular one
  407. if (aStack[length] === a) {
  408. return bStack[length] === b;
  409. }
  410. }
  411. aStack.push(a);
  412. bStack.push(b);
  413. const iterableEqualityWithStack = (a, b) => iterableEquality(a, b, [...filteredCustomTesters], [...aStack], [...bStack]);
  414. // Replace any instance of iterableEquality with the new
  415. // iterableEqualityWithStack so we can do circular detection
  416. const filteredCustomTesters = [...customTesters.filter(t => t !== iterableEquality), iterableEqualityWithStack];
  417. if (a.size !== undefined) {
  418. if (a.size !== b.size) {
  419. return false;
  420. } else if ((0, _jasmineUtils.isA)('Set', a) || (0, _immutableUtils.isImmutableUnorderedSet)(a)) {
  421. let allFound = true;
  422. for (const aValue of a) {
  423. if (!b.has(aValue)) {
  424. let has = false;
  425. for (const bValue of b) {
  426. const isEqual = (0, _jasmineUtils.equals)(aValue, bValue, filteredCustomTesters);
  427. if (isEqual === true) {
  428. has = true;
  429. }
  430. }
  431. if (has === false) {
  432. allFound = false;
  433. break;
  434. }
  435. }
  436. }
  437. // Remove the first value from the stack of traversed values.
  438. aStack.pop();
  439. bStack.pop();
  440. return allFound;
  441. } else if ((0, _jasmineUtils.isA)('Map', a) || (0, _immutableUtils.isImmutableUnorderedKeyed)(a)) {
  442. let allFound = true;
  443. for (const aEntry of a) {
  444. if (!b.has(aEntry[0]) || !(0, _jasmineUtils.equals)(aEntry[1], b.get(aEntry[0]), filteredCustomTesters)) {
  445. let has = false;
  446. for (const bEntry of b) {
  447. const matchedKey = (0, _jasmineUtils.equals)(aEntry[0], bEntry[0], filteredCustomTesters);
  448. let matchedValue = false;
  449. if (matchedKey === true) {
  450. matchedValue = (0, _jasmineUtils.equals)(aEntry[1], bEntry[1], filteredCustomTesters);
  451. }
  452. if (matchedValue === true) {
  453. has = true;
  454. }
  455. }
  456. if (has === false) {
  457. allFound = false;
  458. break;
  459. }
  460. }
  461. }
  462. // Remove the first value from the stack of traversed values.
  463. aStack.pop();
  464. bStack.pop();
  465. return allFound;
  466. }
  467. }
  468. const bIterator = b[IteratorSymbol]();
  469. for (const aValue of a) {
  470. const nextB = bIterator.next();
  471. if (nextB.done || !(0, _jasmineUtils.equals)(aValue, nextB.value, filteredCustomTesters)) {
  472. return false;
  473. }
  474. }
  475. if (!bIterator.next().done) {
  476. return false;
  477. }
  478. if (!(0, _immutableUtils.isImmutableList)(a) && !(0, _immutableUtils.isImmutableOrderedKeyed)(a) && !(0, _immutableUtils.isImmutableOrderedSet)(a) && !(0, _immutableUtils.isImmutableRecord)(a)) {
  479. const aEntries = entries(a);
  480. const bEntries = entries(b);
  481. if (!(0, _jasmineUtils.equals)(aEntries, bEntries)) {
  482. return false;
  483. }
  484. }
  485. // Remove the first value from the stack of traversed values.
  486. aStack.pop();
  487. bStack.pop();
  488. return true;
  489. };
  490. exports.iterableEquality = iterableEquality;
  491. const entries = obj => {
  492. if (!isObject(obj)) return [];
  493. const symbolProperties = Object.getOwnPropertySymbols(obj).filter(key => key !== Symbol.iterator).map(key => [key, obj[key]]);
  494. return [...symbolProperties, ...Object.entries(obj)];
  495. };
  496. const isObject = a => a !== null && typeof a === 'object';
  497. const isObjectWithKeys = a => isObject(a) && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date) && !(a instanceof Set) && !(a instanceof Map);
  498. const subsetEquality = (object, subset, customTesters = []) => {
  499. const filteredCustomTesters = customTesters.filter(t => t !== subsetEquality);
  500. // subsetEquality needs to keep track of the references
  501. // it has already visited to avoid infinite loops in case
  502. // there are circular references in the subset passed to it.
  503. const subsetEqualityWithContext = (seenReferences = new WeakMap()) => (object, subset) => {
  504. if (!isObjectWithKeys(subset)) {
  505. return undefined;
  506. }
  507. if (seenReferences.has(subset)) return undefined;
  508. seenReferences.set(subset, true);
  509. const matchResult = getObjectKeys(subset).every(key => {
  510. if (isObjectWithKeys(subset[key])) {
  511. if (seenReferences.has(subset[key])) {
  512. return (0, _jasmineUtils.equals)(object[key], subset[key], filteredCustomTesters);
  513. }
  514. }
  515. const result = object != null && hasPropertyInObject(object, key) && (0, _jasmineUtils.equals)(object[key], subset[key], [...filteredCustomTesters, subsetEqualityWithContext(seenReferences)]);
  516. // The main goal of using seenReference is to avoid circular node on tree.
  517. // It will only happen within a parent and its child, not a node and nodes next to it (same level)
  518. // We should keep the reference for a parent and its child only
  519. // Thus we should delete the reference immediately so that it doesn't interfere
  520. // other nodes within the same level on tree.
  521. seenReferences.delete(subset[key]);
  522. return result;
  523. });
  524. seenReferences.delete(subset);
  525. return matchResult;
  526. };
  527. return subsetEqualityWithContext()(object, subset);
  528. };
  529. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  530. exports.subsetEquality = subsetEquality;
  531. const typeEquality = (a, b) => {
  532. if (a == null || b == null || a.constructor === b.constructor ||
  533. // Since Jest globals are different from Node globals,
  534. // constructors are different even between arrays when comparing properties of mock objects.
  535. // Both of them should be able to compare correctly when they are array-to-array.
  536. // https://github.com/jestjs/jest/issues/2549
  537. Array.isArray(a) && Array.isArray(b)) {
  538. return undefined;
  539. }
  540. return false;
  541. };
  542. exports.typeEquality = typeEquality;
  543. const arrayBufferEquality = (a, b) => {
  544. let dataViewA = a;
  545. let dataViewB = b;
  546. if (isArrayBuffer(a) && isArrayBuffer(b)) {
  547. dataViewA = new DataView(a);
  548. dataViewB = new DataView(b);
  549. } else if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
  550. dataViewA = new DataView(a.buffer, a.byteOffset, a.byteLength);
  551. dataViewB = new DataView(b.buffer, b.byteOffset, b.byteLength);
  552. }
  553. if (!(dataViewA instanceof DataView && dataViewB instanceof DataView)) {
  554. return undefined;
  555. }
  556. // Buffers are not equal when they do not have the same byte length
  557. if (dataViewA.byteLength !== dataViewB.byteLength) {
  558. return false;
  559. }
  560. // Check if every byte value is equal to each other
  561. for (let i = 0; i < dataViewA.byteLength; i++) {
  562. if (dataViewA.getUint8(i) !== dataViewB.getUint8(i)) {
  563. return false;
  564. }
  565. }
  566. return true;
  567. };
  568. exports.arrayBufferEquality = arrayBufferEquality;
  569. function isArrayBuffer(obj) {
  570. return Object.prototype.toString.call(obj) === '[object ArrayBuffer]';
  571. }
  572. const sparseArrayEquality = (a, b, customTesters = []) => {
  573. if (!Array.isArray(a) || !Array.isArray(b)) {
  574. return undefined;
  575. }
  576. // A sparse array [, , 1] will have keys ["2"] whereas [undefined, undefined, 1] will have keys ["0", "1", "2"]
  577. const aKeys = Object.keys(a);
  578. const bKeys = Object.keys(b);
  579. return (0, _jasmineUtils.equals)(a, b, customTesters.filter(t => t !== sparseArrayEquality), true) && (0, _jasmineUtils.equals)(aKeys, bKeys);
  580. };
  581. exports.sparseArrayEquality = sparseArrayEquality;
  582. const partition = (items, predicate) => {
  583. const result = [[], []];
  584. for (const item of items) result[predicate(item) ? 0 : 1].push(item);
  585. return result;
  586. };
  587. exports.partition = partition;
  588. const pathAsArray = propertyPath => {
  589. const properties = [];
  590. if (propertyPath === '') {
  591. properties.push('');
  592. return properties;
  593. }
  594. // will match everything that's not a dot or a bracket, and "" for consecutive dots.
  595. const pattern = new RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
  596. // Because the regex won't match a dot in the beginning of the path, if present.
  597. if (propertyPath[0] === '.') {
  598. properties.push('');
  599. }
  600. propertyPath.replaceAll(pattern, match => {
  601. properties.push(match);
  602. return match;
  603. });
  604. return properties;
  605. };
  606. // Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/src/Angular.js#L685-L693
  607. exports.pathAsArray = pathAsArray;
  608. const isError = value => {
  609. switch (Object.prototype.toString.call(value)) {
  610. case '[object Error]':
  611. case '[object Exception]':
  612. case '[object DOMException]':
  613. return true;
  614. default:
  615. return value instanceof Error;
  616. }
  617. };
  618. exports.isError = isError;
  619. function emptyObject(obj) {
  620. return obj && typeof obj === 'object' ? Object.keys(obj).length === 0 : false;
  621. }
  622. const MULTILINE_REGEXP = /[\n\r]/;
  623. const isOneline = (expected, received) => typeof expected === 'string' && typeof received === 'string' && (!MULTILINE_REGEXP.test(expected) || !MULTILINE_REGEXP.test(received));
  624. exports.isOneline = isOneline;
  625. /***/ })
  626. /******/ });
  627. /************************************************************************/
  628. /******/ // The module cache
  629. /******/ var __webpack_module_cache__ = {};
  630. /******/
  631. /******/ // The require function
  632. /******/ function __webpack_require__(moduleId) {
  633. /******/ // Check if module is in cache
  634. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  635. /******/ if (cachedModule !== undefined) {
  636. /******/ return cachedModule.exports;
  637. /******/ }
  638. /******/ // Create a new module (and put it into the cache)
  639. /******/ var module = __webpack_module_cache__[moduleId] = {
  640. /******/ // no module.id needed
  641. /******/ // no module.loaded needed
  642. /******/ exports: {}
  643. /******/ };
  644. /******/
  645. /******/ // Execute the module function
  646. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  647. /******/
  648. /******/ // Return the exports of the module
  649. /******/ return module.exports;
  650. /******/ }
  651. /******/
  652. /************************************************************************/
  653. /******/
  654. /******/ // startup
  655. /******/ // Load entry module and return exports
  656. /******/ // This entry module is referenced by other modules so it can't be inlined
  657. /******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
  658. /******/ module.exports = __webpack_exports__;
  659. /******/
  660. /******/ })()
  661. ;