Files
Sauci/apps/mobile/src/test/setup.ts
T
jjbrunton f35114dc77 chore(android): target API 36 with Expo 54
Upgrade the mobile runtime and tracked Android project to compile and target API 36. Align Expo modules, React Native, Node, Gradle, and Android build tooling while preserving the custom widget sources.\n\nAdapt file-system, notification, animation, test, and Metro compatibility for the SDK 54 runtime.
2026-08-28 20:01:15 +01:00

148 lines
4.7 KiB
TypeScript

/// <reference types="jest" />
// Environment variables are set in setupEnv.js (runs before modules load)
// Some modules rely on this global existing in RN.
(global as any).__DEV__ = true;
jest.mock('@supabase/supabase-js', () => {
const makeChannel = () => {
const channel: any = {
on: jest.fn(() => channel),
subscribe: jest.fn(() => channel),
send: jest.fn(async () => ({ data: null, error: null })),
};
return channel;
};
return {
createClient: jest.fn(() => ({
auth: {
getSession: jest.fn(async () => ({ data: { session: null }, error: null })),
getUser: jest.fn(async () => ({ data: { user: null }, error: null })),
signOut: jest.fn(async () => ({ error: null })),
},
from: jest.fn(() => ({
select: jest.fn(),
eq: jest.fn(),
neq: jest.fn(),
is: jest.fn(),
in: jest.fn(),
order: jest.fn(),
range: jest.fn(),
update: jest.fn(),
upsert: jest.fn(),
insert: jest.fn(),
maybeSingle: jest.fn(),
})),
channel: jest.fn(() => makeChannel()),
removeChannel: jest.fn(),
storage: {
from: jest.fn(() => ({
upload: jest.fn(async () => ({ data: null, error: null })),
createSignedUrl: jest.fn(async () => ({ data: { signedUrl: 'https://example.com' }, error: null })),
})),
},
functions: {
invoke: jest.fn(async () => ({ data: null, error: null })),
},
})),
};
});
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper', () => ({}), { virtual: true });
jest.mock('react-native-reanimated', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Reanimated = require('react-native-reanimated/mock');
// The mock is missing `call` in some versions.
Reanimated.default.call = () => {};
return Reanimated;
});
// Reanimated 3 sometimes requires this when running in Jest.
// eslint-disable-next-line no-undef
(global as any).__reanimatedWorkletInit = () => {};
jest.mock('expo-linear-gradient', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const React = require('react');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { View } = require('react-native');
return {
LinearGradient: ({ children, ...props }: any) => React.createElement(View, props, children),
};
});
jest.mock('@expo/vector-icons', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const React = require('react');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Text } = require('react-native');
const Icon = ({ name, ...props }: any) => React.createElement(Text, props, name);
return { Ionicons: Icon };
});
jest.mock('@react-native-async-storage/async-storage', () =>
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);
jest.mock('expo-image-picker', () => ({
requestCameraPermissionsAsync: jest.fn(async () => ({ status: 'granted' })),
launchImageLibraryAsync: jest.fn(async () => ({ canceled: true, assets: [] })),
launchCameraAsync: jest.fn(async () => ({ canceled: true, assets: [] })),
MediaTypeOptions: {
All: 'All',
Videos: 'Videos',
},
}));
jest.mock('expo-file-system/legacy', () => ({
readAsStringAsync: jest.fn(async () => ''),
EncodingType: {
Base64: 'base64',
},
}));
jest.mock('expo-av', () => ({
Audio: {
requestPermissionsAsync: jest.fn(async () => ({ status: 'granted' })),
setAudioModeAsync: jest.fn(async () => undefined),
Recording: {
createAsync: jest.fn(),
},
RecordingOptionsPresets: {
HIGH_QUALITY: {},
},
},
}));
jest.mock('react-native-compressor', () => ({
Video: {
compress: jest.fn(async (uri: string) => uri),
},
}));
jest.mock('base64-arraybuffer', () => ({
decode: jest.fn(() => new ArrayBuffer(0)),
}));
jest.mock('@react-native-firebase/app', () => ({
getApp: jest.fn(() => ({})),
}));
jest.mock('@react-native-firebase/analytics', () => ({
getAnalytics: jest.fn(() => ({})),
logEvent: jest.fn(),
setUserId: jest.fn(),
setUserProperty: jest.fn(),
setAnalyticsCollectionEnabled: jest.fn(() => Promise.resolve()),
resetAnalyticsData: jest.fn(),
}));