xref: /expo/apps/test-suite/TestModules.js (revision 1d47c8ea)
1'use strict';
2
3import Constants from 'expo-constants';
4import { Platform } from 'expo-modules-core';
5
6import ExponentTest from './ExponentTest';
7import { isDeviceFarm } from './utils/Environment';
8
9function browserSupportsWebGL() {
10  try {
11    const canvas = document.createElement('canvas');
12    return (
13      !!window.WebGLRenderingContext &&
14      (canvas.getContext('webgl') || canvas.getContext('experimental-webgl'))
15    );
16  } catch {
17    return false;
18  }
19}
20
21function optionalRequire(requirer) {
22  try {
23    return requirer();
24  } catch {
25    // eslint-disable-next-line
26    return;
27  }
28}
29
30// Both Location and TaskManager test suites define tasks in TaskManager.
31// Since tasks can only be defined during initialization phase (not as a result
32// of calling some function when the application is running, but rather in global scope),
33// we need to trigger code execution of these modules here (not in `getTestModules`
34// which is called in one of the components).
35const LocationTestScreen = optionalRequire(() => require('./tests/Location'));
36const TaskManagerTestScreen = optionalRequire(() => require('./tests/TaskManager'));
37// I have a hunch that optionalRequire doesn't work when *not* in global scope
38// since I had to move Camera screen import here too to get rid of an error
39// caused by missing native module.
40const CameraTestScreen = optionalRequire(() => require('./tests/Camera'));
41
42// List of all modules for tests. Each file path must be statically present for
43// the packager to pick them all up.
44export function getTestModules() {
45  const modules = [
46    // Sanity
47    require('./tests/Basic'),
48  ];
49
50  // Expo core modules should run everywhere
51  modules.push(
52    require('./tests/Asset'),
53    require('./tests/Constants'),
54    require('./tests/FileSystem'),
55    require('./tests/Font'),
56    require('./tests/Permissions'),
57    require('./tests/ImagePicker'),
58    optionalRequire(() => require('./tests/Image'))
59  );
60
61  // Universally tested APIs
62  modules.push(
63    require('./tests/EASClient'),
64    require('./tests/Random'),
65    require('./tests/Crypto'),
66    require('./tests/KeepAwake'),
67    require('./tests/Blur'),
68    require('./tests/LinearGradient'),
69    require('./tests/Facebook'),
70    require('./tests/HTML'),
71    require('./tests/FirebaseCore'),
72    require('./tests/FirebaseAnalytics'),
73    require('./tests/FirebaseRecaptcha'),
74    require('./tests/FirebaseJSSDKCompat'),
75    require('./tests/FirebaseJSSDK'),
76    require('./tests/ImageManipulator'),
77    require('./tests/Clipboard'),
78    optionalRequire(() => require('./tests/SQLite'))
79  );
80
81  if (Platform.OS === 'android') {
82    modules.push(require('./tests/JSC'));
83    modules.push(require('./tests/Hermes'));
84  }
85
86  if (global.DETOX) {
87    modules.push(
88      require('./tests/Contacts'),
89      require('./tests/Haptics'),
90      require('./tests/Localization'),
91      require('./tests/SecureStore'),
92      require('./tests/SMS'),
93      require('./tests/StoreReview'),
94      require('./tests/Notifications')
95    );
96    return modules;
97  }
98
99  if (Platform.OS === 'web') {
100    modules.push(
101      require('./tests/Contacts'),
102      // require('./tests/SVG'),
103      require('./tests/Localization'),
104      require('./tests/Recording'),
105      optionalRequire(() => require('./tests/Notifications')),
106      LocationTestScreen
107    );
108
109    if (browserSupportsWebGL()) {
110      modules.push(optionalRequire(() => require('./tests/GLView')));
111    }
112
113    if (ExponentTest && !ExponentTest.isInCI) {
114      // modules.push(optionalRequire(() => require('./tests/Speech')));
115    }
116    return modules.filter(Boolean);
117  }
118
119  modules.push(
120    optionalRequire(() => require('./tests/Application')),
121    optionalRequire(() => require('./tests/AuthSession')),
122    optionalRequire(() => require('./tests/Device')),
123    optionalRequire(() => require('./tests/GLView')),
124    optionalRequire(() => require('./tests/Haptics')),
125    optionalRequire(() => require('./tests/Localization')),
126    optionalRequire(() => require('./tests/Network')),
127    optionalRequire(() => require('./tests/SecureStore')),
128    optionalRequire(() => require('./tests/Segment')),
129    optionalRequire(() => require('./tests/Speech')),
130    optionalRequire(() => require('./tests/Recording')),
131    optionalRequire(() => require('./tests/ScreenOrientation')),
132    optionalRequire(() => require('./tests/AdMobInterstitial')),
133    optionalRequire(() => require('./tests/AdMobRewarded')),
134    optionalRequire(() => require('./tests/FBBannerAd')),
135    optionalRequire(() => require('./tests/Notifications')),
136    optionalRequire(() => require('./tests/NavigationBar')),
137    optionalRequire(() => require('./tests/SystemUI'))
138  );
139
140  if (!isDeviceFarm()) {
141    // Times out sometimes
142    modules.push(
143      optionalRequire(() => require('./tests/AdMobPublisherBanner')),
144      optionalRequire(() => require('./tests/AdMobBanner'))
145    );
146    // Invalid placementId in CI (all tests fail)
147    modules.push(optionalRequire(() => require('./tests/FBNativeAd')));
148    // Popup to request device's location which uses Google's location service
149    modules.push(LocationTestScreen);
150    // Fails to redirect because of malformed URL in published version with release channel parameter
151    modules.push(optionalRequire(() => require('./tests/Linking')));
152    // Has uncontrolled view controllers
153    modules.push(require('./tests/SMS'));
154    // Requires permission
155    modules.push(optionalRequire(() => require('./tests/Contacts')));
156    modules.push(optionalRequire(() => require('./tests/Calendar')));
157    modules.push(optionalRequire(() => require('./tests/CalendarReminders')));
158    modules.push(optionalRequire(() => require('./tests/MediaLibrary')));
159
160    modules.push(optionalRequire(() => require('./tests/Battery')));
161    if (Constants.isDevice) {
162      modules.push(optionalRequire(() => require('./tests/Brightness')));
163    }
164    // Crashes app when mounting component
165    modules.push(optionalRequire(() => require('./tests/Video')));
166    // "sdkUnversionedTestSuite failed: java.lang.NullPointerException: Attempt to invoke interface method
167    // 'java.util.Map expo.modules.interfaces.taskManager.TaskInterface.getOptions()' on a null object reference"
168    modules.push(TaskManagerTestScreen);
169    // Audio tests are flaky in CI due to asynchronous fetching of resources
170    modules.push(optionalRequire(() => require('./tests/Audio')));
171
172    // The Camera tests are flaky on iOS, i.e. they fail randomly
173    if (Constants.isDevice) {
174      modules.push(CameraTestScreen);
175    }
176  }
177  if (Constants.isDevice) {
178    modules.push(optionalRequire(() => require('./tests/Cellular')));
179    modules.push(optionalRequire(() => require('./tests/BarCodeScanner')));
180  }
181  return modules
182    .filter(Boolean)
183    .sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1));
184}
185