@terreno/test 57.18.0 → 57.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +2074 -0
  2. package/README.md +6 -0
  3. package/dist/assertions/expectAPIError.d.ts +18 -0
  4. package/dist/assertions/expectAPIError.js +33 -0
  5. package/dist/assertions/strictResponseProperties.d.ts +14 -0
  6. package/dist/assertions/strictResponseProperties.js +37 -0
  7. package/dist/cache/mongoTestCache.js +2 -2
  8. package/dist/cli/collectFiles.d.ts +38 -0
  9. package/dist/cli/collectFiles.js +73 -0
  10. package/dist/cli/testHygiene.d.ts +134 -0
  11. package/dist/cli/testHygiene.js +357 -0
  12. package/dist/cli/testHygieneCli.d.ts +2 -0
  13. package/dist/cli/testHygieneCli.js +5 -0
  14. package/dist/cli/testHygieneRules.d.ts +58 -0
  15. package/dist/cli/testHygieneRules.js +517 -0
  16. package/dist/cli/testShard.d.ts +155 -0
  17. package/dist/cli/testShard.js +377 -0
  18. package/dist/cli/testShardCli.d.ts +2 -0
  19. package/dist/cli/testShardCli.js +5 -0
  20. package/dist/expo/authTokenStorage.d.ts +76 -0
  21. package/dist/expo/authTokenStorage.js +160 -0
  22. package/dist/expo/expoModuleMocks.d.ts +24 -0
  23. package/dist/expo/expoModuleMocks.js +456 -0
  24. package/dist/expo/libraryModuleMocks.d.ts +17 -0
  25. package/dist/expo/libraryModuleMocks.js +347 -0
  26. package/dist/expo/mockHelpers.d.ts +39 -0
  27. package/dist/expo/mockHelpers.js +45 -0
  28. package/dist/expo/mockModuleAliases.d.ts +50 -0
  29. package/dist/expo/mockModuleAliases.js +174 -0
  30. package/dist/expo/reactNativeMock.d.ts +39 -0
  31. package/dist/expo/reactNativeMock.js +421 -0
  32. package/dist/expo/registerExpoTestEnvironment.d.ts +69 -0
  33. package/dist/expo/registerExpoTestEnvironment.js +165 -0
  34. package/dist/expo/renderWithTerreno.d.ts +47 -0
  35. package/dist/expo/renderWithTerreno.js +47 -0
  36. package/dist/http/authWithToken.d.ts +20 -0
  37. package/dist/http/authWithToken.js +30 -0
  38. package/dist/index.d.ts +14 -1
  39. package/dist/index.js +33 -1
  40. package/dist/logging/silenceLogs.js +0 -2
  41. package/dist/mocks/aiSdk.d.ts +77 -0
  42. package/dist/mocks/aiSdk.js +102 -0
  43. package/dist/mocks/cloudTasks.d.ts +91 -0
  44. package/dist/mocks/cloudTasks.js +197 -0
  45. package/dist/mocks/expoPush.d.ts +53 -0
  46. package/dist/mocks/expoPush.js +57 -0
  47. package/dist/mocks/gcs.d.ts +101 -0
  48. package/dist/mocks/gcs.js +162 -0
  49. package/dist/mocks/googleAuth.d.ts +69 -0
  50. package/dist/mocks/googleAuth.js +55 -0
  51. package/dist/mocks/mockGroup.d.ts +11 -0
  52. package/dist/mocks/mockGroup.js +21 -0
  53. package/dist/mocks/notifiers.d.ts +21 -0
  54. package/dist/mocks/notifiers.js +26 -0
  55. package/dist/mocks/sendgrid.d.ts +22 -0
  56. package/dist/mocks/sendgrid.js +32 -0
  57. package/dist/mocks/twilio.d.ts +72 -0
  58. package/dist/mocks/twilio.js +64 -0
  59. package/dist/preload/registerBackendPreload.js +4 -1
  60. package/dist/time/freezeTime.d.ts +16 -0
  61. package/dist/time/freezeTime.js +49 -0
  62. package/dist/transaction/testTransaction.d.ts +43 -6
  63. package/dist/transaction/testTransaction.js +371 -92
  64. package/dist/utils/waitUntil.d.ts +22 -0
  65. package/dist/utils/waitUntil.js +34 -0
  66. package/package.json +53 -8
  67. package/src/assertions/expectAPIError.ts +51 -0
  68. package/src/assertions/strictResponseProperties.ts +42 -0
  69. package/src/cache/mongoTestCache.ts +2 -2
  70. package/src/cli/collectFiles.ts +115 -0
  71. package/src/cli/testHygiene.ts +539 -0
  72. package/src/cli/testHygieneCli.ts +4 -0
  73. package/src/cli/testHygieneRules.ts +719 -0
  74. package/src/cli/testShard.ts +532 -0
  75. package/src/cli/testShardCli.ts +4 -0
  76. package/src/expo/authTokenStorage.ts +198 -0
  77. package/src/expo/expoModuleMocks.ts +503 -0
  78. package/src/expo/libraryModuleMocks.ts +411 -0
  79. package/src/expo/mockHelpers.ts +73 -0
  80. package/src/expo/mockModuleAliases.ts +252 -0
  81. package/src/expo/reactNativeMock.ts +534 -0
  82. package/src/expo/registerExpoTestEnvironment.ts +262 -0
  83. package/src/expo/renderWithTerreno.ts +79 -0
  84. package/src/http/authWithToken.ts +38 -0
  85. package/src/index.ts +82 -1
  86. package/src/logging/silenceLogs.ts +0 -2
  87. package/src/mocks/aiSdk.ts +199 -0
  88. package/src/mocks/cloudTasks.ts +323 -0
  89. package/src/mocks/expoPush.ts +134 -0
  90. package/src/mocks/gcs.ts +305 -0
  91. package/src/mocks/googleAuth.ts +136 -0
  92. package/src/mocks/mockGroup.ts +32 -0
  93. package/src/mocks/notifiers.ts +36 -0
  94. package/src/mocks/sendgrid.ts +57 -0
  95. package/src/mocks/twilio.ts +143 -0
  96. package/src/preload/registerBackendPreload.ts +4 -1
  97. package/src/time/freezeTime.ts +61 -0
  98. package/src/transaction/testTransaction.ts +456 -124
  99. package/src/utils/waitUntil.ts +47 -0
  100. package/biome.jsonc +0 -20
  101. package/bunfig.toml +0 -16
  102. package/src/cache/mongoTestCache.test.ts +0 -103
  103. package/src/env/setTerrenoTestEnv.test.ts +0 -26
  104. package/src/http/authAsUser.test.ts +0 -40
  105. package/src/http/getBaseServer.test.ts +0 -45
  106. package/src/logging/setupEnvironment.test.ts +0 -24
  107. package/src/logging/silenceLogs.test.ts +0 -52
  108. package/src/logging/testLogger.test.ts +0 -58
  109. package/src/mocks/sentryBun.test.ts +0 -230
  110. package/src/mongo/connection.test.ts +0 -43
  111. package/src/mongo/mongoServer.test.ts +0 -99
  112. package/src/preload/registerBackendPreload.test.ts +0 -10
  113. package/src/transaction/testTransaction.test.ts +0 -64
  114. package/src/utils/helpers.test.ts +0 -46
  115. package/tsconfig.json +0 -18
@@ -0,0 +1,534 @@
1
+ import {mock} from "bun:test";
2
+ import {
3
+ createElement,
4
+ Fragment,
5
+ forwardRef,
6
+ type ReactElement,
7
+ type ReactNode,
8
+ useImperativeHandle,
9
+ } from "react";
10
+
11
+ import {
12
+ type ExpoTestPlatform,
13
+ hostComponent,
14
+ type MockComponentProps,
15
+ type ModuleExports,
16
+ type ModuleMockMap,
17
+ stub,
18
+ stubIdentity,
19
+ stubResolving,
20
+ stubReturning,
21
+ stubSubscription,
22
+ } from "./mockHelpers";
23
+
24
+ /** Window metrics every dimension API in the mock reports (an iPhone-sized portrait screen). */
25
+ const MOCK_WINDOW_METRICS = {fontScale: 1, height: 812, scale: 2, width: 375} as const;
26
+
27
+ /** Result passed to an `Animated` completion callback. */
28
+ interface AnimationResult {
29
+ finished: boolean;
30
+ }
31
+
32
+ /** The `start`/`stop`/`reset` handle every `Animated` driver returns. */
33
+ export interface MockAnimation {
34
+ reset: () => void;
35
+ start: (callback?: (result: AnimationResult) => void) => void;
36
+ stop: () => void;
37
+ }
38
+
39
+ interface MockFlatListProps extends MockComponentProps {
40
+ data?: readonly unknown[] | null;
41
+ keyExtractor?: (item: unknown, index: number) => string;
42
+ renderItem?: (info: {
43
+ index: number;
44
+ item: unknown;
45
+ separators: {highlight: () => void; unhighlight: () => void};
46
+ }) => ReactNode;
47
+ }
48
+
49
+ interface MockSectionListProps extends MockComponentProps {
50
+ keyExtractor?: (item: unknown, index: number) => string;
51
+ renderItem?: (info: {index: number; item: unknown; section: unknown}) => ReactNode;
52
+ renderSectionHeader?: (info: {section: unknown}) => ReactNode;
53
+ sections?: readonly {data: readonly unknown[]; key?: string}[];
54
+ }
55
+
56
+ type ColorValue = string | number | null | undefined;
57
+
58
+ const SEPARATORS = {highlight: stub(), unhighlight: stub()};
59
+
60
+ const ABSOLUTE_FILL = {bottom: 0, left: 0, position: "absolute", right: 0, top: 0} as const;
61
+
62
+ /** Runs every child animation, then reports completion — matches `Animated.parallel` et al. */
63
+ const compositeAnimation = (animations?: readonly MockAnimation[]): MockAnimation => ({
64
+ reset: stub(),
65
+ start: mock((callback?: (result: AnimationResult) => void): void => {
66
+ for (const animation of animations ?? []) {
67
+ animation?.start?.();
68
+ }
69
+ callback?.({finished: true});
70
+ }),
71
+ stop: stub(),
72
+ });
73
+
74
+ /** A driver (`timing`, `spring`, ...) that completes as soon as it starts. */
75
+ const immediateAnimation = (): MockAnimation => compositeAnimation([]);
76
+
77
+ /** Mirrors `StyleSheet.flatten` for the plain objects and arrays tests pass. */
78
+ export const flattenStyle = (style: unknown): Record<string, unknown> => {
79
+ if (Array.isArray(style)) {
80
+ return Object.assign({}, ...style.map(flattenStyle));
81
+ }
82
+ if (style && typeof style === "object") {
83
+ return style as Record<string, unknown>;
84
+ }
85
+ return {};
86
+ };
87
+
88
+ /** Mirrors `processColor`: numbers pass through, strings become an opaque ARGB number. */
89
+ export const processColor = (color: ColorValue): number | null => {
90
+ if (color === null || color === undefined) {
91
+ return null;
92
+ }
93
+ if (typeof color === "number") {
94
+ return color;
95
+ }
96
+ return 0xff000000;
97
+ };
98
+
99
+ class AnimatedValue {
100
+ _value: number;
101
+ constructor(value = 0) {
102
+ this._value = value;
103
+ }
104
+ setValue = mock((value: number): void => {
105
+ this._value = value;
106
+ });
107
+ setOffset = stub();
108
+ flattenOffset = stub();
109
+ extractOffset = stub();
110
+ addListener = stubReturning("listener-id");
111
+ removeListener = stub();
112
+ removeAllListeners = stub();
113
+ stopAnimation = mock((callback?: (value: number) => void): void => callback?.(this._value));
114
+ resetAnimation = mock((callback?: (value: number) => void): void => callback?.(this._value));
115
+ interpolate = mock((): AnimatedValue => new AnimatedValue(0));
116
+ animate = stub();
117
+ stopTracking = stub();
118
+ track = stub();
119
+ }
120
+
121
+ class AnimatedValueXY {
122
+ x: AnimatedValue;
123
+ y: AnimatedValue;
124
+ constructor(value?: {x?: number; y?: number}) {
125
+ this.x = new AnimatedValue(value?.x ?? 0);
126
+ this.y = new AnimatedValue(value?.y ?? 0);
127
+ }
128
+ setValue = stub();
129
+ setOffset = stub();
130
+ flattenOffset = stub();
131
+ extractOffset = stub();
132
+ stopAnimation = stub();
133
+ resetAnimation = stub();
134
+ addListener = stubReturning("listener-id");
135
+ removeListener = stub();
136
+ removeAllListeners = stub();
137
+ getLayout = mock((): {left: AnimatedValue; top: AnimatedValue} => ({left: this.x, top: this.y}));
138
+ getTranslateTransform = mock((): {translateX?: AnimatedValue; translateY?: AnimatedValue}[] => [
139
+ {translateX: this.x},
140
+ {translateY: this.y},
141
+ ]);
142
+ }
143
+
144
+ const animatedNode = (): AnimatedValue => new AnimatedValue(0);
145
+
146
+ /**
147
+ * Renders every `data` row through `renderItem`. Exposes the scroll methods tests usually
148
+ * reach for through a ref (`scrollToOffset`, `scrollToIndex`, `scrollToEnd`).
149
+ */
150
+ const FlatList = forwardRef<unknown, MockFlatListProps>((flatListProps, ref): ReactElement => {
151
+ const {data, keyExtractor, renderItem, ...props} = flatListProps as MockFlatListProps;
152
+ useImperativeHandle(ref, () => ({
153
+ scrollTo: stub(),
154
+ scrollToEnd: stub(),
155
+ scrollToIndex: stub(),
156
+ scrollToOffset: stub(),
157
+ }));
158
+ const rows = (data ?? []).map((item, index) =>
159
+ createElement(
160
+ Fragment,
161
+ {key: keyExtractor?.(item, index) ?? String(index)},
162
+ renderItem?.({index, item, separators: SEPARATORS})
163
+ )
164
+ );
165
+ return createElement("FlatList", props, rows);
166
+ });
167
+
168
+ /** Renders each section header followed by its rows. */
169
+ const SectionList = ({
170
+ keyExtractor,
171
+ renderItem,
172
+ renderSectionHeader,
173
+ sections,
174
+ ...props
175
+ }: MockSectionListProps): ReactElement => {
176
+ const children = (sections ?? []).map((section, sectionIndex) =>
177
+ createElement(
178
+ Fragment,
179
+ {key: section.key ?? String(sectionIndex)},
180
+ renderSectionHeader?.({section}),
181
+ section.data.map((item, index) =>
182
+ createElement(
183
+ Fragment,
184
+ {key: keyExtractor?.(item, index) ?? String(index)},
185
+ renderItem?.({index, item, section})
186
+ )
187
+ )
188
+ )
189
+ );
190
+ return createElement("SectionList", props, children);
191
+ };
192
+
193
+ /**
194
+ * Builds the `react-native` module stand-in: host-element components, no-op native APIs, and
195
+ * `Platform.OS` set to `platform`. Bun cannot parse React Native's Flow sources, so every test
196
+ * that renders React Native code needs this (or an equivalent) registered before the first import.
197
+ */
198
+ export const createReactNativeMock = ({
199
+ platform = "ios",
200
+ }: {
201
+ platform?: ExpoTestPlatform;
202
+ } = {}): ModuleExports => {
203
+ const View = hostComponent("View");
204
+ const Text = hostComponent("Text");
205
+ const Image = hostComponent("Image");
206
+ const ScrollView = hostComponent("ScrollView");
207
+
208
+ const Animated = {
209
+ add: mock(animatedNode),
210
+ createAnimatedComponent: stubIdentity(),
211
+ decay: mock(immediateAnimation),
212
+ delay: mock(immediateAnimation),
213
+ diffClamp: mock(animatedNode),
214
+ divide: mock(animatedNode),
215
+ event: stubReturning(stub()),
216
+ FlatList,
217
+ Image,
218
+ loop: mock((animation?: MockAnimation) => compositeAnimation(animation ? [animation] : [])),
219
+ modulo: mock(animatedNode),
220
+ multiply: mock(animatedNode),
221
+ parallel: mock(compositeAnimation),
222
+ ScrollView,
223
+ sequence: mock(compositeAnimation),
224
+ spring: mock(immediateAnimation),
225
+ stagger: mock((_delay: number, animations?: readonly MockAnimation[]) =>
226
+ compositeAnimation(animations)
227
+ ),
228
+ subtract: mock(animatedNode),
229
+ Text,
230
+ timing: mock(immediateAnimation),
231
+ Value: AnimatedValue,
232
+ ValueXY: AnimatedValueXY,
233
+ View,
234
+ };
235
+
236
+ const Platform = {
237
+ constants: {reactNativeVersion: {major: 0, minor: 0, patch: 0}},
238
+ isPad: false,
239
+ isTV: false,
240
+ OS: platform,
241
+ select: <T>(spec: Partial<Record<ExpoTestPlatform | "native" | "default", T>>): T | undefined =>
242
+ spec[platform] ?? (platform === "web" ? undefined : spec.native) ?? spec.default,
243
+ Version: platform === "android" ? 34 : "17.0",
244
+ };
245
+
246
+ const StyleSheet = {
247
+ absoluteFill: ABSOLUTE_FILL,
248
+ absoluteFillObject: ABSOLUTE_FILL,
249
+ compose: (a: unknown, b: unknown): unknown => (a && b ? [a, b] : (a ?? b)),
250
+ create: <T>(styles: T): T => styles,
251
+ flatten: flattenStyle,
252
+ hairlineWidth: 1,
253
+ };
254
+
255
+ const exports: ModuleExports = {
256
+ AccessibilityInfo: {
257
+ addEventListener: stubSubscription(),
258
+ announceForAccessibility: stub(),
259
+ isAccessibilityServiceEnabled: stubResolving(false),
260
+ isBoldTextEnabled: stubResolving(false),
261
+ isGrayscaleEnabled: stubResolving(false),
262
+ isInvertColorsEnabled: stubResolving(false),
263
+ isReduceMotionEnabled: stubResolving(false),
264
+ isReduceTransparencyEnabled: stubResolving(false),
265
+ isScreenReaderEnabled: stubResolving(false),
266
+ setAccessibilityFocus: stub(),
267
+ },
268
+ ActivityIndicator: hostComponent("ActivityIndicator"),
269
+ Alert: {alert: stub(), prompt: stub()},
270
+ Animated,
271
+ Appearance: {
272
+ addChangeListener: stubSubscription(),
273
+ getColorScheme: stubReturning("light"),
274
+ setColorScheme: stub(),
275
+ },
276
+ AppRegistry: {
277
+ getAppKeys: stubReturning([]),
278
+ registerComponent: stub(),
279
+ registerRunnable: stub(),
280
+ runApplication: stub(),
281
+ },
282
+ AppState: {addEventListener: stubSubscription(), currentState: "active"},
283
+ BackHandler: {addEventListener: stubSubscription(), exitApp: stub()},
284
+ Button: hostComponent("Button"),
285
+ DeviceEventEmitter: {
286
+ addListener: stubSubscription(),
287
+ emit: stub(),
288
+ removeAllListeners: stub(),
289
+ },
290
+ Dimensions: {addEventListener: stubSubscription(), get: stubReturning(MOCK_WINDOW_METRICS)},
291
+ DynamicColorIOS: (colors: {light: string}): string => colors.light,
292
+ Easing: {
293
+ back: stubReturning(stubIdentity()),
294
+ bezier: stubReturning(stubIdentity()),
295
+ bounce: stubIdentity(),
296
+ circle: stubIdentity(),
297
+ cubic: stubIdentity(),
298
+ ease: stubIdentity(),
299
+ elastic: stubReturning(stubIdentity()),
300
+ exp: stubIdentity(),
301
+ in: stubIdentity(),
302
+ inOut: stubIdentity(),
303
+ linear: stubIdentity(),
304
+ out: stubIdentity(),
305
+ poly: stubReturning(stubIdentity()),
306
+ quad: stubIdentity(),
307
+ sin: stubIdentity(),
308
+ },
309
+ FlatList,
310
+ findNodeHandle: mock((node: unknown): number | null =>
311
+ typeof node === "number" ? node : null
312
+ ),
313
+ I18nManager: {
314
+ allowRTL: stub(),
315
+ doLeftAndRightSwapInRTL: true,
316
+ forceRTL: stub(),
317
+ isRTL: false,
318
+ swapLeftAndRightInRTL: stub(),
319
+ },
320
+ Image,
321
+ ImageBackground: hostComponent("ImageBackground"),
322
+ InteractionManager: {
323
+ clearInteractionHandle: stub(),
324
+ createInteractionHandle: stubReturning(1),
325
+ runAfterInteractions: mock((task?: () => void) => {
326
+ task?.();
327
+ return {cancel: stub(), done: Promise.resolve()};
328
+ }),
329
+ },
330
+ Keyboard: {
331
+ addListener: stubSubscription(),
332
+ dismiss: stub(),
333
+ isVisible: stubReturning(false),
334
+ metrics: stubReturning(undefined),
335
+ },
336
+ KeyboardAvoidingView: hostComponent("KeyboardAvoidingView"),
337
+ LayoutAnimation: {
338
+ configureNext: stub(),
339
+ create: stubReturning({}),
340
+ easeInEaseOut: stub(),
341
+ linear: stub(),
342
+ Presets: {},
343
+ Properties: {},
344
+ spring: stub(),
345
+ Types: {},
346
+ },
347
+ Linking: {
348
+ addEventListener: stubSubscription(),
349
+ canOpenURL: stubResolving(true),
350
+ getInitialURL: stubResolving(null),
351
+ openSettings: stubResolving(undefined),
352
+ openURL: stubResolving(undefined),
353
+ },
354
+ LogBox: {ignoreAllLogs: stub(), ignoreLogs: stub(), install: stub(), uninstall: stub()},
355
+ Modal: hostComponent("Modal"),
356
+ NativeEventEmitter: class NativeEventEmitter {
357
+ addListener = stubSubscription();
358
+ emit = stub();
359
+ listenerCount = stubReturning(0);
360
+ removeAllListeners = stub();
361
+ removeSubscription = stub();
362
+ },
363
+ NativeModules: {},
364
+ PanResponder: {
365
+ create: mock(() => ({getInteractionHandle: stubReturning(null), panHandlers: {}})),
366
+ },
367
+ PixelRatio: {
368
+ get: stubReturning(MOCK_WINDOW_METRICS.scale),
369
+ getFontScale: stubReturning(MOCK_WINDOW_METRICS.fontScale),
370
+ getPixelSizeForLayoutSize: mock((size: number): number => size * MOCK_WINDOW_METRICS.scale),
371
+ roundToNearestPixel: stubIdentity(),
372
+ },
373
+ Platform,
374
+ PlatformColor: (...names: string[]): string | undefined => names[0],
375
+ Pressable: hostComponent("Pressable"),
376
+ processColor,
377
+ RefreshControl: hostComponent("RefreshControl"),
378
+ requireNativeComponent: stubIdentity(),
379
+ SafeAreaView: hostComponent("SafeAreaView"),
380
+ ScrollView,
381
+ SectionList,
382
+ Share: {
383
+ dismissedAction: "dismissedAction",
384
+ share: stubResolving({action: "sharedAction"}),
385
+ sharedAction: "sharedAction",
386
+ },
387
+ StatusBar: Object.assign(hostComponent("StatusBar"), {
388
+ currentHeight: 0,
389
+ setBackgroundColor: stub(),
390
+ setBarStyle: stub(),
391
+ setHidden: stub(),
392
+ setNetworkActivityIndicatorVisible: stub(),
393
+ setTranslucent: stub(),
394
+ }),
395
+ StyleSheet,
396
+ Switch: hostComponent("Switch"),
397
+ Text,
398
+ TextInput: Object.assign(hostComponent("TextInput"), {
399
+ State: {
400
+ blurTextInput: stub(),
401
+ currentlyFocusedInput: stubReturning(null),
402
+ focusTextInput: stub(),
403
+ },
404
+ }),
405
+ TouchableHighlight: hostComponent("TouchableHighlight"),
406
+ TouchableNativeFeedback: hostComponent("TouchableNativeFeedback"),
407
+ TouchableOpacity: hostComponent("TouchableOpacity"),
408
+ TouchableWithoutFeedback: hostComponent("TouchableWithoutFeedback"),
409
+ TurboModuleRegistry: {get: stubReturning(null), getEnforcing: stubReturning({})},
410
+ UIManager: {
411
+ getViewManagerConfig: stubReturning({}),
412
+ measure: stub(),
413
+ setLayoutAnimationEnabledExperimental: stub(),
414
+ },
415
+ useColorScheme: stubReturning("light"),
416
+ useWindowDimensions: stubReturning(MOCK_WINDOW_METRICS),
417
+ Vibration: {cancel: stub(), vibrate: stub()},
418
+ View,
419
+ VirtualizedList: FlatList,
420
+ };
421
+ return {...exports, default: exports};
422
+ };
423
+
424
+ /** `default` + named export module for a single value, as React Native's internal files expose. */
425
+ const defaultExport = (value: unknown): ModuleExports => ({__esModule: true, default: value});
426
+
427
+ /**
428
+ * Stand-ins for React Native internals that libraries import by deep path. Each of these files
429
+ * uses Flow syntax Bun cannot parse, so a library that reaches past the `react-native` entry
430
+ * point needs the matching stub. Keys are relative to the `react-native` package.
431
+ */
432
+ export const createReactNativeInternalMocks = (
433
+ reactNative: ModuleExports
434
+ ): Record<string, () => ModuleExports> => {
435
+ const pick = (name: string): unknown => reactNative[name];
436
+ return {
437
+ "Libraries/Animated/NativeAnimatedHelper": () => ({
438
+ default: {},
439
+ shouldUseNativeDriver: stubReturning(false),
440
+ }),
441
+ "Libraries/Components/View/View": () => defaultExport(pick("View")),
442
+ "Libraries/Core/Devtools/parseErrorStack": () => defaultExport(stubReturning([])),
443
+ "Libraries/EventEmitter/NativeEventEmitter": () => defaultExport(pick("NativeEventEmitter")),
444
+ "Libraries/Image/AssetSourceResolver": () =>
445
+ defaultExport(
446
+ class AssetSourceResolver {
447
+ defaultAsset = stubReturning({height: 0, scale: 1, uri: "", width: 0});
448
+ fromSource = stubReturning({height: 0, scale: 1, uri: "", width: 0});
449
+ }
450
+ ),
451
+ "Libraries/Image/resolveAssetSource": () =>
452
+ defaultExport(
453
+ mock((source: {height?: number; uri?: string; width?: number} | null | undefined) =>
454
+ source
455
+ ? {
456
+ height: source.height ?? 0,
457
+ scale: 1,
458
+ uri: source.uri ?? "",
459
+ width: source.width ?? 0,
460
+ }
461
+ : null
462
+ )
463
+ ),
464
+ "Libraries/NativeComponent/NativeComponentRegistry": () => ({
465
+ get: stubReturning("View"),
466
+ getWithFallback_DEPRECATED: stubReturning("View"),
467
+ setRuntimeConfigProvider: stub(),
468
+ }),
469
+ "Libraries/NativeComponent/ViewConfigIgnore": () => ({
470
+ ConditionallyIgnoredEventHandlers: stubIdentity(),
471
+ DynamicallyInjectedByGestureHandler: stubIdentity(),
472
+ isIgnored: stubReturning(false),
473
+ }),
474
+ "Libraries/Pressability/PressabilityDebug": () => ({
475
+ isEnabled: stubReturning(false),
476
+ PressabilityDebugView: stubReturning(null),
477
+ }),
478
+ "Libraries/Renderer/shims/ReactNative": () => ({
479
+ default: {},
480
+ findNodeHandle: pick("findNodeHandle"),
481
+ }),
482
+ "Libraries/Renderer/shims/ReactNativeTypes": () => ({}),
483
+ "Libraries/Renderer/shims/ReactNativeViewConfigRegistry": () => ({
484
+ customBubblingEventTypes: {},
485
+ customDirectEventTypes: {},
486
+ get: stubReturning({}),
487
+ register: stub(),
488
+ }),
489
+ "Libraries/StyleSheet/normalizeColor": () => defaultExport(processColor),
490
+ "Libraries/StyleSheet/PlatformColorValueTypes": () => ({
491
+ DynamicColorIOS: pick("DynamicColorIOS"),
492
+ normalizeColorObject: stubIdentity(),
493
+ PlatformColor: pick("PlatformColor"),
494
+ processColorObject: stubIdentity(),
495
+ }),
496
+ "Libraries/StyleSheet/processColor": () => defaultExport(processColor),
497
+ "Libraries/StyleSheet/StyleSheet": () => ({
498
+ ...(pick("StyleSheet") as ModuleExports),
499
+ default: pick("StyleSheet"),
500
+ }),
501
+ "Libraries/TurboModule/TurboModuleRegistry": () => pick("TurboModuleRegistry") as ModuleExports,
502
+ "Libraries/Utilities/codegenNativeCommands": () => defaultExport(stubReturning({})),
503
+ "Libraries/Utilities/codegenNativeComponent": () => defaultExport(stubIdentity()),
504
+ "Libraries/Utilities/Platform": () => ({
505
+ ...(pick("Platform") as ModuleExports),
506
+ default: pick("Platform"),
507
+ }),
508
+ "Libraries/vendor/core/ErrorUtils": () =>
509
+ defaultExport({getGlobalHandler: stubReturning(stub()), setGlobalHandler: stub()}),
510
+ };
511
+ };
512
+
513
+ /**
514
+ * Registers `react-native` and its Flow-only internals under every given package prefix.
515
+ * Pass `"@scope/pkg/node_modules/"` for a nested copy a dependency resolves on its own.
516
+ */
517
+ export const createReactNativeModuleMocks = ({
518
+ platform = "ios",
519
+ packagePrefixes = [""],
520
+ }: {
521
+ packagePrefixes?: readonly string[];
522
+ platform?: ExpoTestPlatform;
523
+ } = {}): ModuleMockMap => {
524
+ const reactNative = createReactNativeMock({platform});
525
+ const internals = createReactNativeInternalMocks(reactNative);
526
+ const mocks: ModuleMockMap = {};
527
+ for (const prefix of packagePrefixes) {
528
+ mocks[`${prefix}react-native`] = (): ModuleExports => reactNative;
529
+ for (const [path, factory] of Object.entries(internals)) {
530
+ mocks[`${prefix}react-native/${path}`] = factory;
531
+ }
532
+ }
533
+ return mocks;
534
+ };