Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["module:@react-native/babel-preset"],
"plugins": ["relay"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ example/android
example/ios
legendapp-list.tgz
tsconfig.tsbuildinfo
__generated__/*.graphql.ts
57 changes: 53 additions & 4 deletions __tests__/__mocks__/react-native.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Minimal React Native stub for Bun test environment
import * as React from "react";

type AnyFunction = (...args: any[]) => any;

Expand All @@ -12,6 +13,28 @@ export type LayoutChangeEvent = any;
export type NativeScrollEvent = any;
export type NativeSyntheticEvent<T> = { nativeEvent: T };

const createMockComponent = (displayName: string, options?: { triggerLayout?: boolean }) => {
const Component = React.forwardRef<any, any>((props, _ref) => {
React.useEffect(() => {
if (options?.triggerLayout && typeof props.onLayout === "function") {
props.onLayout({
nativeEvent: {
layout: {
height: props.__mockHeight ?? 600,
width: props.__mockWidth ?? 375,
x: 0,
y: 0,
},
},
});
}
}, []);
return React.createElement(React.Fragment, null, props.children);
});
Component.displayName = displayName;
return Component;
};

export const Platform = {
OS: "ios",
select<T>(spec: { ios?: T; android?: T; web?: T; default?: T }): T {
Expand Down Expand Up @@ -64,6 +87,8 @@ export const Animated = {
return { start: (cb?: AnyFunction) => cb?.() };
},
Value: AnimatedValue,
View: createMockComponent("Animated.View", { triggerLayout: true }),
ScrollView: createMockComponent("Animated.ScrollView", { triggerLayout: true }),
};

// Provide a global requestAnimationFrame fallback for tests that expect it
Expand All @@ -72,11 +97,35 @@ if (typeof globalThis.requestAnimationFrame !== "function") {
globalThis.requestAnimationFrame = (cb: AnyFunction) => setTimeout(cb, 0);
}

// FlatList mock that renders items
export const FlatList = React.forwardRef<any, any>((props, _ref) => {
const { data, renderItem, keyExtractor } = props;

if (!data || !renderItem) {
return null;
}

return React.createElement(
React.Fragment,
null,
data.map((item: any, index: number) => {
const key = keyExtractor ? keyExtractor(item, index) : String(index);
return React.createElement(
React.Fragment,
{ key },
renderItem({ item, index })
);
})
);
});
FlatList.displayName = "FlatList";

// Very light component stubs
export const View = (() => null) as unknown as AnyFunction;
export const Text = (() => null) as unknown as AnyFunction;
export const RefreshControl = ((_props: any) => null) as unknown as AnyFunction;
export const ScrollView = (() => null) as unknown as AnyFunction;
export const View = createMockComponent("View", { triggerLayout: true }) as unknown as AnyFunction;
export const Text = createMockComponent("Text") as unknown as AnyFunction;
export const RefreshControl = createMockComponent("RefreshControl") as unknown as AnyFunction;
export const ScrollView = createMockComponent("ScrollView", { triggerLayout: true }) as unknown as AnyFunction;

export type View = any; // for type-only imports
export type ScrollView = any; // for type-only imports
export type FlatList = any; // for type-only imports
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: ['relay'],
};
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"files": {
"ignoreUnknown": false,
"includes": ["**/*.ts", "**/*.tsx"]
"includes": ["**/*.ts", "**/*.tsx", "!**/*.generated.ts"]
},
"formatter": {
"enabled": true,
Expand Down
2,786 changes: 2,370 additions & 416 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bunfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
saveTextLockfile = true

[test]
preload = ["./__tests__/setup.ts"]
preload = ["./__tests__/setup.ts"]
Loading