-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
145 lines (130 loc) · 5.05 KB
/
Copy pathjest.setup.js
File metadata and controls
145 lines (130 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Jest setup file for mocking React Native modules
// Setup React Native Testing Library (built-in matchers included in v12.4+)
// Mock AsyncStorage
const mockAsyncStorage = {
getItem: jest.fn().mockResolvedValue(null),
setItem: jest.fn().mockResolvedValue(undefined),
removeItem: jest.fn().mockResolvedValue(undefined),
getAllKeys: jest.fn().mockResolvedValue([]),
multiGet: jest.fn().mockResolvedValue([]),
multiSet: jest.fn().mockResolvedValue(undefined),
multiRemove: jest.fn().mockResolvedValue(undefined),
clear: jest.fn().mockResolvedValue(undefined)
};
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
// Mock MLKit Image Labeling
jest.mock('@infinitered/react-native-mlkit-image-labeling', () => ({
ImageLabeling: {
initialize: jest.fn().mockResolvedValue(undefined),
label: jest.fn().mockResolvedValue([]),
},
}));
// Removed react-native-reanimated mock since we no longer use reanimated
jest.mock('expo-haptics', () => ({
impactAsync: jest.fn(),
notificationAsync: jest.fn(),
selectionAsync: jest.fn(),
ImpactFeedbackStyle: {
Light: 'light',
Medium: 'medium',
Heavy: 'heavy',
},
NotificationFeedbackType: {
Success: 'success',
Warning: 'warning',
Error: 'error',
},
}));
jest.mock('expo-file-system', () => ({
getInfoAsync: jest.fn().mockResolvedValue({ exists: true, size: 1024 }),
readAsStringAsync: jest.fn().mockResolvedValue('mock file content'),
writeAsStringAsync: jest.fn().mockResolvedValue(undefined),
deleteAsync: jest.fn().mockResolvedValue(undefined),
makeDirectoryAsync: jest.fn().mockResolvedValue(undefined),
readDirectoryAsync: jest.fn().mockResolvedValue([]),
documentDirectory: '/mock/documents/',
cacheDirectory: '/mock/cache/',
EncodingType: {
UTF8: 'utf8',
Base64: 'base64'
}
}));
jest.mock('@react-native-community/netinfo', () => ({
fetch: jest.fn().mockResolvedValue({
isConnected: true,
isInternetReachable: true,
}),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
}));
jest.mock('expo-av', () => ({
Audio: {
RecordingOptionsPresets: {
HIGH_QUALITY: {},
},
Recording: class MockRecording {
prepareToRecordAsync = jest.fn().mockResolvedValue(undefined);
startAsync = jest.fn().mockResolvedValue(undefined);
stopAndUnloadAsync = jest.fn().mockResolvedValue(undefined);
getURI = jest.fn().mockReturnValue('/mock/audio/recording.m4a');
getStatusAsync = jest.fn().mockResolvedValue({ isDoneRecording: true });
},
Sound: class MockSound {
static createAsync = jest.fn().mockResolvedValue({
sound: {
getStatusAsync: jest.fn().mockResolvedValue({
isLoaded: true,
durationMillis: 3000
}),
unloadAsync: jest.fn().mockResolvedValue(undefined)
}
});
loadAsync = jest.fn().mockResolvedValue(undefined);
playAsync = jest.fn().mockResolvedValue(undefined);
stopAsync = jest.fn().mockResolvedValue(undefined);
unloadAsync = jest.fn().mockResolvedValue(undefined);
},
setAudioModeAsync: jest.fn().mockResolvedValue(undefined),
requestPermissionsAsync: jest.fn().mockResolvedValue({ status: 'granted' }),
AndroidOutputFormat: {
MPEG_4: 'mp4',
},
AndroidAudioEncoder: {
AAC: 'aac',
},
IOSOutputFormat: {
MPEG4AAC: 'mp4',
},
IOSAudioQuality: {
HIGH: 'high',
MEDIUM: 'medium',
}
},
}));
// Mock .tflite files
jest.mock('../assets/models/birdnet/birdnet_v24.tflite', () => 'mock-tflite-path', { virtual: true });
// Mock labels.json
jest.mock('../assets/models/birdnet/labels.json', () => ({
labels: [
{ index: 0, scientific_name: 'Turdus migratorius', common_name: 'American Robin', label: 'Turdus migratorius_American Robin' },
{ index: 1, scientific_name: 'Passer domesticus', common_name: 'House Sparrow', label: 'Passer domesticus_House Sparrow' }
]
}), { virtual: true });
// Mock CSV files
jest.mock('../assets/birds_fully_translated.csv', () => 'mock-csv-data', { virtual: true });
// Mock whoBIRD TFLite models and related assets
jest.mock('../assets/models/whoBIRD-TFlite-master/BirdNET_GLOBAL_6K_V2.4_Model_FP16.tflite', () => 'mock-whobird-fp16-path', { virtual: true });
jest.mock('../assets/models/whoBIRD-TFlite-master/BirdNET_GLOBAL_6K_V2.4_Model_FP32.tflite', () => 'mock-whobird-fp32-path', { virtual: true });
jest.mock('../assets/models/whoBIRD-TFlite-master/BirdNET_GLOBAL_6K_V2.4_MData_Model_FP16.tflite', () => 'mock-whobird-mdata-fp16-path', { virtual: true });
jest.mock('../assets/models/whoBIRD-TFlite-master/BirdNET_GLOBAL_6K_V2.4_MData_Model_V2_FP16.tflite', () => 'mock-whobird-mdata-v2-fp16-path', { virtual: true });
// Mock react-native-fast-tflite
jest.mock('react-native-fast-tflite', () => {
return require('./__mocks__/react-native-fast-tflite');
});
// Mock any additional ML Kit dependencies
jest.mock('@infinitered/react-native-mlkit-object-detection', () => ({
ObjectDetection: {
initialize: jest.fn().mockResolvedValue(undefined),
detect: jest.fn().mockResolvedValue([]),
},
}));