@multiplatform.one/test-utils 7.83.1 → 7.83.2

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.
@@ -0,0 +1,583 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
+ get: () => from[key],
11
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
+ });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+ var import_jest_dom = require("@testing-library/jest-dom");
26
+ var import_matchmedia_polyfill = require("matchmedia-polyfill");
27
+ var import_config = require("@tamagui/config");
28
+ var import_react = require("@testing-library/react");
29
+ var import_tamagui = require("tamagui");
30
+ var import_vitest = require("vitest");
31
+ var import_frames = require("./frames.cjs");
32
+ const _noopStorage = {
33
+ getItem: () => null,
34
+ setItem: () => {},
35
+ removeItem: () => {},
36
+ clear: () => {},
37
+ get length() {
38
+ return 0;
39
+ },
40
+ key: () => null
41
+ };
42
+ if (typeof globalThis !== "undefined" && typeof globalThis.localStorage === "undefined") {
43
+ Object.defineProperty(globalThis, "localStorage", {
44
+ value: _noopStorage,
45
+ writable: true
46
+ });
47
+ }
48
+ if (typeof global !== "undefined" && !("localStorage" in global)) {
49
+ Object.defineProperty(global, "localStorage", {
50
+ value: _noopStorage,
51
+ writable: true
52
+ });
53
+ }
54
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
55
+ if (typeof CSSStyleDeclaration !== "undefined" && CSSStyleDeclaration.prototype) {
56
+ for (let i = 0; i <= 64; i++) {
57
+ const key = String(i);
58
+ const desc = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, key);
59
+ if (!desc || desc.set == null) {
60
+ Object.defineProperty(CSSStyleDeclaration.prototype, key, {
61
+ configurable: true,
62
+ enumerable: false,
63
+ get() {
64
+ return "";
65
+ },
66
+ set() {}
67
+ });
68
+ }
69
+ }
70
+ }
71
+ if (typeof NodeList !== "undefined" && NodeList.prototype) {
72
+ if (!NodeList.prototype.forEach) {
73
+ NodeList.prototype.forEach = Array.prototype.forEach;
74
+ }
75
+ }
76
+ if (typeof HTMLCollection !== "undefined" && HTMLCollection.prototype) {
77
+ if (!HTMLCollection.prototype.forEach) {
78
+ HTMLCollection.prototype.forEach = Array.prototype.forEach;
79
+ }
80
+ }
81
+ const matchesImpl = function (selector) {
82
+ if (!this || typeof this !== "object") return false;
83
+ if (this.nodeType === 1) {
84
+ if (this.webkitMatchesSelector) return this.webkitMatchesSelector(selector);
85
+ if (this.mozMatchesSelector) return this.mozMatchesSelector(selector);
86
+ if (this.msMatchesSelector) return this.msMatchesSelector(selector);
87
+ const matches = (this.ownerDocument || document).querySelectorAll(selector);
88
+ let i = matches.length;
89
+ while (--i >= 0 && matches[i] !== this) {}
90
+ return i > -1;
91
+ }
92
+ return false;
93
+ };
94
+ if (Element.prototype && !Element.prototype.matches) {
95
+ Object.defineProperty(Element.prototype, "matches", {
96
+ value: matchesImpl,
97
+ writable: true,
98
+ configurable: true,
99
+ enumerable: false
100
+ });
101
+ }
102
+ if (typeof HTMLElement !== "undefined" && HTMLElement.prototype && !HTMLElement.prototype.matches) {
103
+ Object.defineProperty(HTMLElement.prototype, "matches", {
104
+ value: matchesImpl,
105
+ writable: true,
106
+ configurable: true,
107
+ enumerable: false
108
+ });
109
+ }
110
+ const hasAttributeImpl = function (name) {
111
+ if (!this || this.nodeType !== 1) return false;
112
+ if (Element.prototype.hasAttribute && this instanceof Element) {
113
+ return Element.prototype.hasAttribute.call(this, name);
114
+ }
115
+ if (this.attributes) {
116
+ for (let i = 0; i < this.attributes.length; i++) {
117
+ if (this.attributes[i].name === name) return true;
118
+ }
119
+ }
120
+ return false;
121
+ };
122
+ const getAttributeImpl = function (name) {
123
+ if (!this || this.nodeType !== 1) return null;
124
+ if (Element.prototype.getAttribute && this instanceof Element) {
125
+ return Element.prototype.getAttribute.call(this, name);
126
+ }
127
+ if (this.attributes) {
128
+ for (let i = 0; i < this.attributes.length; i++) {
129
+ if (this.attributes[i].name === name) return this.attributes[i].value;
130
+ }
131
+ }
132
+ return null;
133
+ };
134
+ const nodeTypes = [typeof Node !== "undefined" && Node, typeof Element !== "undefined" && Element, typeof HTMLElement !== "undefined" && HTMLElement, typeof HTMLDivElement !== "undefined" && HTMLDivElement, typeof HTMLSpanElement !== "undefined" && HTMLSpanElement, typeof HTMLInputElement !== "undefined" && HTMLInputElement, typeof HTMLButtonElement !== "undefined" && HTMLButtonElement, typeof HTMLFormElement !== "undefined" && HTMLFormElement, typeof HTMLLabelElement !== "undefined" && HTMLLabelElement, typeof Text !== "undefined" && Text, typeof Comment !== "undefined" && Comment, typeof Document !== "undefined" && Document, typeof DocumentFragment !== "undefined" && DocumentFragment].filter(Boolean);
135
+ for (const NodeType of nodeTypes) {
136
+ if (NodeType?.prototype) {
137
+ if (!NodeType.prototype.hasAttribute) {
138
+ Object.defineProperty(NodeType.prototype, "hasAttribute", {
139
+ value: hasAttributeImpl,
140
+ writable: true,
141
+ configurable: true,
142
+ enumerable: false
143
+ });
144
+ }
145
+ if (!NodeType.prototype.getAttribute) {
146
+ Object.defineProperty(NodeType.prototype, "getAttribute", {
147
+ value: getAttributeImpl,
148
+ writable: true,
149
+ configurable: true,
150
+ enumerable: false
151
+ });
152
+ }
153
+ if (!NodeType.prototype.setAttribute) {
154
+ Object.defineProperty(NodeType.prototype, "setAttribute", {
155
+ value: function (name, value) {
156
+ if (this.nodeType === 1 && Element.prototype.setAttribute) {
157
+ Element.prototype.setAttribute.call(this, name, value);
158
+ }
159
+ },
160
+ writable: true,
161
+ configurable: true,
162
+ enumerable: false
163
+ });
164
+ }
165
+ }
166
+ }
167
+ if (typeof HTMLFormElement !== "undefined") {
168
+ Object.defineProperty(HTMLFormElement.prototype, "requestSubmit", {
169
+ value: function (submitter) {
170
+ if (submitter) {
171
+ if (submitter.type !== "submit") {
172
+ throw new TypeError("The specified element is not a submit button");
173
+ }
174
+ if (submitter.form !== this) {
175
+ throw new DOMException("The specified element is not owned by this form element", "NotFoundError");
176
+ }
177
+ }
178
+ const submitEvent = new Event("submit", {
179
+ bubbles: true,
180
+ cancelable: true
181
+ });
182
+ this.dispatchEvent(submitEvent);
183
+ },
184
+ writable: true,
185
+ configurable: true,
186
+ enumerable: false
187
+ });
188
+ }
189
+ }
190
+ const floatingUiPatched = import("@floating-ui/react/utils").then(floatingUiUtils => {
191
+ if (floatingUiUtils?.enableFocusInside) {
192
+ const originalEnableFocusInside = floatingUiUtils.enableFocusInside;
193
+ floatingUiUtils.enableFocusInside = container => {
194
+ if (!container || !container.querySelectorAll) return;
195
+ const elements = container.querySelectorAll("[data-tabindex]");
196
+ if (!elements.forEach) {
197
+ elements.forEach = Array.prototype.forEach;
198
+ }
199
+ return originalEnableFocusInside(container);
200
+ };
201
+ }
202
+ }).catch(() => {});
203
+ (0, import_vitest.beforeAll)(() => floatingUiPatched);
204
+ (0, import_tamagui.createTamagui)(import_config.config);
205
+ const noopStorage = {
206
+ getItem: () => null,
207
+ setItem: () => {},
208
+ removeItem: () => {},
209
+ clear: () => {},
210
+ get length() {
211
+ return 0;
212
+ },
213
+ key: () => null
214
+ };
215
+ import_vitest.vi.stubGlobal("localStorage", noopStorage);
216
+ Object.defineProperty(globalThis, "localStorage", {
217
+ value: noopStorage,
218
+ writable: true
219
+ });
220
+ if (typeof global !== "undefined") {
221
+ Object.defineProperty(global, "localStorage", {
222
+ value: noopStorage,
223
+ writable: true
224
+ });
225
+ }
226
+ if (typeof globalThis !== "undefined" && typeof globalThis.BroadcastChannel === "undefined") {
227
+ globalThis.BroadcastChannel = class BroadcastChannelMock {
228
+ name;
229
+ onmessage = null;
230
+ constructor(name) {
231
+ this.name = name;
232
+ }
233
+ postMessage(_message) {}
234
+ close() {}
235
+ };
236
+ }
237
+ if (typeof window !== "undefined" && !window.indexedDB) {
238
+ Object.defineProperty(window, "indexedDB", {
239
+ value: {
240
+ open: () => ({
241
+ onsuccess: null,
242
+ onerror: null,
243
+ onupgradeneeded: null,
244
+ result: null
245
+ }),
246
+ deleteDatabase: () => ({
247
+ onsuccess: null,
248
+ onerror: null
249
+ })
250
+ },
251
+ writable: true
252
+ });
253
+ }
254
+ import_vitest.vi.stubGlobal("fetch", import_vitest.vi.fn(() => Promise.resolve(new Response(JSON.stringify({
255
+ data: []
256
+ }), {
257
+ status: 200,
258
+ headers: {
259
+ "Content-Type": "application/json"
260
+ }
261
+ }))));
262
+ window.matchMedia = window.matchMedia || (() => ({
263
+ matches: false,
264
+ addListener: () => {},
265
+ removeListener: () => {}
266
+ }));
267
+ const animationFrames = (0, import_frames.createAnimationFrames)();
268
+ global.requestAnimationFrame = animationFrames.request;
269
+ global.cancelAnimationFrame = animationFrames.cancel;
270
+ (0, import_vitest.afterAll)(animationFrames.close);
271
+ class MockResizeObserver {
272
+ observe() {}
273
+ unobserve() {}
274
+ disconnect() {}
275
+ }
276
+ window.ResizeObserver = MockResizeObserver;
277
+ class MockIntersectionObserver {
278
+ root = null;
279
+ rootMargin = "0px";
280
+ // TS7's dom lib added scrollMargin to the interface.
281
+ scrollMargin = "0px";
282
+ thresholds = [0];
283
+ observe() {}
284
+ unobserve() {}
285
+ disconnect() {}
286
+ takeRecords() {
287
+ return [];
288
+ }
289
+ }
290
+ if (typeof window !== "undefined") {
291
+ Object.defineProperty(window, "IntersectionObserver", {
292
+ value: MockIntersectionObserver,
293
+ writable: true,
294
+ configurable: true
295
+ });
296
+ }
297
+ Object.defineProperty(globalThis, "IntersectionObserver", {
298
+ value: MockIntersectionObserver,
299
+ writable: true,
300
+ configurable: true
301
+ });
302
+ if (typeof global !== "undefined") {
303
+ Object.defineProperty(global, "IntersectionObserver", {
304
+ value: MockIntersectionObserver,
305
+ writable: true,
306
+ configurable: true
307
+ });
308
+ }
309
+ if (typeof self !== "undefined") {
310
+ Object.defineProperty(self, "IntersectionObserver", {
311
+ value: MockIntersectionObserver,
312
+ writable: true,
313
+ configurable: true
314
+ });
315
+ }
316
+ if (typeof DataTransfer === "undefined") {
317
+ global.DataTransfer = class DataTransfer {
318
+ data;
319
+ constructor() {
320
+ this.data = /* @__PURE__ */new Map();
321
+ }
322
+ getData(format) {
323
+ return this.data.get(format) || "";
324
+ }
325
+ setData(format, data) {
326
+ this.data.set(format, data);
327
+ }
328
+ clearData(format) {
329
+ if (format) {
330
+ this.data.delete(format);
331
+ } else {
332
+ this.data.clear();
333
+ }
334
+ }
335
+ };
336
+ }
337
+ if (typeof ClipboardEvent === "undefined") {
338
+ global.ClipboardEvent = class ClipboardEvent extends Event {
339
+ clipboardData;
340
+ constructor(type, options) {
341
+ super(type, options);
342
+ this.clipboardData = options?.clipboardData || {
343
+ getData: () => "",
344
+ setData: () => {}
345
+ };
346
+ }
347
+ };
348
+ }
349
+ class ESBuildAndJSDOMCompatibleTextEncoder extends TextEncoder {
350
+ encode(input) {
351
+ if (typeof input !== "string") throw new TypeError("`input` must be a string");
352
+ const decodedURI = decodeURIComponent(encodeURIComponent(input));
353
+ const arr = new Uint8Array(decodedURI.length);
354
+ const chars = decodedURI.split("");
355
+ for (let i = 0; i < chars.length; i++) {
356
+ arr[i] = (decodedURI[i] || "").charCodeAt(0);
357
+ }
358
+ return arr;
359
+ }
360
+ }
361
+ Object.defineProperty(global, "TextEncoder", {
362
+ value: ESBuildAndJSDOMCompatibleTextEncoder,
363
+ writable: true
364
+ });
365
+ import_vitest.vi.mock("@multiplatform.one/theme", async importOriginal => {
366
+ const actual = await importOriginal();
367
+ const getSizeClass = actual.getLayoutSizeClass;
368
+ const getPaneBudget = actual.defaultMaxPanes;
369
+ const fallbackWidth = actual.layoutBreakpoints.medium;
370
+ const viewportWidth = () => typeof window === "undefined" ? fallbackWidth : window.innerWidth;
371
+ return {
372
+ ...actual,
373
+ // Real useLayoutSizeClass subscribes via matchMedia().addEventListener,
374
+ // which test matchMedia polyfills / per-spec vi.fn mocks routinely lack;
375
+ // resolve from window.innerWidth at render (the same value the real hook
376
+ // computes at mount) through the real getLayoutSizeClass.
377
+ useLayoutSizeClass: () => getSizeClass(viewportWidth()),
378
+ // Rides useLayoutSizeClass (same matchMedia dependency); derive the pane
379
+ // budget through the real defaultMaxPanes.
380
+ useMultiPane: maxPanes => {
381
+ const budget = getPaneBudget(getSizeClass(viewportWidth()));
382
+ return (maxPanes ?? budget) >= 2 && budget >= 2;
383
+ },
384
+ // Real tracker installs document-level capture listeners backed by module
385
+ // state, leaking "last input was keyboard" across tests in a file; noop.
386
+ ensureKeyboardModalityTracking: () => {},
387
+ // Pin pointer modality so manual focus-ring painting is deterministic.
388
+ wasKeyboardFocus: () => false
389
+ };
390
+ });
391
+ import_vitest.vi.mock("one", () => ({
392
+ default: {},
393
+ SafeAreaView: ({
394
+ children
395
+ }) => children,
396
+ Head: ({
397
+ children
398
+ }) => children,
399
+ useRouter: () => ({
400
+ push: import_vitest.vi.fn(),
401
+ replace: import_vitest.vi.fn(),
402
+ back: import_vitest.vi.fn()
403
+ })
404
+ }));
405
+ import_vitest.vi.mock("@tamagui/animations-reanimated", () => ({
406
+ createAnimations: config2 => ({
407
+ ...config2,
408
+ View: void 0,
409
+ Text: void 0,
410
+ isReactNative: false,
411
+ animations: config2,
412
+ useAnimatedNumber: initial => ({
413
+ value: initial,
414
+ setValue: () => {}
415
+ }),
416
+ useAnimatedNumberReaction: () => {},
417
+ useAnimatedNumberStyle: () => ({}),
418
+ AnimatedView: ({
419
+ children
420
+ }) => children,
421
+ AnimatedText: ({
422
+ children
423
+ }) => children
424
+ })
425
+ }));
426
+ import_vitest.vi.mock("react-native-reanimated", () => ({
427
+ default: {
428
+ useSharedValue: init => ({
429
+ value: init
430
+ }),
431
+ useAnimatedStyle: () => ({}),
432
+ withTiming: val => val,
433
+ withSpring: val => val,
434
+ withDecay: val => val,
435
+ withSequence: (...args) => args[args.length - 1],
436
+ withDelay: (_, val) => val,
437
+ createAnimatedComponent: component => component,
438
+ useDerivedValue: fn => ({
439
+ value: fn()
440
+ }),
441
+ useAnimatedRef: () => ({
442
+ current: null
443
+ }),
444
+ runOnJS: fn => fn,
445
+ runOnUI: fn => fn,
446
+ Extrapolation: {
447
+ CLAMP: "clamp"
448
+ },
449
+ Layout: {
450
+ duration: () => ({})
451
+ },
452
+ FadeIn: {
453
+ duration: () => ({})
454
+ },
455
+ FadeOut: {
456
+ duration: () => ({})
457
+ },
458
+ Easing: {
459
+ linear: v => v,
460
+ ease: v => v,
461
+ bezier: () => v => v
462
+ },
463
+ measure: () => null,
464
+ scrollTo: () => {},
465
+ makeMutable: init => ({
466
+ value: init
467
+ })
468
+ },
469
+ useSharedValue: init => ({
470
+ value: init
471
+ }),
472
+ useAnimatedStyle: () => ({}),
473
+ withTiming: val => val,
474
+ withSpring: val => val,
475
+ createAnimatedComponent: component => component,
476
+ runOnJS: fn => fn,
477
+ runOnUI: fn => fn,
478
+ useDerivedValue: fn => ({
479
+ value: fn()
480
+ }),
481
+ useAnimatedRef: () => ({
482
+ current: null
483
+ }),
484
+ Easing: {
485
+ linear: v => v,
486
+ ease: v => v,
487
+ bezier: () => v => v
488
+ },
489
+ FadeIn: {
490
+ duration: () => ({})
491
+ },
492
+ FadeOut: {
493
+ duration: () => ({})
494
+ },
495
+ Layout: {
496
+ duration: () => ({})
497
+ }
498
+ }));
499
+ import_vitest.vi.mock("@react-navigation/native", () => ({
500
+ NavigationContainer: ({
501
+ children
502
+ }) => children,
503
+ useNavigation: () => ({}),
504
+ useRoute: () => ({}),
505
+ useFocusEffect: () => {}
506
+ }));
507
+ if (typeof document !== "undefined") {
508
+ const style = document.createElement("style");
509
+ style.textContent = "html { pointer-events: auto !important; }";
510
+ document.head.appendChild(style);
511
+ }
512
+ const ignoredTestWarnings = ["React does not recognize the `scaleIcon` prop on a DOM element", "React does not recognize the `pressTheme` prop on a DOM element", "React does not recognize the `marginLeft` prop on a DOM element", "Received `true` for a non-boolean attribute `editable`", "non-boolean attribute `editable`", "Received `true` for a non-boolean attribute `elevate`", "Received `true` for a non-boolean attribute `bordered`", "react-i18next:: useTranslation: You will need to pass in an i18next instance"];
513
+ const originalConsoleWarn = console.warn.bind(console);
514
+ const originalConsoleError = console.error.bind(console);
515
+ const shouldIgnoreTestWarning = args => {
516
+ const message = args.map(arg => {
517
+ if (typeof arg === "string") return arg;
518
+ if (arg instanceof Error) return arg.message;
519
+ return String(arg);
520
+ }).join(" ");
521
+ if (ignoredTestWarnings.some(pattern => message.includes(pattern))) {
522
+ return true;
523
+ }
524
+ const firstArg = typeof args[0] === "string" ? args[0] : "";
525
+ const hasNonBooleanTemplate = firstArg.includes("non-boolean attribute");
526
+ if (hasNonBooleanTemplate) {
527
+ const tokens = args.map(arg => String(arg));
528
+ if (tokens.includes("editable") || tokens.includes("elevate") || tokens.includes("bordered")) {
529
+ return true;
530
+ }
531
+ }
532
+ return false;
533
+ };
534
+ let consoleWarnSpy = null;
535
+ let consoleErrorSpy = null;
536
+ (0, import_vitest.beforeEach)(() => {
537
+ Object.defineProperty(globalThis, "IntersectionObserver", {
538
+ value: MockIntersectionObserver,
539
+ writable: true,
540
+ configurable: true
541
+ });
542
+ if (typeof window !== "undefined") {
543
+ Object.defineProperty(window, "IntersectionObserver", {
544
+ value: MockIntersectionObserver,
545
+ writable: true,
546
+ configurable: true
547
+ });
548
+ }
549
+ if (typeof global !== "undefined") {
550
+ Object.defineProperty(global, "IntersectionObserver", {
551
+ value: MockIntersectionObserver,
552
+ writable: true,
553
+ configurable: true
554
+ });
555
+ }
556
+ consoleWarnSpy = import_vitest.vi.spyOn(console, "warn").mockImplementation((...args) => {
557
+ if (shouldIgnoreTestWarning(args)) return;
558
+ originalConsoleWarn(...args);
559
+ });
560
+ consoleErrorSpy = import_vitest.vi.spyOn(console, "error").mockImplementation((...args) => {
561
+ if (shouldIgnoreTestWarning(args)) return;
562
+ originalConsoleError(...args);
563
+ });
564
+ });
565
+ (0, import_vitest.afterEach)(() => {
566
+ Object.defineProperty(globalThis, "IntersectionObserver", {
567
+ value: MockIntersectionObserver,
568
+ writable: true,
569
+ configurable: true
570
+ });
571
+ if (typeof window !== "undefined") {
572
+ Object.defineProperty(window, "IntersectionObserver", {
573
+ value: MockIntersectionObserver,
574
+ writable: true,
575
+ configurable: true
576
+ });
577
+ }
578
+ consoleWarnSpy?.mockRestore();
579
+ consoleErrorSpy?.mockRestore();
580
+ consoleWarnSpy = null;
581
+ consoleErrorSpy = null;
582
+ (0, import_react.cleanup)();
583
+ });