@terreno/test 57.18.0 → 57.19.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.
Files changed (115) hide show
  1. package/CHANGELOG.md +1681 -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 +163 -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 +260 -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,39 @@
1
+ import { type ExpoTestPlatform, type ModuleExports, type ModuleMockMap } from "./mockHelpers";
2
+ /** Result passed to an `Animated` completion callback. */
3
+ interface AnimationResult {
4
+ finished: boolean;
5
+ }
6
+ /** The `start`/`stop`/`reset` handle every `Animated` driver returns. */
7
+ export interface MockAnimation {
8
+ reset: () => void;
9
+ start: (callback?: (result: AnimationResult) => void) => void;
10
+ stop: () => void;
11
+ }
12
+ type ColorValue = string | number | null | undefined;
13
+ /** Mirrors `StyleSheet.flatten` for the plain objects and arrays tests pass. */
14
+ export declare const flattenStyle: (style: unknown) => Record<string, unknown>;
15
+ /** Mirrors `processColor`: numbers pass through, strings become an opaque ARGB number. */
16
+ export declare const processColor: (color: ColorValue) => number | null;
17
+ /**
18
+ * Builds the `react-native` module stand-in: host-element components, no-op native APIs, and
19
+ * `Platform.OS` set to `platform`. Bun cannot parse React Native's Flow sources, so every test
20
+ * that renders React Native code needs this (or an equivalent) registered before the first import.
21
+ */
22
+ export declare const createReactNativeMock: ({ platform, }?: {
23
+ platform?: ExpoTestPlatform;
24
+ }) => ModuleExports;
25
+ /**
26
+ * Stand-ins for React Native internals that libraries import by deep path. Each of these files
27
+ * uses Flow syntax Bun cannot parse, so a library that reaches past the `react-native` entry
28
+ * point needs the matching stub. Keys are relative to the `react-native` package.
29
+ */
30
+ export declare const createReactNativeInternalMocks: (reactNative: ModuleExports) => Record<string, () => ModuleExports>;
31
+ /**
32
+ * Registers `react-native` and its Flow-only internals under every given package prefix.
33
+ * Pass `"@scope/pkg/node_modules/"` for a nested copy a dependency resolves on its own.
34
+ */
35
+ export declare const createReactNativeModuleMocks: ({ platform, packagePrefixes, }?: {
36
+ packagePrefixes?: readonly string[];
37
+ platform?: ExpoTestPlatform;
38
+ }) => ModuleMockMap;
39
+ export {};
@@ -0,0 +1,421 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createReactNativeModuleMocks = exports.createReactNativeInternalMocks = exports.createReactNativeMock = exports.processColor = exports.flattenStyle = void 0;
4
+ const bun_test_1 = require("bun:test");
5
+ const react_1 = require("react");
6
+ const mockHelpers_1 = require("./mockHelpers");
7
+ /** Window metrics every dimension API in the mock reports (an iPhone-sized portrait screen). */
8
+ const MOCK_WINDOW_METRICS = { fontScale: 1, height: 812, scale: 2, width: 375 };
9
+ const SEPARATORS = { highlight: (0, mockHelpers_1.stub)(), unhighlight: (0, mockHelpers_1.stub)() };
10
+ const ABSOLUTE_FILL = { bottom: 0, left: 0, position: "absolute", right: 0, top: 0 };
11
+ /** Runs every child animation, then reports completion — matches `Animated.parallel` et al. */
12
+ const compositeAnimation = (animations) => ({
13
+ reset: (0, mockHelpers_1.stub)(),
14
+ start: (0, bun_test_1.mock)((callback) => {
15
+ for (const animation of animations ?? []) {
16
+ animation?.start?.();
17
+ }
18
+ callback?.({ finished: true });
19
+ }),
20
+ stop: (0, mockHelpers_1.stub)(),
21
+ });
22
+ /** A driver (`timing`, `spring`, ...) that completes as soon as it starts. */
23
+ const immediateAnimation = () => compositeAnimation([]);
24
+ /** Mirrors `StyleSheet.flatten` for the plain objects and arrays tests pass. */
25
+ const flattenStyle = (style) => {
26
+ if (Array.isArray(style)) {
27
+ return Object.assign({}, ...style.map(exports.flattenStyle));
28
+ }
29
+ if (style && typeof style === "object") {
30
+ return style;
31
+ }
32
+ return {};
33
+ };
34
+ exports.flattenStyle = flattenStyle;
35
+ /** Mirrors `processColor`: numbers pass through, strings become an opaque ARGB number. */
36
+ const processColor = (color) => {
37
+ if (color === null || color === undefined) {
38
+ return null;
39
+ }
40
+ if (typeof color === "number") {
41
+ return color;
42
+ }
43
+ return 0xff000000;
44
+ };
45
+ exports.processColor = processColor;
46
+ class AnimatedValue {
47
+ _value;
48
+ constructor(value = 0) {
49
+ this._value = value;
50
+ }
51
+ setValue = (0, bun_test_1.mock)((value) => {
52
+ this._value = value;
53
+ });
54
+ setOffset = (0, mockHelpers_1.stub)();
55
+ flattenOffset = (0, mockHelpers_1.stub)();
56
+ extractOffset = (0, mockHelpers_1.stub)();
57
+ addListener = (0, mockHelpers_1.stubReturning)("listener-id");
58
+ removeListener = (0, mockHelpers_1.stub)();
59
+ removeAllListeners = (0, mockHelpers_1.stub)();
60
+ stopAnimation = (0, bun_test_1.mock)((callback) => callback?.(this._value));
61
+ resetAnimation = (0, bun_test_1.mock)((callback) => callback?.(this._value));
62
+ interpolate = (0, bun_test_1.mock)(() => new AnimatedValue(0));
63
+ animate = (0, mockHelpers_1.stub)();
64
+ stopTracking = (0, mockHelpers_1.stub)();
65
+ track = (0, mockHelpers_1.stub)();
66
+ }
67
+ class AnimatedValueXY {
68
+ x;
69
+ y;
70
+ constructor(value) {
71
+ this.x = new AnimatedValue(value?.x ?? 0);
72
+ this.y = new AnimatedValue(value?.y ?? 0);
73
+ }
74
+ setValue = (0, mockHelpers_1.stub)();
75
+ setOffset = (0, mockHelpers_1.stub)();
76
+ flattenOffset = (0, mockHelpers_1.stub)();
77
+ extractOffset = (0, mockHelpers_1.stub)();
78
+ stopAnimation = (0, mockHelpers_1.stub)();
79
+ resetAnimation = (0, mockHelpers_1.stub)();
80
+ addListener = (0, mockHelpers_1.stubReturning)("listener-id");
81
+ removeListener = (0, mockHelpers_1.stub)();
82
+ removeAllListeners = (0, mockHelpers_1.stub)();
83
+ getLayout = (0, bun_test_1.mock)(() => ({ left: this.x, top: this.y }));
84
+ getTranslateTransform = (0, bun_test_1.mock)(() => [
85
+ { translateX: this.x },
86
+ { translateY: this.y },
87
+ ]);
88
+ }
89
+ const animatedNode = () => new AnimatedValue(0);
90
+ /**
91
+ * Renders every `data` row through `renderItem`. Exposes the scroll methods tests usually
92
+ * reach for through a ref (`scrollToOffset`, `scrollToIndex`, `scrollToEnd`).
93
+ */
94
+ const FlatList = (0, react_1.forwardRef)((flatListProps, ref) => {
95
+ const { data, keyExtractor, renderItem, ...props } = flatListProps;
96
+ (0, react_1.useImperativeHandle)(ref, () => ({
97
+ scrollTo: (0, mockHelpers_1.stub)(),
98
+ scrollToEnd: (0, mockHelpers_1.stub)(),
99
+ scrollToIndex: (0, mockHelpers_1.stub)(),
100
+ scrollToOffset: (0, mockHelpers_1.stub)(),
101
+ }));
102
+ const rows = (data ?? []).map((item, index) => (0, react_1.createElement)(react_1.Fragment, { key: keyExtractor?.(item, index) ?? String(index) }, renderItem?.({ index, item, separators: SEPARATORS })));
103
+ return (0, react_1.createElement)("FlatList", props, rows);
104
+ });
105
+ /** Renders each section header followed by its rows. */
106
+ const SectionList = ({ keyExtractor, renderItem, renderSectionHeader, sections, ...props }) => {
107
+ const children = (sections ?? []).map((section, sectionIndex) => (0, react_1.createElement)(react_1.Fragment, { key: section.key ?? String(sectionIndex) }, renderSectionHeader?.({ section }), section.data.map((item, index) => (0, react_1.createElement)(react_1.Fragment, { key: keyExtractor?.(item, index) ?? String(index) }, renderItem?.({ index, item, section })))));
108
+ return (0, react_1.createElement)("SectionList", props, children);
109
+ };
110
+ /**
111
+ * Builds the `react-native` module stand-in: host-element components, no-op native APIs, and
112
+ * `Platform.OS` set to `platform`. Bun cannot parse React Native's Flow sources, so every test
113
+ * that renders React Native code needs this (or an equivalent) registered before the first import.
114
+ */
115
+ const createReactNativeMock = ({ platform = "ios", } = {}) => {
116
+ const View = (0, mockHelpers_1.hostComponent)("View");
117
+ const Text = (0, mockHelpers_1.hostComponent)("Text");
118
+ const Image = (0, mockHelpers_1.hostComponent)("Image");
119
+ const ScrollView = (0, mockHelpers_1.hostComponent)("ScrollView");
120
+ const Animated = {
121
+ add: (0, bun_test_1.mock)(animatedNode),
122
+ createAnimatedComponent: (0, mockHelpers_1.stubIdentity)(),
123
+ decay: (0, bun_test_1.mock)(immediateAnimation),
124
+ delay: (0, bun_test_1.mock)(immediateAnimation),
125
+ diffClamp: (0, bun_test_1.mock)(animatedNode),
126
+ divide: (0, bun_test_1.mock)(animatedNode),
127
+ event: (0, mockHelpers_1.stubReturning)((0, mockHelpers_1.stub)()),
128
+ FlatList,
129
+ Image,
130
+ loop: (0, bun_test_1.mock)((animation) => compositeAnimation(animation ? [animation] : [])),
131
+ modulo: (0, bun_test_1.mock)(animatedNode),
132
+ multiply: (0, bun_test_1.mock)(animatedNode),
133
+ parallel: (0, bun_test_1.mock)(compositeAnimation),
134
+ ScrollView,
135
+ sequence: (0, bun_test_1.mock)(compositeAnimation),
136
+ spring: (0, bun_test_1.mock)(immediateAnimation),
137
+ stagger: (0, bun_test_1.mock)((_delay, animations) => compositeAnimation(animations)),
138
+ subtract: (0, bun_test_1.mock)(animatedNode),
139
+ Text,
140
+ timing: (0, bun_test_1.mock)(immediateAnimation),
141
+ Value: AnimatedValue,
142
+ ValueXY: AnimatedValueXY,
143
+ View,
144
+ };
145
+ const Platform = {
146
+ constants: { reactNativeVersion: { major: 0, minor: 0, patch: 0 } },
147
+ isPad: false,
148
+ isTV: false,
149
+ OS: platform,
150
+ select: (spec) => spec[platform] ?? (platform === "web" ? undefined : spec.native) ?? spec.default,
151
+ Version: platform === "android" ? 34 : "17.0",
152
+ };
153
+ const StyleSheet = {
154
+ absoluteFill: ABSOLUTE_FILL,
155
+ absoluteFillObject: ABSOLUTE_FILL,
156
+ compose: (a, b) => (a && b ? [a, b] : (a ?? b)),
157
+ create: (styles) => styles,
158
+ flatten: exports.flattenStyle,
159
+ hairlineWidth: 1,
160
+ };
161
+ const exports = {
162
+ AccessibilityInfo: {
163
+ addEventListener: (0, mockHelpers_1.stubSubscription)(),
164
+ announceForAccessibility: (0, mockHelpers_1.stub)(),
165
+ isAccessibilityServiceEnabled: (0, mockHelpers_1.stubResolving)(false),
166
+ isBoldTextEnabled: (0, mockHelpers_1.stubResolving)(false),
167
+ isGrayscaleEnabled: (0, mockHelpers_1.stubResolving)(false),
168
+ isInvertColorsEnabled: (0, mockHelpers_1.stubResolving)(false),
169
+ isReduceMotionEnabled: (0, mockHelpers_1.stubResolving)(false),
170
+ isReduceTransparencyEnabled: (0, mockHelpers_1.stubResolving)(false),
171
+ isScreenReaderEnabled: (0, mockHelpers_1.stubResolving)(false),
172
+ setAccessibilityFocus: (0, mockHelpers_1.stub)(),
173
+ },
174
+ ActivityIndicator: (0, mockHelpers_1.hostComponent)("ActivityIndicator"),
175
+ Alert: { alert: (0, mockHelpers_1.stub)(), prompt: (0, mockHelpers_1.stub)() },
176
+ Animated,
177
+ Appearance: {
178
+ addChangeListener: (0, mockHelpers_1.stubSubscription)(),
179
+ getColorScheme: (0, mockHelpers_1.stubReturning)("light"),
180
+ setColorScheme: (0, mockHelpers_1.stub)(),
181
+ },
182
+ AppRegistry: {
183
+ getAppKeys: (0, mockHelpers_1.stubReturning)([]),
184
+ registerComponent: (0, mockHelpers_1.stub)(),
185
+ registerRunnable: (0, mockHelpers_1.stub)(),
186
+ runApplication: (0, mockHelpers_1.stub)(),
187
+ },
188
+ AppState: { addEventListener: (0, mockHelpers_1.stubSubscription)(), currentState: "active" },
189
+ BackHandler: { addEventListener: (0, mockHelpers_1.stubSubscription)(), exitApp: (0, mockHelpers_1.stub)() },
190
+ Button: (0, mockHelpers_1.hostComponent)("Button"),
191
+ DeviceEventEmitter: {
192
+ addListener: (0, mockHelpers_1.stubSubscription)(),
193
+ emit: (0, mockHelpers_1.stub)(),
194
+ removeAllListeners: (0, mockHelpers_1.stub)(),
195
+ },
196
+ Dimensions: { addEventListener: (0, mockHelpers_1.stubSubscription)(), get: (0, mockHelpers_1.stubReturning)(MOCK_WINDOW_METRICS) },
197
+ DynamicColorIOS: (colors) => colors.light,
198
+ Easing: {
199
+ back: (0, mockHelpers_1.stubReturning)((0, mockHelpers_1.stubIdentity)()),
200
+ bezier: (0, mockHelpers_1.stubReturning)((0, mockHelpers_1.stubIdentity)()),
201
+ bounce: (0, mockHelpers_1.stubIdentity)(),
202
+ circle: (0, mockHelpers_1.stubIdentity)(),
203
+ cubic: (0, mockHelpers_1.stubIdentity)(),
204
+ ease: (0, mockHelpers_1.stubIdentity)(),
205
+ elastic: (0, mockHelpers_1.stubReturning)((0, mockHelpers_1.stubIdentity)()),
206
+ exp: (0, mockHelpers_1.stubIdentity)(),
207
+ in: (0, mockHelpers_1.stubIdentity)(),
208
+ inOut: (0, mockHelpers_1.stubIdentity)(),
209
+ linear: (0, mockHelpers_1.stubIdentity)(),
210
+ out: (0, mockHelpers_1.stubIdentity)(),
211
+ poly: (0, mockHelpers_1.stubReturning)((0, mockHelpers_1.stubIdentity)()),
212
+ quad: (0, mockHelpers_1.stubIdentity)(),
213
+ sin: (0, mockHelpers_1.stubIdentity)(),
214
+ },
215
+ FlatList,
216
+ findNodeHandle: (0, bun_test_1.mock)((node) => typeof node === "number" ? node : null),
217
+ I18nManager: {
218
+ allowRTL: (0, mockHelpers_1.stub)(),
219
+ doLeftAndRightSwapInRTL: true,
220
+ forceRTL: (0, mockHelpers_1.stub)(),
221
+ isRTL: false,
222
+ swapLeftAndRightInRTL: (0, mockHelpers_1.stub)(),
223
+ },
224
+ Image,
225
+ ImageBackground: (0, mockHelpers_1.hostComponent)("ImageBackground"),
226
+ InteractionManager: {
227
+ clearInteractionHandle: (0, mockHelpers_1.stub)(),
228
+ createInteractionHandle: (0, mockHelpers_1.stubReturning)(1),
229
+ runAfterInteractions: (0, bun_test_1.mock)((task) => {
230
+ task?.();
231
+ return { cancel: (0, mockHelpers_1.stub)(), done: Promise.resolve() };
232
+ }),
233
+ },
234
+ Keyboard: {
235
+ addListener: (0, mockHelpers_1.stubSubscription)(),
236
+ dismiss: (0, mockHelpers_1.stub)(),
237
+ isVisible: (0, mockHelpers_1.stubReturning)(false),
238
+ metrics: (0, mockHelpers_1.stubReturning)(undefined),
239
+ },
240
+ KeyboardAvoidingView: (0, mockHelpers_1.hostComponent)("KeyboardAvoidingView"),
241
+ LayoutAnimation: {
242
+ configureNext: (0, mockHelpers_1.stub)(),
243
+ create: (0, mockHelpers_1.stubReturning)({}),
244
+ easeInEaseOut: (0, mockHelpers_1.stub)(),
245
+ linear: (0, mockHelpers_1.stub)(),
246
+ Presets: {},
247
+ Properties: {},
248
+ spring: (0, mockHelpers_1.stub)(),
249
+ Types: {},
250
+ },
251
+ Linking: {
252
+ addEventListener: (0, mockHelpers_1.stubSubscription)(),
253
+ canOpenURL: (0, mockHelpers_1.stubResolving)(true),
254
+ getInitialURL: (0, mockHelpers_1.stubResolving)(null),
255
+ openSettings: (0, mockHelpers_1.stubResolving)(undefined),
256
+ openURL: (0, mockHelpers_1.stubResolving)(undefined),
257
+ },
258
+ LogBox: { ignoreAllLogs: (0, mockHelpers_1.stub)(), ignoreLogs: (0, mockHelpers_1.stub)(), install: (0, mockHelpers_1.stub)(), uninstall: (0, mockHelpers_1.stub)() },
259
+ Modal: (0, mockHelpers_1.hostComponent)("Modal"),
260
+ NativeEventEmitter: class NativeEventEmitter {
261
+ addListener = (0, mockHelpers_1.stubSubscription)();
262
+ emit = (0, mockHelpers_1.stub)();
263
+ listenerCount = (0, mockHelpers_1.stubReturning)(0);
264
+ removeAllListeners = (0, mockHelpers_1.stub)();
265
+ removeSubscription = (0, mockHelpers_1.stub)();
266
+ },
267
+ NativeModules: {},
268
+ PanResponder: {
269
+ create: (0, bun_test_1.mock)(() => ({ getInteractionHandle: (0, mockHelpers_1.stubReturning)(null), panHandlers: {} })),
270
+ },
271
+ PixelRatio: {
272
+ get: (0, mockHelpers_1.stubReturning)(MOCK_WINDOW_METRICS.scale),
273
+ getFontScale: (0, mockHelpers_1.stubReturning)(MOCK_WINDOW_METRICS.fontScale),
274
+ getPixelSizeForLayoutSize: (0, bun_test_1.mock)((size) => size * MOCK_WINDOW_METRICS.scale),
275
+ roundToNearestPixel: (0, mockHelpers_1.stubIdentity)(),
276
+ },
277
+ Platform,
278
+ PlatformColor: (...names) => names[0],
279
+ Pressable: (0, mockHelpers_1.hostComponent)("Pressable"),
280
+ processColor: exports.processColor,
281
+ RefreshControl: (0, mockHelpers_1.hostComponent)("RefreshControl"),
282
+ requireNativeComponent: (0, mockHelpers_1.stubIdentity)(),
283
+ SafeAreaView: (0, mockHelpers_1.hostComponent)("SafeAreaView"),
284
+ ScrollView,
285
+ SectionList,
286
+ Share: {
287
+ dismissedAction: "dismissedAction",
288
+ share: (0, mockHelpers_1.stubResolving)({ action: "sharedAction" }),
289
+ sharedAction: "sharedAction",
290
+ },
291
+ StatusBar: Object.assign((0, mockHelpers_1.hostComponent)("StatusBar"), {
292
+ currentHeight: 0,
293
+ setBackgroundColor: (0, mockHelpers_1.stub)(),
294
+ setBarStyle: (0, mockHelpers_1.stub)(),
295
+ setHidden: (0, mockHelpers_1.stub)(),
296
+ setNetworkActivityIndicatorVisible: (0, mockHelpers_1.stub)(),
297
+ setTranslucent: (0, mockHelpers_1.stub)(),
298
+ }),
299
+ StyleSheet,
300
+ Switch: (0, mockHelpers_1.hostComponent)("Switch"),
301
+ Text,
302
+ TextInput: Object.assign((0, mockHelpers_1.hostComponent)("TextInput"), {
303
+ State: {
304
+ blurTextInput: (0, mockHelpers_1.stub)(),
305
+ currentlyFocusedInput: (0, mockHelpers_1.stubReturning)(null),
306
+ focusTextInput: (0, mockHelpers_1.stub)(),
307
+ },
308
+ }),
309
+ TouchableHighlight: (0, mockHelpers_1.hostComponent)("TouchableHighlight"),
310
+ TouchableNativeFeedback: (0, mockHelpers_1.hostComponent)("TouchableNativeFeedback"),
311
+ TouchableOpacity: (0, mockHelpers_1.hostComponent)("TouchableOpacity"),
312
+ TouchableWithoutFeedback: (0, mockHelpers_1.hostComponent)("TouchableWithoutFeedback"),
313
+ TurboModuleRegistry: { get: (0, mockHelpers_1.stubReturning)(null), getEnforcing: (0, mockHelpers_1.stubReturning)({}) },
314
+ UIManager: {
315
+ getViewManagerConfig: (0, mockHelpers_1.stubReturning)({}),
316
+ measure: (0, mockHelpers_1.stub)(),
317
+ setLayoutAnimationEnabledExperimental: (0, mockHelpers_1.stub)(),
318
+ },
319
+ useColorScheme: (0, mockHelpers_1.stubReturning)("light"),
320
+ useWindowDimensions: (0, mockHelpers_1.stubReturning)(MOCK_WINDOW_METRICS),
321
+ Vibration: { cancel: (0, mockHelpers_1.stub)(), vibrate: (0, mockHelpers_1.stub)() },
322
+ View,
323
+ VirtualizedList: FlatList,
324
+ };
325
+ return { ...exports, default: exports };
326
+ };
327
+ exports.createReactNativeMock = createReactNativeMock;
328
+ /** `default` + named export module for a single value, as React Native's internal files expose. */
329
+ const defaultExport = (value) => ({ __esModule: true, default: value });
330
+ /**
331
+ * Stand-ins for React Native internals that libraries import by deep path. Each of these files
332
+ * uses Flow syntax Bun cannot parse, so a library that reaches past the `react-native` entry
333
+ * point needs the matching stub. Keys are relative to the `react-native` package.
334
+ */
335
+ const createReactNativeInternalMocks = (reactNative) => {
336
+ const pick = (name) => reactNative[name];
337
+ return {
338
+ "Libraries/Animated/NativeAnimatedHelper": () => ({
339
+ default: {},
340
+ shouldUseNativeDriver: (0, mockHelpers_1.stubReturning)(false),
341
+ }),
342
+ "Libraries/Components/View/View": () => defaultExport(pick("View")),
343
+ "Libraries/Core/Devtools/parseErrorStack": () => defaultExport((0, mockHelpers_1.stubReturning)([])),
344
+ "Libraries/EventEmitter/NativeEventEmitter": () => defaultExport(pick("NativeEventEmitter")),
345
+ "Libraries/Image/AssetSourceResolver": () => defaultExport(class AssetSourceResolver {
346
+ defaultAsset = (0, mockHelpers_1.stubReturning)({ height: 0, scale: 1, uri: "", width: 0 });
347
+ fromSource = (0, mockHelpers_1.stubReturning)({ height: 0, scale: 1, uri: "", width: 0 });
348
+ }),
349
+ "Libraries/Image/resolveAssetSource": () => defaultExport((0, bun_test_1.mock)((source) => source
350
+ ? {
351
+ height: source.height ?? 0,
352
+ scale: 1,
353
+ uri: source.uri ?? "",
354
+ width: source.width ?? 0,
355
+ }
356
+ : null)),
357
+ "Libraries/NativeComponent/NativeComponentRegistry": () => ({
358
+ get: (0, mockHelpers_1.stubReturning)("View"),
359
+ getWithFallback_DEPRECATED: (0, mockHelpers_1.stubReturning)("View"),
360
+ setRuntimeConfigProvider: (0, mockHelpers_1.stub)(),
361
+ }),
362
+ "Libraries/NativeComponent/ViewConfigIgnore": () => ({
363
+ ConditionallyIgnoredEventHandlers: (0, mockHelpers_1.stubIdentity)(),
364
+ DynamicallyInjectedByGestureHandler: (0, mockHelpers_1.stubIdentity)(),
365
+ isIgnored: (0, mockHelpers_1.stubReturning)(false),
366
+ }),
367
+ "Libraries/Pressability/PressabilityDebug": () => ({
368
+ isEnabled: (0, mockHelpers_1.stubReturning)(false),
369
+ PressabilityDebugView: (0, mockHelpers_1.stubReturning)(null),
370
+ }),
371
+ "Libraries/Renderer/shims/ReactNative": () => ({
372
+ default: {},
373
+ findNodeHandle: pick("findNodeHandle"),
374
+ }),
375
+ "Libraries/Renderer/shims/ReactNativeTypes": () => ({}),
376
+ "Libraries/Renderer/shims/ReactNativeViewConfigRegistry": () => ({
377
+ customBubblingEventTypes: {},
378
+ customDirectEventTypes: {},
379
+ get: (0, mockHelpers_1.stubReturning)({}),
380
+ register: (0, mockHelpers_1.stub)(),
381
+ }),
382
+ "Libraries/StyleSheet/normalizeColor": () => defaultExport(exports.processColor),
383
+ "Libraries/StyleSheet/PlatformColorValueTypes": () => ({
384
+ DynamicColorIOS: pick("DynamicColorIOS"),
385
+ normalizeColorObject: (0, mockHelpers_1.stubIdentity)(),
386
+ PlatformColor: pick("PlatformColor"),
387
+ processColorObject: (0, mockHelpers_1.stubIdentity)(),
388
+ }),
389
+ "Libraries/StyleSheet/processColor": () => defaultExport(exports.processColor),
390
+ "Libraries/StyleSheet/StyleSheet": () => ({
391
+ ...pick("StyleSheet"),
392
+ default: pick("StyleSheet"),
393
+ }),
394
+ "Libraries/TurboModule/TurboModuleRegistry": () => pick("TurboModuleRegistry"),
395
+ "Libraries/Utilities/codegenNativeCommands": () => defaultExport((0, mockHelpers_1.stubReturning)({})),
396
+ "Libraries/Utilities/codegenNativeComponent": () => defaultExport((0, mockHelpers_1.stubIdentity)()),
397
+ "Libraries/Utilities/Platform": () => ({
398
+ ...pick("Platform"),
399
+ default: pick("Platform"),
400
+ }),
401
+ "Libraries/vendor/core/ErrorUtils": () => defaultExport({ getGlobalHandler: (0, mockHelpers_1.stubReturning)((0, mockHelpers_1.stub)()), setGlobalHandler: (0, mockHelpers_1.stub)() }),
402
+ };
403
+ };
404
+ exports.createReactNativeInternalMocks = createReactNativeInternalMocks;
405
+ /**
406
+ * Registers `react-native` and its Flow-only internals under every given package prefix.
407
+ * Pass `"@scope/pkg/node_modules/"` for a nested copy a dependency resolves on its own.
408
+ */
409
+ const createReactNativeModuleMocks = ({ platform = "ios", packagePrefixes = [""], } = {}) => {
410
+ const reactNative = (0, exports.createReactNativeMock)({ platform });
411
+ const internals = (0, exports.createReactNativeInternalMocks)(reactNative);
412
+ const mocks = {};
413
+ for (const prefix of packagePrefixes) {
414
+ mocks[`${prefix}react-native`] = () => reactNative;
415
+ for (const [path, factory] of Object.entries(internals)) {
416
+ mocks[`${prefix}react-native/${path}`] = factory;
417
+ }
418
+ }
419
+ return mocks;
420
+ };
421
+ exports.createReactNativeModuleMocks = createReactNativeModuleMocks;
@@ -0,0 +1,69 @@
1
+ import { type ExpoModuleMockOptions } from "./expoModuleMocks";
2
+ import type { ModuleMockMap } from "./mockHelpers";
3
+ /** What the `afterEach` hook the registrar installs resets. Every flag defaults to `true`. */
4
+ export interface ExpoTestCleanupOptions {
5
+ /** Empty the in-memory SecureStore/AsyncStorage and reset their mocks. */
6
+ clearStorage?: boolean;
7
+ /** `mock.restore()`: put every `spyOn` spy back. Does not undo `mock.module`. */
8
+ restoreMocks?: boolean;
9
+ /**
10
+ * Specifiers whose environment mock is re-registered after each test, undoing a suite's own
11
+ * `mock.module` for them (which `mock.restore()` cannot). Default `[]`.
12
+ */
13
+ restoreModules?: readonly string[];
14
+ /** Set `__DEV__` back to `true`. */
15
+ resetDevFlag?: boolean;
16
+ }
17
+ /** Options for `registerExpoTestEnvironment`. Every field is optional. */
18
+ export interface ExpoTestEnvironmentOptions extends ExpoModuleMockOptions {
19
+ /** Install the `afterEach` reset (`true`), skip it (`false`), or pick its steps. Default `true`. */
20
+ cleanup?: boolean | ExpoTestCleanupOptions;
21
+ /** ISO timestamp the clock is frozen at before each test (`setSystemTime`). Default: real clock. */
22
+ fixedNow?: string;
23
+ /**
24
+ * Package prefixes that hold their own `react-native` copy, e.g. `"@terreno/ui/node_modules/"`.
25
+ * Bun loads a nested copy as a separate module, so it needs its own mock.
26
+ */
27
+ nestedPackagePrefixes?: readonly string[];
28
+ /** Factories that replace a default mock, or add a module the defaults do not cover. */
29
+ overrides?: ModuleMockMap;
30
+ /**
31
+ * Directory the app resolves packages from. Each mock is also registered under the file path a
32
+ * specifier resolves to from here, so it still applies when the app and `@terreno/test` resolve
33
+ * a package to different copies. `false` registers bare specifiers only. Default `process.cwd()`.
34
+ */
35
+ resolveFrom?: string | false;
36
+ /** Write `TZ` and `EXPO_OS` into `process.env`. Default `true`. */
37
+ setProcessEnv?: boolean;
38
+ /** Specifiers to leave unmocked (the real module loads). */
39
+ skip?: readonly string[];
40
+ /** Serve image, font, and media imports as Metro-style asset stubs. Default `true`. */
41
+ stubAssets?: boolean;
42
+ }
43
+ /** Handle returned by `registerExpoTestEnvironment`. */
44
+ export interface ExpoTestEnvironment {
45
+ /** The specifiers mocked, in registration order. */
46
+ mockedModules: string[];
47
+ /** Re-registers this environment's mock for `specifier`, undoing a suite's own `mock.module`. */
48
+ restoreModuleMock: (specifier: string) => void;
49
+ }
50
+ /** File extensions served as `{uri, width, height}` stubs instead of being parsed as code. */
51
+ export declare const ASSET_FILE_PATTERN: RegExp;
52
+ /** Every module the environment mocks by default, keyed by specifier. */
53
+ export declare const createDefaultExpoModuleMocks: ({ nestedPackagePrefixes, platform, ...expoOptions }?: Pick<ExpoTestEnvironmentOptions, "nestedPackagePrefixes"> & ExpoModuleMockOptions) => ModuleMockMap;
54
+ /**
55
+ * Prepares Bun to run Expo / React Native component tests. Call it from a `bunfig.toml` preload
56
+ * (or at the top of a test file, then `await import()` what the test renders) before anything
57
+ * imports `react-native`:
58
+ *
59
+ * - mocks `react-native` and its Flow-only internals, the common `expo-*` modules,
60
+ * `expo-router`, `@expo/vector-icons`, and common native libraries (Reanimated, Gesture
61
+ * Handler, SVG, safe-area-context, NetInfo, SecureStore, AsyncStorage, ...);
62
+ * - sets `__DEV__`, `IS_REACT_ACT_ENVIRONMENT`, `globalThis.expo`, `TZ`, and `EXPO_OS`;
63
+ * - stubs image / font / media imports;
64
+ * - installs an `afterEach` that restores spies, empties the in-memory storage, and resets
65
+ * `__DEV__`.
66
+ *
67
+ * `skip` leaves a module real; `overrides` replaces or adds a factory.
68
+ */
69
+ export declare const registerExpoTestEnvironment: (options?: ExpoTestEnvironmentOptions) => ExpoTestEnvironment;